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

feat: oci_pull supports loading Helm charts #349

Closed
wants to merge 3 commits into from
Closed
Changes from 2 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
21 changes: 16 additions & 5 deletions oci/private/pull.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ _SUPPORTED_MEDIA_TYPES = {
"manifest": [
"application/vnd.docker.distribution.manifest.v2+json",
"application/vnd.oci.image.manifest.v1+json",
"application/vnd.cncf.helm.config.v1+json",
alexeagle marked this conversation as resolved.
Show resolved Hide resolved
],
}

Expand Down Expand Up @@ -358,7 +359,12 @@ def _oci_pull_impl(rctx):

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

if mf["mediaType"] in _SUPPORTED_MEDIA_TYPES["manifest"]:
if "mediaType" in mf:
media_type = mf["mediaType"]
else:
media_type = mf["config"]["mediaType"]
alexeagle marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -367,7 +373,7 @@ def _oci_pull_impl(rctx):
image_digest = rctx.attr.identifier
if _is_tag(rctx.attr.identifier):
image_digest = "sha256:{}".format(util.sha256(rctx, "manifest.json"))
elif mf["mediaType"] in _SUPPORTED_MEDIA_TYPES["index"]:
elif media_type in _SUPPORTED_MEDIA_TYPES["index"]:
# extra download to get the manifest for the selected arch
if not rctx.attr.platform:
fail("{}/{} is a multi-architecture image, so attribute 'platforms' is required.".format(rctx.attr.registry, rctx.attr.repository))
Expand All @@ -377,7 +383,7 @@ def _oci_pull_impl(rctx):
image_digest = matching_mf["digest"]
image_mf, image_mf_len = downloader.download_manifest(image_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 @@ -391,6 +397,11 @@ def _oci_pull_impl(rctx):
if hash not in tars:
tars.append(hash)

if "mediaType" in image_mf:
alexeagle marked this conversation as resolved.
Show resolved Hide resolved
image_media_type = image_mf["mediaType"]
else:
image_media_type = image_mf["config"]["mediaType"]

# To make testing against `crane pull` simple, we take care to produce a byte-for-byte-identical
# index.json file, which means we can't use jq (it produces a trailing newline) or starlark
# json.encode_indent (it re-orders keys in the dictionary).
Expand All @@ -411,7 +422,7 @@ def _oci_pull_impl(rctx):
}
}
]
}""" % (image_mf["mediaType"], image_mf_len, image_digest, arch, os)
}""" % (image_media_type, image_mf_len, image_digest, arch, os)
else:
index_mf = """\
{
Expand All @@ -424,7 +435,7 @@ def _oci_pull_impl(rctx):
"digest": "%s"
}
]
}""" % (image_mf["mediaType"], image_mf_len, image_digest)
}""" % (image_media_type, image_mf_len, image_digest)

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