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
@@ -38,15 +38,16 @@ _IMAGE_REFERENCE_ATTRS = {
38
38
SCHEMA1_ERROR = """\
39
39
The registry sent a manifest with schemaVersion=1.
40
40
This commonly occurs when fetching from a registry that needs the Docker-Distribution-API-Version header to be set.
41
+ See: https://github.com/bazel-contrib/rules_oci/blob/main/docs/pull.md#authentication-using-credential-helpers
41
42
"""
42
43
43
44
OCI_MEDIA_TYPE_OR_AUTHN_ERROR = """\
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
+ Unable to retrieve the image manifest. This could be due to authentication problems or an attempt to fetch an image with OCI image media types.
46
+ See: https://github.com/bazel-contrib/rules_oci/blob/main/docs/pull.md#authentication-using-credential-helpers
45
47
"""
46
48
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
49
+ OCI_MEDIA_TYPE_OR_AUTHN_ERROR_BAZEL7 = """\
50
+ Unable to retrieve the image manifest. This could be due to authentication problems.
50
51
"""
51
52
52
53
# Supported media types
@@ -85,7 +86,7 @@ def _digest_into_blob_path(digest):
85
86
digest_path = digest .replace (":" , "/" , 1 )
86
87
return "blobs/{}" .format (digest_path )
87
88
88
- def _download (rctx , authn , identifier , output , resource , download_fn = download . bazel , headers = {}, allow_fail = False ):
89
+ def _download (rctx , authn , identifier , output , resource , headers = {}, allow_fail = False ):
89
90
"Use the Bazel Downloader to fetch from the remote registry"
90
91
91
92
if resource != "blobs" and resource != "manifests" :
@@ -108,17 +109,19 @@ def _download(rctx, authn, identifier, output, resource, download_fn = download.
108
109
if identifier .startswith ("sha256:" ):
109
110
sha256 = identifier [len ("sha256:" ):]
110
111
else :
111
- util .warning (rctx , "Fetching from {}@{} without an integrity hash. The result will not be cached." .format (rctx .attr .repository , identifier ))
112
+ util .warning (rctx , "Fetching from {}@{} without an integrity hash, result will not be cached." .format (rctx .attr .repository , identifier ))
112
113
113
- return download_fn (
114
- rctx ,
114
+ kwargs = dict (
115
115
output = output ,
116
116
sha256 = sha256 ,
117
117
url = registry_url ,
118
118
auth = {registry_url : auth },
119
- headers = headers ,
120
119
allow_fail = allow_fail ,
121
120
)
121
+ if versions .is_at_least ("7.1.0" , versions .get ()):
122
+ return rctx .download (headers = headers , ** kwargs )
123
+ else :
124
+ return rctx .download (** kwargs )
122
125
123
126
def _download_manifest (rctx , authn , identifier , output ):
124
127
bytes = None
@@ -135,35 +138,19 @@ def _download_manifest(rctx, authn, identifier, output):
135
138
headers = _DOWNLOAD_HEADERS ,
136
139
)
137
140
138
- fallback_to_curl = False
139
141
if result .success :
140
142
bytes = rctx .read (output )
141
143
manifest = json .decode (bytes )
142
144
digest = "sha256:{}" .format (result .sha256 )
143
145
if manifest ["schemaVersion" ] == 1 :
144
- fallback_to_curl = True
145
- util .warning (rctx , SCHEMA1_ERROR )
146
+ fail (SCHEMA1_ERROR )
146
147
else :
147
- fallback_to_curl = True
148
- util .warning (rctx , OCI_MEDIA_TYPE_OR_AUTHN_ERROR )
149
148
explanation = authn .explain ()
150
149
if explanation :
151
150
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 ,
151
+ fail (
152
+ OCI_MEDIA_TYPE_OR_AUTHN_ERROR_BAZEL7 if versions .is_at_least ("7.1.0" , versions .get ()) else OCI_MEDIA_TYPE_OR_AUTHN_ERROR ,
163
153
)
164
- bytes = rctx .read (output )
165
- manifest = json .decode (bytes )
166
- digest = "sha256:{}" .format (util .sha256 (rctx , output ))
167
154
168
155
return manifest , len (bytes ), digest
169
156
0 commit comments