diff --git a/container/incremental_load.sh.tpl b/container/incremental_load.sh.tpl index b0e0157c8..18513fba8 100644 --- a/container/incremental_load.sh.tpl +++ b/container/incremental_load.sh.tpl @@ -249,6 +249,16 @@ function read_variables() { # This is not executed if the single argument --norun is passed or # no run_statements are generated (in which case, 'run' is 'False'). if [[ "%{run}" == "True" ]]; then + # When 'bazel run' is called, it expects that the args specified in the BUILD + # file are not known to the run command and will prepend them to all other + # arguments. + # + # However, we have already baked those commands into the image, because users + # expect that 'args' in the case of an image target will be included in the + # image. This templated script de-duplicates the args specified in the BUILD + # file by skipping the number of args already included in the image command. + shift "%{run_num_args}" + docker_args=() container_args=() diff --git a/container/layer_tools.bzl b/container/layer_tools.bzl index 33ab3fb8c..4bf413b49 100644 --- a/container/layer_tools.bzl +++ b/container/layer_tools.bzl @@ -290,6 +290,7 @@ def incremental_load( "%{docker_flags}": " ".join(toolchain_info.docker_flags), "%{docker_tool_path}": docker_path(toolchain_info), "%{load_statements}": "\n".join(load_statements), + "%{run_num_args}": str(len(ctx.attr.args)), "%{run_statement}": run_statement, "%{run_tag}": run_tag, "%{run}": str(run),