Skip to content

Commit

Permalink
oci: allow oci artifact registration (PROJQUAY-1032) (#803)
Browse files Browse the repository at this point in the history
Allow registration of custom oci artifact types in Quay's configuration.
  • Loading branch information
kleesc committed Jul 26, 2021
1 parent 0999baa commit 64bc11f
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@

# Register additional experimental artifact types.
# TODO: extract this into a real, dynamic registration system.
if features.GENERAL_OCI_SUPPORT:
for media_type, layer_types in app.config.get("ALLOWED_OCI_ARTIFACT_TYPES").items():
register_artifact_type(media_type, layer_types)

if features.HELM_OCI_SUPPORT:
HELM_CHART_CONFIG_TYPE = "application/vnd.cncf.helm.config.v1+json"
HELM_CHART_LAYER_TYPES = ["application/tar+gzip"]
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ def create_transaction(db):

# Feature Flag: Whether OCI manifest support should be enabled generally.
FEATURE_GENERAL_OCI_SUPPORT = True
ALLOWED_OCI_ARTIFACT_TYPES = {}

# Feature Flag: Whether to allow Helm OCI content types.
# See: https://helm.sh/docs/topics/registries/
Expand Down
1 change: 1 addition & 0 deletions endpoints/api/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def _manifest_dict(manifest):
"digest": manifest.digest,
"is_manifest_list": manifest.is_manifest_list,
"manifest_data": manifest.internal_manifest_bytes.as_unicode(),
"config_media_type": manifest.config_media_type,
"layers": (
[_layer_dict(lyr.layer_info, idx) for idx, lyr in enumerate(layers)] if layers else None
),
Expand Down
8 changes: 6 additions & 2 deletions image/oci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@


def register_artifact_type(artifact_config_type, artifact_layer_types):
ALLOWED_ARTIFACT_TYPES.append(artifact_config_type)
ADDITIONAL_LAYER_CONTENT_TYPES.extend(artifact_layer_types)
if artifact_config_type not in ALLOWED_ARTIFACT_TYPES:
ALLOWED_ARTIFACT_TYPES.append(artifact_config_type)

for layer_type in artifact_layer_types:
if layer_type not in ADDITIONAL_LAYER_CONTENT_TYPES:
ADDITIONAL_LAYER_CONTENT_TYPES.append(layer_type)
34 changes: 34 additions & 0 deletions image/oci/test/test_oci_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

import pytest

from image.oci import (
register_artifact_type,
ALLOWED_ARTIFACT_TYPES,
ADDITIONAL_LAYER_CONTENT_TYPES,
OCI_IMAGE_CONFIG_CONTENT_TYPE,
)
from image.oci.config import OCIConfig, MalformedConfig, LayerHistory
from util.bytes import Bytes

Expand Down Expand Up @@ -114,3 +120,31 @@ def test_config_missing_required():
def test_invalid_config():
with pytest.raises(MalformedConfig):
OCIConfig(Bytes.for_string_or_unicode("{}"))


def test_artifact_registratioon():
# Register helm
register_artifact_type("application/vnd.cncf.helm.config.v1+json", ["application/tar+gzip"])
assert "application/vnd.cncf.helm.config.v1+json" in ALLOWED_ARTIFACT_TYPES
assert "application/tar+gzip" in ADDITIONAL_LAYER_CONTENT_TYPES

# Register a new layer type to an existing config type
register_artifact_type(
OCI_IMAGE_CONFIG_CONTENT_TYPE, ["application/vnd.oci.image.layer.v1.tar+zstd"]
)
assert (
OCI_IMAGE_CONFIG_CONTENT_TYPE in ALLOWED_ARTIFACT_TYPES
and ALLOWED_ARTIFACT_TYPES.count(OCI_IMAGE_CONFIG_CONTENT_TYPE) == 1
)
assert "application/vnd.oci.image.layer.v1.tar+zstd" in ADDITIONAL_LAYER_CONTENT_TYPES

# Attempt to register existing helm type
register_artifact_type("application/vnd.cncf.helm.config.v1+json", ["application/tar+gzip"])
assert (
"application/vnd.cncf.helm.config.v1+json" in ALLOWED_ARTIFACT_TYPES
and ALLOWED_ARTIFACT_TYPES.count("application/vnd.cncf.helm.config.v1+json") == 1
)
assert (
"application/tar+gzip" in ADDITIONAL_LAYER_CONTENT_TYPES
and ADDITIONAL_LAYER_CONTENT_TYPES.count("application/tar+gzip") == 1
)
Binary file added static/img/helm-chart-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/oci-icon-color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions util/config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,5 +1179,16 @@
"description": "If set to true, the first User account may be created via API /api/v1/user/initialize",
"x-example": False,
},
# OCI artifact types
"ALLOWED_OCI_ARTIFACT_TYPES": {
"type": "object",
"description": "The set of allowed OCI artifact mimetypes and the assiciated layer types",
"x-example": {
"application/vnd.cncf.helm.config.v1+json": ["application/tar+gzip"],
"application/vnd.sylabs.sif.config.v1+json": [
"application/vnd.sylabs.sif.layer.v1.sif"
],
},
},
},
}

0 comments on commit 64bc11f

Please sign in to comment.