Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comments on Pr349 #378

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions oci/private/pull.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ _SUPPORTED_MEDIA_TYPES = {
"manifest": [
"application/vnd.docker.distribution.manifest.v2+json",
"application/vnd.oci.image.manifest.v1+json",
# See https://helm.sh/blog/helm-oci-mediatypes/
"application/vnd.cncf.helm.config.v1+json",
],
}

Expand Down Expand Up @@ -292,7 +294,7 @@ Falling back to using `curl`. See https://github.com/bazelbuild/bazel/issues/178
)
bytes = rctx.read(output)
manifest = json.decode(bytes)
digest = "sha256:{}".format(util.sha256(rctx, output))
digest = "sha256:{}".format(util.sha256(rctx, output))

return manifest, len(bytes), digest

Expand Down Expand Up @@ -372,12 +374,21 @@ def _find_platform_manifest(image_mf, platform_wanted):
return mf
return None

def _determine_media_type(mf):
if "mediaType" in mf:
return mf["mediaType"]
elif "config" in mf and "mediaType" in mf["config"]:
# Allow for manifests that are malformed, like some Helm charts, see #349
return mf["config"]["mediaType"]
else:
fail("Unable to determine mediaType from manifest {}".format(mf))

def _oci_pull_impl(rctx):
downloader = _create_downloader(rctx)

mf, mf_len, mf_digest = downloader.download_manifest(rctx.attr.identifier, "manifest.json")

if mf["mediaType"] in _SUPPORTED_MEDIA_TYPES["manifest"]:
media_type = _determine_media_type(mf)
if media_type in _SUPPORTED_MEDIA_TYPES["manifest"]:
if rctx.attr.platform:
fail("{}/{} is a single-architecture image, so attribute 'platforms' should not be set.".format(rctx.attr.registry, rctx.attr.repository))

Expand All @@ -395,7 +406,7 @@ def _oci_pull_impl(rctx):
image_mf, image_mf_len, image_digest = downloader.download_manifest(matching_mf["digest"], "manifest.json")

else:
fail("Unrecognized mediaType {} in manifest file".format(mf["mediaType"]))
fail("Unrecognized mediaType {} in manifest file".format(media_type))

image_config_file = _trim_hash_algorithm(image_mf["config"]["digest"])
downloader.download_blob(image_mf["config"]["digest"], image_config_file)
Expand All @@ -410,13 +421,13 @@ def _oci_pull_impl(rctx):
tars.append(hash)

rctx.file("index.json", util.build_manifest_json(
media_type = image_mf["mediaType"],
media_type = _determine_media_type(image_mf),
size = image_mf_len,
digest = image_digest,
platform = rctx.attr.platform
platform = rctx.attr.platform,
))
rctx.file("oci-layout", json.encode_indent({"imageLayoutVersion": "1.0.0"}, indent = " "))

rctx.file("BUILD.bazel", content = _build_file.format(
target_name = rctx.attr.target_name,
tars = tars,
Expand Down
Loading