Skip to content

Commit

Permalink
Fix the docker_target parameter for toolchains
Browse files Browse the repository at this point in the history
We have to update the configure parameter to actually use docker_target. Once that is setup, we have to make sure that the executable is added to the runfiles, and update the entrypoint script to find the built binary. This should resolve bazelbuild#2170
  • Loading branch information
pbecotte committed Mar 24, 2023
1 parent 6db7c12 commit 31677fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ test:remote --remote_timeout=3600
test:remote --keep_going

# Configuration specific to buildkite CI testing the default workspace
test:buildkite --action_env=PATH
test:buildkite --define=ENV_KEY=my_key # for tests/container:set_env_make_vars_test
test:buildkite --define=ENV_VALUE=my_value # for tests/container:set_env_make_vars_test
test:buildkite --action_env=PATH
test:buildkite --test_output=errors

# A test verifies that these values can be expanded as make vars
test --define=ENV_KEY=my_key # for tests/container:set_env_make_vars_test
test --define=ENV_VALUE=my_value # for tests/container:set_env_make_vars_test
6 changes: 5 additions & 1 deletion container/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,12 @@ def _impl(
command = "cp %s %s" % (config_digest.path, output_config_digest.path),
)

toolchain_info = ctx.toolchains["@io_bazel_rules_docker//toolchains/docker:toolchain_type"].info
runfiles_files = [config_file, config_digest, output_config_digest]
if toolchain_info.tool_target:
runfiles_files.append(toolchain_info.tool_target.files_to_run.executable)
runfiles = ctx.runfiles(
files = unzipped_layers + diff_ids + [config_file, config_digest, output_config_digest] +
files = unzipped_layers + diff_ids + runfiles_files +
([container_parts["legacy"]] if container_parts["legacy"] else []),
)

Expand Down
3 changes: 1 addition & 2 deletions container/incremental_load.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ function guess_runfiles() {

RUNFILES="${PYTHON_RUNFILES:-$(guess_runfiles)}"

DOCKER="%{docker_tool_path}"
DOCKER="$(readlink -nf %{docker_tool_path})"
DOCKER_FLAGS="%{docker_flags}"

if [[ -z "${DOCKER}" ]]; then
echo >&2 "error: docker not found; do you need to manually configure the docker toolchain?"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion toolchains/docker/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _toolchain_configure_impl(repository_ctx):

tool_attr = ""
if repository_ctx.attr.docker_target:
tool_attr = "tool_target = \"%s\"," % repository_ctx.attr.tool_target
tool_attr = "tool_target = \"%s\"," % repository_ctx.attr.docker_target
elif repository_ctx.attr.docker_path:
tool_attr = "tool_path = \"%s\"," % repository_ctx.attr.docker_path
elif repository_ctx.which("docker"):
Expand Down

0 comments on commit 31677fb

Please sign in to comment.