Skip to content

Commit d787152

Browse files
committed
refactor: remote curl fallback
1 parent cbff154 commit d787152

File tree

4 files changed

+18
-170
lines changed

4 files changed

+18
-170
lines changed

fetch.bzl

+8-6
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@ def fetch_images():
3131
],
3232
)
3333

34-
# Pull an image from public ECR.
34+
# Pull an image from public ECR.
3535
# When --credential_helper is provided, see .bazelrc at workspace root, it will take precende over
36-
# auth from oci_pull. However, pulling from public ECR works out of the box so this will never fail
36+
# auth from oci_pull. However, pulling from public ECR works out of the box so this will never fail
3737
# unless oci_pull's authentication mechanism breaks and --credential_helper is absent.
3838
oci_pull(
3939
name = "ecr_lambda_python",
4040
image = "public.ecr.aws/lambda/python",
4141
tag = "3.11.2024.01.25.10",
42+
# digest = "sha256:9499013bebe91a97ad3925269d1097408c092d85a1f6b96f91c7bb3a100e2c18",
4243
platforms = [
4344
"linux/amd64",
44-
"linux/arm64/v8"
45-
]
45+
"linux/arm64/v8",
46+
],
4647
)
4748

4849
# Show that the digest is optional.
@@ -141,6 +142,7 @@ def fetch_images():
141142
oci_pull(
142143
name = "fluxcd_flux",
143144
image = "docker.io/fluxcd/flux:1.25.4",
145+
# digest = "sha256:c18e0c96fbb510fffa27ca0fb2561c2124e74f975a8a826d1f33cd4c82552db1"
144146
)
145147

146148
oci_pull(
@@ -172,7 +174,7 @@ def fetch_images():
172174
digest = "sha256:9a83bce5d337e7e19d789ee7f952d36d0d514c80987c3d76d90fd1afd2411a9a",
173175
platforms = [
174176
"linux/amd64",
175-
"linux/arm64"
177+
"linux/arm64",
176178
],
177179
)
178180

@@ -183,7 +185,7 @@ def fetch_images():
183185
digest = "sha256:8d38ffa8fad72f4bc2647644284c16491cc2d375602519a1f963f96ccc916276",
184186
platforms = [
185187
"linux/amd64",
186-
"linux/arm64"
188+
"linux/arm64",
187189
],
188190
)
189191

oci/private/BUILD.bazel

-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ bzl_library(
5151
],
5252
deps = [
5353
"//oci/private:authn",
54-
"//oci/private:download",
5554
"//oci/private:util",
5655
"@bazel_skylib//lib:dicts",
5756
],
@@ -84,13 +83,6 @@ bzl_library(
8483
visibility = ["//oci:__subpackages__"],
8584
)
8685

87-
bzl_library(
88-
name = "download",
89-
srcs = ["download.bzl"],
90-
visibility = ["//oci:__subpackages__"],
91-
deps = ["@bazel_skylib//lib:versions"],
92-
)
93-
9486
bzl_library(
9587
name = "authn",
9688
srcs = ["authn.bzl"],

oci/private/download.bzl

-125
This file was deleted.

oci/private/pull.bzl

+10-31
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"Implementation details for oci_pull repository rules"
22

33
load("@bazel_skylib//lib:dicts.bzl", "dicts")
4+
load("@bazel_skylib//lib:versions.bzl", "versions")
45
load("//oci/private:authn.bzl", "authn")
5-
load("//oci/private:download.bzl", "download")
66
load("//oci/private:util.bzl", "util")
77

88
# attributes that are specific to image reference url. shared between multiple targets
@@ -44,11 +44,6 @@ OCI_MEDIA_TYPE_OR_AUTHN_ERROR = """\
4444
Unable to retrieve the manifest. This could be due to authentication problems or an attempt to fetch an image with OCI image media types.
4545
"""
4646

47-
CURL_FALLBACK_WARNING = """\
48-
The use of Curl fallback is deprecated and is set to be removed in version 2.0.
49-
For more details, refer to: https://github.com/bazel-contrib/rules_oci/issues/456
50-
"""
51-
5247
# Supported media types
5348
# * OCI spec: https://github.com/opencontainers/image-spec/blob/main/media-types.md
5449
# * Docker spec: https://github.com/distribution/distribution/blob/main/docs/spec/manifest-v2-2.md#media-types
@@ -85,7 +80,7 @@ def _digest_into_blob_path(digest):
8580
digest_path = digest.replace(":", "/", 1)
8681
return "blobs/{}".format(digest_path)
8782

88-
def _download(rctx, authn, identifier, output, resource, download_fn = download.bazel, headers = {}, allow_fail = False):
83+
def _download(rctx, authn, identifier, output, resource, headers = {}, allow_fail = False):
8984
"Use the Bazel Downloader to fetch from the remote registry"
9085

9186
if resource != "blobs" and resource != "manifests":
@@ -108,17 +103,19 @@ def _download(rctx, authn, identifier, output, resource, download_fn = download.
108103
if identifier.startswith("sha256:"):
109104
sha256 = identifier[len("sha256:"):]
110105
else:
111-
util.warning(rctx, "Fetching from {}@{} without an integrity hash. The result will not be cached.".format(rctx.attr.repository, identifier))
106+
util.warning(rctx, "Fetching from {}@{} without an integrity hash, result will not be cached.".format(rctx.attr.repository, identifier))
112107

113-
return download_fn(
114-
rctx,
108+
kwargs = dict(
115109
output = output,
116110
sha256 = sha256,
117111
url = registry_url,
118112
auth = {registry_url: auth},
119-
headers = headers,
120113
allow_fail = allow_fail,
121114
)
115+
if versions.is_at_least("7.1.0", versions.get()):
116+
return rctx.download(headers = headers, **kwargs)
117+
else:
118+
return rctx.download(**kwargs)
122119

123120
def _download_manifest(rctx, authn, identifier, output):
124121
bytes = None
@@ -135,35 +132,17 @@ def _download_manifest(rctx, authn, identifier, output):
135132
headers = _DOWNLOAD_HEADERS,
136133
)
137134

138-
fallback_to_curl = False
139135
if result.success:
140136
bytes = rctx.read(output)
141137
manifest = json.decode(bytes)
142138
digest = "sha256:{}".format(result.sha256)
143139
if manifest["schemaVersion"] == 1:
144-
fallback_to_curl = True
145-
util.warning(rctx, SCHEMA1_ERROR)
140+
fail(SCHEMA1_ERROR)
146141
else:
147-
fallback_to_curl = True
148-
util.warning(rctx, OCI_MEDIA_TYPE_OR_AUTHN_ERROR)
149142
explanation = authn.explain()
150143
if explanation:
151144
util.warning(rctx, explanation)
152-
153-
if fallback_to_curl:
154-
util.warning(rctx, CURL_FALLBACK_WARNING)
155-
_download(
156-
rctx,
157-
authn,
158-
identifier,
159-
output,
160-
"manifests",
161-
download.curl,
162-
headers = _DOWNLOAD_HEADERS,
163-
)
164-
bytes = rctx.read(output)
165-
manifest = json.decode(bytes)
166-
digest = "sha256:{}".format(util.sha256(rctx, output))
145+
fail(OCI_MEDIA_TYPE_OR_AUTHN_ERROR)
167146

168147
return manifest, len(bytes), digest
169148

0 commit comments

Comments
 (0)