Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Fail to use the toolchain_configure rule with its docker_target parameter #2170

Closed
jrovani opened this issue Oct 10, 2022 · 3 comments · May be fixed by #2237
Closed

Fail to use the toolchain_configure rule with its docker_target parameter #2170

jrovani opened this issue Oct 10, 2022 · 3 comments · May be fixed by #2237
Labels
Can Close? Will close in 30 days unless there is a comment indicating why not

Comments

@jrovani
Copy link

jrovani commented Oct 10, 2022

🐞 bug report

Affected Rule

I fail to use the toolchain_configure rule with its docker_target parameter.

Is this a regression?

I don't think, I tried with previous versions of the rules and get the same error. In addition, I might have not understood correctly how to use the docker_target argument.

Description

I used Nix to define a docker target. I can successfully run docker using bazel run @docker20//:bin/docker

Then, I try to use it to configure the docker toolchain with the docker_target argument (using this doc) as below:

rules_docker_version = "0.25.0"

http_archive(
    name = "io_bazel_rules_docker",
    sha256 = "b1e80761a8a8243d03ebca8845e9cc1ba6c82ce7c5179ce2b295cd36f7e394bf",
    urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v{}/rules_docker-v{}.tar.gz".format(rules_docker_version, rules_docker_version)],
)

## configure docker toolchain
load("@io_bazel_rules_docker//toolchains/docker:toolchain.bzl", docker_toolchain_configure = "toolchain_configure")
#load("//toolchains/docker:toolchain.bzl", docker_toolchain_configure = "toolchain_configure")

# can be tested with `bazel run @docker20//:bin/docker version`
nixpkgs_package(
    name = "docker20",
    nix_file = "//:docker.nix",
    repository = "@nixpkgs//:default.nix",
)

docker_toolchain_configure(
    name = "docker_config",
    docker_target = "@docker20//:bin/docker",
)

and I get this error:

ERROR: An error occurred during the fetch of repository 'docker_config':
   Traceback (most recent call last):
        File "/home/jean/.cache/bazel/_bazel_jean/5205a4ea94d8eb84064fc534c16a222a/external/io_bazel_rules_docker/toolchains/docker/toolchain.bzl", line 129, column 66, in _toolchain_configure_impl
                tool_attr = "tool_target = \"%s\"," % repository_ctx.attr.tool_target
Error: No such attribute 'tool_target'

🔬 Minimal Reproduction

It relies on Nix as well, but I think it is more related to the docker toolchain as I can actually run docker using bazel run @docker20//:bin/docker

🔥 Exception or Error

ERROR: An error occurred during the fetch of repository 'docker_config':
   Traceback (most recent call last):
        File "/home/jean/.cache/bazel/_bazel_jean/5205a4ea94d8eb84064fc534c16a222a/external/io_bazel_rules_docker/toolchains/docker/toolchain.bzl", line 129, column 66, in _toolchain_configure_impl
                tool_attr = "tool_target = \"%s\"," % repository_ctx.attr.tool_target
Error: No such attribute 'tool_target'

🌍 Your Environment

Operating System:

Linux

Output of bazel version:

Bazelisk version: v1.8.1
Build label: 5.3.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Aug 23 00:45:53 2022 (1661215553)
Build timestamp: 1661215553
Build timestamp as int: 1661215553

Rules_docker version:

I can run bazel run @docker20//:bin/docker version and get

Client:
Version: 20.10.2
API version: 1.40
Go version: go1.16.4
Git commit: v20.10.2
Built: Thu Jan 1 00:00:00 1970
OS/Arch: linux/amd64
Context: default
Experimental: true

Server: Docker Engine - Community
Engine:
Version: 19.03.12
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:44:07 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683

Anything else relevant?

Looking at _toolchain_configure_impl, repository_ctx.attr.tool_target is used while tool_target is not in toolchain_configure attributes. I tried to override this locally using docker_target instead, but I get an other issue:

/home/jean/.cache/bazel/_bazel_jean/5205a4ea94d8eb84064fc534c16a222a/execroot/reproducible-cv/bazel-out/k8-fastbuild-ST-4a519fd6d3e4/bin/src/cv_utils/docker.executable: line 214: external/docker20/bin/docker: No such file or directory
@pbecotte
Copy link

pbecotte commented Jan 2, 2023

Had to change three things to get this working (am not allowed to make PRs)

  1. change toolchain_configure to use "docker_target"
  2. Add 'toolchain_info.tool_target.files_to_run.executable' to the runfiles for the image layer
  3. Use readlink to resolve the symlink to the docker binary (the tar command does not follow symlinks, which is how the 'target' gets passed)

pbecotte added a commit to pbecotte/rules_docker that referenced this issue Mar 24, 2023
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
pbecotte added a commit to pbecotte/rules_docker that referenced this issue Mar 24, 2023
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
@github-actions
Copy link

github-actions bot commented Jul 2, 2023

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days.
Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_docker!

@github-actions github-actions bot added the Can Close? Will close in 30 days unless there is a comment indicating why not label Jul 2, 2023
@github-actions
Copy link

github-actions bot commented Aug 2, 2023

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

@github-actions github-actions bot closed this as completed Aug 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Can Close? Will close in 30 days unless there is a comment indicating why not
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants