|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 | "container_pull rule"
|
| 15 | + |
| 16 | +load("//internal:execution.bzl", "env_execute", "executable_extension") |
| 17 | + |
15 | 18 | _DOC = """A repository rule that pulls down a Docker base image in a manner suitable for use with the `base` attribute of `container_image`.
|
16 | 19 |
|
17 | 20 | This is based on google/containerregistry using google/go-containerregistry.
|
@@ -81,30 +84,6 @@ _container_pull_attrs = {
|
81 | 84 | "platform_features": attr.string_list(
|
82 | 85 | doc = "Specifies platform features when pulling a multi-platform manifest list.",
|
83 | 86 | ),
|
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 |
| - ), |
108 | 87 | "registry": attr.string(
|
109 | 88 | mandatory = True,
|
110 | 89 | doc = "The registry from which we are pulling.",
|
@@ -136,18 +115,9 @@ def _impl(repository_ctx):
|
136 | 115 |
|
137 | 116 | import_rule_tags = "[\"{}\"]".format("\", \"".join(repository_ctx.attr.import_tags))
|
138 | 117 |
|
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))))) |
149 | 119 | args = [
|
150 |
| - repository_ctx.path(puller), |
| 120 | + puller, |
151 | 121 | "-directory",
|
152 | 122 | repository_ctx.path("image"),
|
153 | 123 | "-os",
|
@@ -211,7 +181,28 @@ def _impl(repository_ctx):
|
211 | 181 | else:
|
212 | 182 | fail("'%s' is invalid value for PULLER_TIMEOUT. Must be an integer." % (timeout_in_secs))
|
213 | 183 |
|
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=IQoJb3JpZ2luX2VjEIz%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLWVhc3QtMSJGMEQCICqdixAGiKRY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-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) |
215 | 206 | if result.return_code:
|
216 | 207 | fail("Pull command failed: %s (%s)" % (result.stderr, " ".join([str(a) for a in args])))
|
217 | 208 |
|
|
0 commit comments