Skip to content

Commit 42157c2

Browse files
committed
WIP: Starting to build puller/pusher instead of downloading
1 parent b886744 commit 42157c2

File tree

272 files changed

+42791
-43
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

272 files changed

+42791
-43
lines changed

container/BUILD

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bzl_library(
7878
bzl_library(
7979
name = "container.docs",
8080
srcs = ["container.docs.bzl"],
81-
deps = ["container"],
81+
deps = [":container"],
8282
)
8383

8484
bzl_library(
@@ -98,6 +98,7 @@ bzl_library(
9898
":layer",
9999
":layer_tools",
100100
":providers",
101+
"//internal:execution_bzl",
101102
"//skylib:filetype",
102103
"//skylib:label",
103104
"//skylib:path",

container/pull.bzl

+27-36
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
"container_pull rule"
15+
16+
load("//internal:execution.bzl", "env_execute", "executable_extension")
17+
1518
_DOC = """A repository rule that pulls down a Docker base image in a manner suitable for use with the `base` attribute of `container_image`.
1619
1720
This is based on google/containerregistry using google/go-containerregistry.
@@ -81,30 +84,6 @@ _container_pull_attrs = {
8184
"platform_features": attr.string_list(
8285
doc = "Specifies platform features when pulling a multi-platform manifest list.",
8386
),
84-
"puller_darwin": attr.label(
85-
executable = True,
86-
default = Label("@go_puller_darwin//file:downloaded"),
87-
cfg = "host",
88-
doc = "Exposed to provide a way to test other pullers on macOS",
89-
),
90-
"puller_linux_amd64": attr.label(
91-
executable = True,
92-
default = Label("@go_puller_linux_amd64//file:downloaded"),
93-
cfg = "host",
94-
doc = "Exposed to provide a way to test other pullers on Linux",
95-
),
96-
"puller_linux_arm64": attr.label(
97-
executable = True,
98-
default = Label("@go_puller_linux_arm64//file:downloaded"),
99-
cfg = "host",
100-
doc = "Exposed to provide a way to test other pullers on Linux",
101-
),
102-
"puller_linux_s390x": attr.label(
103-
executable = True,
104-
default = Label("@go_puller_linux_s390x//file:downloaded"),
105-
cfg = "host",
106-
doc = "Exposed to provide a way to test other pullers on Linux",
107-
),
10887
"registry": attr.string(
10988
mandatory = True,
11089
doc = "The registry from which we are pulling.",
@@ -136,18 +115,9 @@ def _impl(repository_ctx):
136115

137116
import_rule_tags = "[\"{}\"]".format("\", \"".join(repository_ctx.attr.import_tags))
138117

139-
puller = repository_ctx.attr.puller_linux_amd64
140-
if repository_ctx.os.name.lower().startswith("mac os"):
141-
puller = repository_ctx.attr.puller_darwin
142-
elif repository_ctx.os.name.lower().startswith("linux"):
143-
arch = repository_ctx.execute(["uname", "-m"]).stdout.strip()
144-
if arch == "arm64" or arch == "aarch64":
145-
puller = repository_ctx.attr.puller_linux_arm64
146-
elif arch == "s390x":
147-
puller = repository_ctx.attr.puller_linux_s390x
148-
118+
puller = str(repository_ctx.path(Label("@rules_docker_repository_tools//:bin/puller{}".format(executable_extension(repository_ctx)))))
149119
args = [
150-
repository_ctx.path(puller),
120+
puller,
151121
"-directory",
152122
repository_ctx.path("image"),
153123
"-os",
@@ -211,7 +181,28 @@ def _impl(repository_ctx):
211181
else:
212182
fail("'%s' is invalid value for PULLER_TIMEOUT. Must be an integer." % (timeout_in_secs))
213183

214-
result = repository_ctx.execute(args, **kwargs)
184+
env = {
185+
k: v
186+
for k, v in repository_ctx.os.environ.items()
187+
if k.lower() in (
188+
"home",
189+
190+
# Unfortunately we explicitly need to pass along PATH. This prevents these CI failures:
191+
# https://buildkite-cloud.s3.amazonaws.com/logs-by-pipeline/975a9deb-b320-454c-bbbd-f48ff8715013/a909ba30-d7c1-4933-8967-b065cd26ada6/3627cc09-b972-4ef9-b016-1769b5f1bc1e.log?response-content-disposition=inline&response-content-type=text%2Fplain&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAQPCP3C7L5YYASYPJ%2F20210729%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210729T213055Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Security-Token=IQo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%2BEfSu2WsBhkOkcmHuqIqF0iNNx%2Bu292PQ3LtTM7qwMECzZLqgat%2FRV%2BeJ61hxVsgw%3D%3D&X-Amz-Signature=19b6022f09bafab8b72b9ec16bd970af72328d1aafe4303f93a1dcd3540c73ef
192+
# TODO(gravypod): Find out how to avoid needing to do this. Might need to refactor puller.
193+
"path",
194+
195+
# Only allow environment variables that influence the pusher through.
196+
"ssh_auth_sock",
197+
"ssl_cert_file",
198+
"ssl_cert_dir",
199+
"http_proxy",
200+
"https_proxy",
201+
"no_proxy",
202+
)
203+
}
204+
205+
result = env_execute(repository_ctx, args, environment = env, **kwargs)
215206
if result.return_code:
216207
fail("Pull command failed: %s (%s)" % (result.stderr, " ".join([str(a) for a in args])))
217208

docs/container.md

+1-6
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ The created target can be referenced as `@label_name//image`.
150150

151151
<pre>
152152
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>,
153-
<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>,
154-
<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>)
153+
<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-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>)
155154
</pre>
156155

157156
A repository rule that pulls down a Docker base image in a manner suitable for use with the `base` attribute of `container_image`.
@@ -191,10 +190,6 @@ please use the bazel startup flag `--loading_phase_threads=1` in your bazel invo
191190
| <a id="container_pull-os_features"></a>os_features | Specifies os features when pulling a multi-platform manifest list. | List of strings | optional | [] |
192191
| <a id="container_pull-os_version"></a>os_version | Which os version to pull if this image refers to a multi-platform manifest list. | String | optional | "" |
193192
| <a id="container_pull-platform_features"></a>platform_features | Specifies platform features when pulling a multi-platform manifest list. | List of strings | optional | [] |
194-
| <a id="container_pull-puller_darwin"></a>puller_darwin | Exposed to provide a way to test other pullers on macOS | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | @go_puller_darwin//file:downloaded |
195-
| <a id="container_pull-puller_linux_amd64"></a>puller_linux_amd64 | Exposed to provide a way to test other pullers on Linux | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | @go_puller_linux_amd64//file:downloaded |
196-
| <a id="container_pull-puller_linux_arm64"></a>puller_linux_arm64 | Exposed to provide a way to test other pullers on Linux | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | @go_puller_linux_arm64//file:downloaded |
197-
| <a id="container_pull-puller_linux_s390x"></a>puller_linux_s390x | Exposed to provide a way to test other pullers on Linux | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | @go_puller_linux_s390x//file:downloaded |
198193
| <a id="container_pull-registry"></a>registry | The registry from which we are pulling. | String | required | |
199194
| <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 | |
200195
| <a id="container_pull-repository"></a>repository | The name of the image. | String | required | |

0 commit comments

Comments
 (0)