Skip to content

Commit 84043cc

Browse files
authored
feat: add timeout attribute to container_pull (#1960)
The PULLER_TIMEOUT env variable is convenient, but one very large image shouldn't require that all of them have timeouts changed.
1 parent 8f6a2aa commit 84043cc

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

container/pull.bzl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ construct new images.
2222
NOTE: `container_pull` now supports authentication using custom docker client configuration.
2323
See [here](https://github.com/bazelbuild/rules_docker#container_pull-custom-client-configuration) for details.
2424
25-
NOTE: Set `PULLER_TIMEOUT` env variable to change the default 600s timeout.
25+
NOTE: Set `PULLER_TIMEOUT` env variable to change the default 600s timeout for all container_pull targets.
2626
2727
NOTE: Set `DOCKER_REPO_CACHE` env variable to make the container puller cache downloaded layers at the directory specified as a value to this env variable.
2828
The caching feature hasn't been thoroughly tested and may be thread unsafe.
@@ -123,6 +123,11 @@ _container_pull_attrs = {
123123
Note: For reproducible builds, use of `digest` is recommended.
124124
""",
125125
),
126+
"timeout": attr.int(
127+
doc = """Timeout in seconds to fetch the image from the registry.
128+
129+
This attribute will be overridden by the PULLER_TIMEOUT environment variable, if it is set.""",
130+
),
126131
}
127132

128133
def _impl(repository_ctx):
@@ -210,6 +215,9 @@ def _impl(repository_ctx):
210215
kwargs["timeout"] = int(timeout_in_secs)
211216
else:
212217
fail("'%s' is invalid value for PULLER_TIMEOUT. Must be an integer." % (timeout_in_secs))
218+
elif repository_ctx.attr.timeout > 0:
219+
args.extend(["-timeout", str(repository_ctx.attr.timeout)])
220+
kwargs["timeout"] = repository_ctx.attr.timeout
213221

214222
result = repository_ctx.execute(args, **kwargs)
215223
if result.return_code:

docs/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ stardoc(
2020
# If these fail, run `bazel run //docs:update`
2121
diff_test(
2222
name = "check_container",
23+
failure_message = "Please run bazel run //docs:update",
2324
file1 = "container.md",
2425
file2 = ":container_doc",
2526
)

docs/container.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ The created target can be referenced as `@label_name//image`.
152152
<pre>
153153
container_pull(<a href="#container_pull-name">name</a>, <a href="#container_pull-architecture">architecture</a>, <a href="#container_pull-cpu_variant">cpu_variant</a>, <a href="#container_pull-digest">digest</a>, <a href="#container_pull-docker_client_config">docker_client_config</a>, <a href="#container_pull-import_tags">import_tags</a>, <a href="#container_pull-os">os</a>,
154154
<a href="#container_pull-os_features">os_features</a>, <a href="#container_pull-os_version">os_version</a>, <a href="#container_pull-platform_features">platform_features</a>, <a href="#container_pull-puller_darwin">puller_darwin</a>, <a href="#container_pull-puller_linux_amd64">puller_linux_amd64</a>,
155-
<a href="#container_pull-puller_linux_arm64">puller_linux_arm64</a>, <a href="#container_pull-puller_linux_s390x">puller_linux_s390x</a>, <a href="#container_pull-registry">registry</a>, <a href="#container_pull-repo_mapping">repo_mapping</a>, <a href="#container_pull-repository">repository</a>, <a href="#container_pull-tag">tag</a>)
155+
<a href="#container_pull-puller_linux_arm64">puller_linux_arm64</a>, <a href="#container_pull-puller_linux_s390x">puller_linux_s390x</a>, <a href="#container_pull-registry">registry</a>, <a href="#container_pull-repo_mapping">repo_mapping</a>, <a href="#container_pull-repository">repository</a>, <a href="#container_pull-tag">tag</a>,
156+
<a href="#container_pull-timeout">timeout</a>)
156157
</pre>
157158

158159
A repository rule that pulls down a Docker base image in a manner suitable for use with the `base` attribute of `container_image`.
@@ -165,7 +166,7 @@ construct new images.
165166
NOTE: `container_pull` now supports authentication using custom docker client configuration.
166167
See [here](https://github.com/bazelbuild/rules_docker#container_pull-custom-client-configuration) for details.
167168

168-
NOTE: Set `PULLER_TIMEOUT` env variable to change the default 600s timeout.
169+
NOTE: Set `PULLER_TIMEOUT` env variable to change the default 600s timeout for all container_pull targets.
169170

170171
NOTE: Set `DOCKER_REPO_CACHE` env variable to make the container puller cache downloaded layers at the directory specified as a value to this env variable.
171172
The caching feature hasn't been thoroughly tested and may be thread unsafe.
@@ -200,6 +201,7 @@ please use the bazel startup flag `--loading_phase_threads=1` in your bazel invo
200201
| <a id="container_pull-repo_mapping"></a>repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.&lt;p&gt;For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>). | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | required | |
201202
| <a id="container_pull-repository"></a>repository | The name of the image. | String | required | |
202203
| <a id="container_pull-tag"></a>tag | The <code>tag</code> of the Docker image to pull from the specified <code>repository</code>.<br><br> If neither this nor <code>digest</code> is specified, this attribute defaults to <code>latest</code>. If both are specified, then <code>tag</code> is ignored.<br><br> Note: For reproducible builds, use of <code>digest</code> is recommended. | String | optional | "latest" |
204+
| <a id="container_pull-timeout"></a>timeout | Timeout in seconds to fetch the image from the registry.<br><br> This attribute will be overridden by the PULLER_TIMEOUT environment variable, if it is set. | Integer | optional | 0 |
203205

204206

205207
<a id="#container_push"></a>

repositories/repositories.bzl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ def repositories():
170170
if "bazel_skylib" not in excludes:
171171
http_archive(
172172
name = "bazel_skylib",
173-
sha256 = "7ac0fa88c0c4ad6f5b9ffb5e09ef81e235492c873659e6bb99efb89d11246bcb",
174-
strip_prefix = "bazel-skylib-1.0.3",
175-
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/1.0.3.tar.gz"],
173+
urls = [
174+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
175+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
176+
],
177+
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
176178
)
177179

178180
if "bazel_gazelle" not in excludes:

0 commit comments

Comments
 (0)