1
1
"Implementation details for oci_pull repository rules"
2
2
3
3
load ("@bazel_skylib//lib:dicts.bzl" , "dicts" )
4
+ load ("@bazel_skylib//lib:versions.bzl" , "versions" )
4
5
load ("//oci/private:authn.bzl" , "authn" )
5
- load ("//oci/private:download.bzl" , "download" )
6
6
load ("//oci/private:util.bzl" , "util" )
7
7
8
8
# attributes that are specific to image reference url. shared between multiple targets
@@ -44,11 +44,6 @@ OCI_MEDIA_TYPE_OR_AUTHN_ERROR = """\
44
44
Unable to retrieve the manifest. This could be due to authentication problems or an attempt to fetch an image with OCI image media types.
45
45
"""
46
46
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
-
52
47
# Supported media types
53
48
# * OCI spec: https://github.com/opencontainers/image-spec/blob/main/media-types.md
54
49
# * 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):
85
80
digest_path = digest .replace (":" , "/" , 1 )
86
81
return "blobs/{}" .format (digest_path )
87
82
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 ):
89
84
"Use the Bazel Downloader to fetch from the remote registry"
90
85
91
86
if resource != "blobs" and resource != "manifests" :
@@ -108,17 +103,19 @@ def _download(rctx, authn, identifier, output, resource, download_fn = download.
108
103
if identifier .startswith ("sha256:" ):
109
104
sha256 = identifier [len ("sha256:" ):]
110
105
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 ))
112
107
113
- return download_fn (
114
- rctx ,
108
+ kwargs = dict (
115
109
output = output ,
116
110
sha256 = sha256 ,
117
111
url = registry_url ,
118
112
auth = {registry_url : auth },
119
- headers = headers ,
120
113
allow_fail = allow_fail ,
121
114
)
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 )
122
119
123
120
def _download_manifest (rctx , authn , identifier , output ):
124
121
bytes = None
@@ -135,35 +132,17 @@ def _download_manifest(rctx, authn, identifier, output):
135
132
headers = _DOWNLOAD_HEADERS ,
136
133
)
137
134
138
- fallback_to_curl = False
139
135
if result .success :
140
136
bytes = rctx .read (output )
141
137
manifest = json .decode (bytes )
142
138
digest = "sha256:{}" .format (result .sha256 )
143
139
if manifest ["schemaVersion" ] == 1 :
144
- fallback_to_curl = True
145
- util .warning (rctx , SCHEMA1_ERROR )
140
+ fail (SCHEMA1_ERROR )
146
141
else :
147
- fallback_to_curl = True
148
- util .warning (rctx , OCI_MEDIA_TYPE_OR_AUTHN_ERROR )
149
142
explanation = authn .explain ()
150
143
if explanation :
151
144
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 )
167
146
168
147
return manifest , len (bytes ), digest
169
148
0 commit comments