Skip to content

Commit

Permalink
Improve container image startup
Browse files Browse the repository at this point in the history
  • Loading branch information
mering committed Jun 22, 2023
1 parent 7910f4d commit f373f06
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 39 deletions.
29 changes: 29 additions & 0 deletions .docker/copybara
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

# Handle environment variables for backwards compatibility
if [ -n "$COPYBARA_SUBCOMMAND" ] || [ -n "$COPYBARA_CONFIG" ] || [ -n "$COPYBARA_WORKFLOW" ] || [ -n "$COPYBARA_SOURCEREF" ]; then
echo "Detected \$COPYBARA_* environment variables, overwriting shell args"
ARGS=()
if [ -n "$COPYBARA_SUBCOMMAND" ]; then
ARGS+=("$COPYBARA_SUBCOMMAND")
else
ARGS+=("migrate")
fi
if [ -n "$COPYBARA_CONFIG" ]; then
ARGS+=("$COPYBARA_CONFIG")
else
ARGS+=("copy.bara.sky")
fi
if [ -n "$COPYBARA_WORKFLOW" ]; then
ARGS+=("$COPYBARA_WORKFLOW")
else
ARGS+=("default")
fi
if [ -n "$COPYBARA_SOURCEREF" ]; then
ARGS+=("$COPYBARA_SOURCEREF")
fi
echo "Setting arguments to: \"${ARGS[@]}\""
set -- "${ARGS[@]}"
fi

exec java -jar /opt/copybara/copybara_deploy.jar "$@"
17 changes: 0 additions & 17 deletions .docker/entrypoint.sh

This file was deleted.

11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ RUN apt-get update && apt-get install -y \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build /home/ubuntu/bazel-bin/java/com/google/copybara/copybara_deploy.jar /opt/copybara/
COPY --from=buildtools /go/bin/buildozer /go/bin/buildifier /usr/bin/
ENV COPYBARA_SUBCOMMAND="migrate" \
COPYBARA_CONFIG="copy.bara.sky" \
COPYBARA_WORKFLOW="default" \
COPYBARA_SOURCEREF="" \
COPYBARA_OPTIONS=""
COPY .docker/entrypoint.sh /usr/local/bin/copybara
RUN chmod +x /usr/local/bin/copybara
# NOTE NullPointerException when using directly ENTRYPOINT["java","-jar","/opt/copybara/copybara_deploy.jar"]
COPY .docker/copybara /usr/local/bin/copybara
ENTRYPOINT ["/usr/local/bin/copybara"]
CMD ["migrate", "copy.bara.sky"]
WORKDIR /usr/src/app
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,15 @@ Once this has finished building, you can run the image like so from the root of
the code you are trying to use Copybara on:

```sh
docker run -it -v "$(pwd)":/usr/src/app copybara copybara
docker run -it -v "$(pwd)":/usr/src/app copybara
```

A few environment variables exist to allow you to change how you run copybara:
* `COPYBARA_CONFIG=copy.bara.sky`
* allows you to specify a path to a config file, defaults to root `copy.bara.sky`
* `COPYBARA_SUBCOMMAND=migrate`
* allows you to change the command run, defaults to `migrate`
* `COPYBARA_OPTIONS=''`
* allows you to specify options for copybara, defaults to none
* `COPYBARA_WORKFLOW=default`
* allows you to specify the workflow to run, defaults to `default`
* `COPYBARA_SOURCEREF=''`
* allows you to specify the sourceref, defaults to none

```sh
docker run \
-e COPYBARA_CONFIG='other.config.sky' \
-e COPYBARA_SUBCOMMAND='validate' \
-v "$(pwd)":/usr/src/app \
-it copybara copybara
-it copybara
```

#### Git Config and Credentials
Expand All @@ -200,7 +188,7 @@ docker run \
-v ~/.ssh:/root/.ssh \
-v ~/.gitconfig:/root/.gitconfig \
-v "$(pwd)":/usr/src/app \
-it copybara copybara
-it copybara
```

## Documentation
Expand Down

0 comments on commit f373f06

Please sign in to comment.