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

Commit

Permalink
feat: add timeout attribute to container_pull
Browse files Browse the repository at this point in the history
The PULLER_TIMEOUT env variable is convenient, but one very large image shouldn't require that all of them have timeouts changed.
  • Loading branch information
alexeagle committed Nov 17, 2021
1 parent 8f6a2aa commit 7652779
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions container/pull.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ construct new images.
NOTE: `container_pull` now supports authentication using custom docker client configuration.
See [here](https://github.com/bazelbuild/rules_docker#container_pull-custom-client-configuration) for details.
NOTE: Set `PULLER_TIMEOUT` env variable to change the default 600s timeout.
NOTE: Set `PULLER_TIMEOUT` env variable to change the default 600s timeout for all container_pull targets.
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.
The caching feature hasn't been thoroughly tested and may be thread unsafe.
Expand Down Expand Up @@ -123,6 +123,11 @@ _container_pull_attrs = {
Note: For reproducible builds, use of `digest` is recommended.
""",
),
"timeout": attr.int(
doc = """Timeout in seconds to fetch the image from the registry.
If specified, this overrides the value from the PULLER_TIMEOUT environment variable.""",
),
}

def _impl(repository_ctx):
Expand Down Expand Up @@ -200,7 +205,10 @@ def _impl(repository_ctx):

kwargs = {}

if "PULLER_TIMEOUT" in repository_ctx.os.environ:
if repository_ctx.attr.timeout > 0:
args.extend(["-timeout", str(repository_ctx.attr.timeout)])
kwargs["timeout"] = repository_ctx.attr.timeout
elif "PULLER_TIMEOUT" in repository_ctx.os.environ:
timeout_in_secs = repository_ctx.os.environ["PULLER_TIMEOUT"]
if timeout_in_secs.isdigit():
args += [
Expand Down

0 comments on commit 7652779

Please sign in to comment.