Skip to content

Commit

Permalink
Specifying client config.json with Bazel label (#2032)
Browse files Browse the repository at this point in the history
* Specifying client config.json with Bazel label

* regenerate stardoc
  • Loading branch information
linzhp authored Feb 28, 2022
1 parent 26e5dbb commit a17900c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,12 @@ docker_toolchain_configure(
client_config="/path/to/docker/client/config",
)

# Alternatively, specify the Bazel label for the config.json
docker_toolchain_configure(
name = "docker_config",
client_config="@//path/to/docker/client:config.json",
)

# Load the custom version of container_pull created by the docker toolchain
# configuration.
load("@docker_config//:pull.bzl", authenticated_container_pull="container_pull")
Expand Down
10 changes: 7 additions & 3 deletions container/pull.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ _container_pull_attrs = {
doc = "The digest of the image to pull.",
),
"docker_client_config": attr.string(
doc = """Specifies a custom directory to look for the docker client configuration.
doc = """Specifies a custom directory to look for the docker client configuration, or a Bazel label of
the config.json file.
Don't use this directly.
Instead, specify the docker configuration directory using a custom docker toolchain configuration.
Expand Down Expand Up @@ -170,8 +171,11 @@ def _impl(repository_ctx):
]

# Use the custom docker client config directory if specified.
if repository_ctx.attr.docker_client_config != "":
args += ["-client-config-dir", "{}".format(repository_ctx.attr.docker_client_config)]
docker_client_config = repository_ctx.attr.docker_client_config
if docker_client_config.startswith("@") or docker_client_config.startswith("//"):
args += ["-client-config-dir", repository_ctx.path(Label(docker_client_config)).dirname]
elif docker_client_config:
args += ["-client-config-dir", docker_client_config]

cache_dir = repository_ctx.os.environ.get("DOCKER_REPO_CACHE")
if cache_dir:
Expand Down
2 changes: 1 addition & 1 deletion docs/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ please use the bazel startup flag `--loading_phase_threads=1` in your bazel invo
| <a id="container_pull-architecture"></a>architecture | Which CPU architecture to pull if this image refers to a multi-platform manifest list, default 'amd64'. | String | optional | "amd64" |
| <a id="container_pull-cpu_variant"></a>cpu_variant | Which CPU variant to pull if this image refers to a multi-platform manifest list. | String | optional | "" |
| <a id="container_pull-digest"></a>digest | The digest of the image to pull. | String | optional | "" |
| <a id="container_pull-docker_client_config"></a>docker_client_config | Specifies a custom directory to look for the docker client configuration.<br><br> Don't use this directly. Instead, specify the docker configuration directory using a custom docker toolchain configuration. Look for the <code>client_config</code> attribute in <code>docker_toolchain_configure</code> [here](https://github.com/bazelbuild/rules_docker#setup) for details. See [here](https://github.com/bazelbuild/rules_docker#container_pull-custom-client-configuration) for an example on how to use container_pull after configuring the docker toolchain<br><br> When left unspecified (ie not set explicitly or set by the docker toolchain), docker will use the directory specified via the <code>DOCKER_CONFIG</code> environment variable.<br><br> If <code>DOCKER_CONFIG</code> isn't set, docker falls back to <code>$HOME/.docker</code>. | String | optional | "" |
| <a id="container_pull-docker_client_config"></a>docker_client_config | Specifies a custom directory to look for the docker client configuration, or a Bazel label of the config.json file.<br><br> Don't use this directly. Instead, specify the docker configuration directory using a custom docker toolchain configuration. Look for the <code>client_config</code> attribute in <code>docker_toolchain_configure</code> [here](https://github.com/bazelbuild/rules_docker#setup) for details. See [here](https://github.com/bazelbuild/rules_docker#container_pull-custom-client-configuration) for an example on how to use container_pull after configuring the docker toolchain<br><br> When left unspecified (ie not set explicitly or set by the docker toolchain), docker will use the directory specified via the <code>DOCKER_CONFIG</code> environment variable.<br><br> If <code>DOCKER_CONFIG</code> isn't set, docker falls back to <code>$HOME/.docker</code>. | String | optional | "" |
| <a id="container_pull-import_tags"></a>import_tags | Tags to be propagated to generated rules. | List of strings | optional | [] |
| <a id="container_pull-os"></a>os | Which os to pull if this image refers to a multi-platform manifest list. | String | optional | "linux" |
| <a id="container_pull-os_features"></a>os_features | Specifies os features when pulling a multi-platform manifest list. | List of strings | optional | [] |
Expand Down
6 changes: 3 additions & 3 deletions toolchains/docker/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ docker_toolchain = rule(
),
"client_config": attr.string(
default = "",
doc = "A custom directory for the docker client config.json. If " +
"DOCKER_CONFIG is not specified, the value of the " +
doc = "A custom directory or a Bazel label for the docker client config.json. " +
"If DOCKER_CONFIG is not specified, the value of the " +
"DOCKER_CONFIG environment variable will be used. " +
"DOCKER_CONFIG is not defined, the home directory will be " +
"used.",
Expand Down Expand Up @@ -189,7 +189,7 @@ toolchain_configure = repository_rule(
),
"client_config": attr.string(
mandatory = False,
doc = "A custom directory for the docker client " +
doc = "A custom directory or a Bazel label for the docker client" +
"config.json. If DOCKER_CONFIG is not specified, the value " +
"of the DOCKER_CONFIG environment variable will be used. " +
"DOCKER_CONFIG is not defined, the default set for the " +
Expand Down

0 comments on commit a17900c

Please sign in to comment.