From 31677fb533636efcb0793064b3ba8559030ff5e5 Mon Sep 17 00:00:00 2001 From: Paul Becotte Date: Fri, 24 Mar 2023 15:03:02 -0400 Subject: [PATCH] Fix the docker_target parameter for toolchains 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 https://github.com/bazelbuild/rules_docker/issues/2170 --- .bazelrc | 8 +++++--- container/image.bzl | 6 +++++- container/incremental_load.sh.tpl | 3 +-- toolchains/docker/toolchain.bzl | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.bazelrc b/.bazelrc index 178245be2..6d97b9aab 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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 diff --git a/container/image.bzl b/container/image.bzl index 790409a7e..bbf6f697e 100644 --- a/container/image.bzl +++ b/container/image.bzl @@ -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 []), ) diff --git a/container/incremental_load.sh.tpl b/container/incremental_load.sh.tpl index b0e0157c8..2ed009fa4 100644 --- a/container/incremental_load.sh.tpl +++ b/container/incremental_load.sh.tpl @@ -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 diff --git a/toolchains/docker/toolchain.bzl b/toolchains/docker/toolchain.bzl index a7bbf9441..16f20d0f9 100644 --- a/toolchains/docker/toolchain.bzl +++ b/toolchains/docker/toolchain.bzl @@ -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"):