-
Notifications
You must be signed in to change notification settings - Fork 691
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for docker run args for docker image targets (#1957)
This adds parsing of command-line arguments being passed to 'bazel run' when executing an image target. The "--" delimiter is used to separate arguments for "docker run" from arguments to the container. This makes the following style of calls possible: ``` bazel run //:my_cool_image -- -p 8080:8080 -v /tmp:/tmp -- --my-cool-flag ``` which is translated into ``` docker run -i --rm -p 8080:8080 -v /tmp:/tmp bazel/my_cool_image:image --my-cool-flag ```
- Loading branch information
Showing
3 changed files
with
56 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,11 +242,41 @@ function read_variables() { | |
# An optional "docker run" statement for invoking a loaded container. | ||
# This is not executed if the single argument --norun is passed or | ||
# no run_statements are generated (in which case, 'run' is 'False'). | ||
if [[ "a$*" != "a--norun" && "%{run}" == "True" ]]; then | ||
if [[ "%{run}" == "True" ]]; then | ||
docker_args=() | ||
container_args=() | ||
|
||
# Search remaining params looking for docker and container args. | ||
# | ||
# It is assumed that they will follow the pattern: | ||
# [dockerargs...] -- [container args...] | ||
# | ||
# "--norun" is treated as a "virtual" additional parameter to | ||
# "docker run", since it cannot conflict with any "docker run" | ||
# arguments. If "--norun" needs to be passed to the container, | ||
# it can be safely placed after "--". | ||
This comment has been minimized.
Sorry, something went wrong.
chasezheng
|
||
while test $# -gt 0 | ||
This comment has been minimized.
Sorry, something went wrong.
chasezheng
|
||
do | ||
case "$1" in | ||
--norun) # norun as a "docker run" option means exit | ||
exit | ||
;; | ||
--) # divider between docker and container args | ||
shift | ||
container_args=("$@") | ||
break | ||
;; | ||
*) # potential "docker run" option | ||
docker_args+=("$1") | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
# Once we've loaded the images for all layers, we no longer need the temporary files on disk. | ||
# We can clean up before we exec docker, since the exit handler will no longer run. | ||
cleanup | ||
|
||
# This generated and injected by docker_*. | ||
exec %{run_statements} | ||
exec %{run_statement} "${docker_args[@]}" "%{run_tag}" "${container_args[@]}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maybe just
bazel run my/image:helloworld -- --docker_args="-p 8080:80" --container_args="arg0"