Skip to content

Commit

Permalink
Add support for build metadata in version string
Browse files Browse the repository at this point in the history
To be compatible with SemVer, we should be able to handle versions which
include optional build metadata
([see](https://semver.org/#spec-item-10)). In general, this is already
the case. However, (some) OCI registries don't allow `+` in their tags,
which is used as separator for these build metadata. That's why, the
version has to be sanitised prior to uploading to a registry or after
retrieving it from there.
  • Loading branch information
8R0WNI3 committed Jul 1, 2024
1 parent 1e5cb5b commit a62fc72
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion oci/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
oci_request_logger = logging.getLogger('oci.client.request_logger')
oci_request_logger.setLevel(logging.DEBUG)

# additional build metadata as defined in SemVer can be added via `+` to the version
# however, OCI registries don't allow `+` in tags and use a `META_SEPARATOR` instead
META_SEPARATOR = '.build-'


def _append_b64_padding_if_missing(b64_str: str):
if b64_str[-1] == '=':
Expand Down Expand Up @@ -226,6 +230,8 @@ def manifest_url(self, image_reference: typing.Union[str, om.OciImageReference])
if not (tag := image_reference.tag):
raise ValueError(f'{image_reference=} does not seem to contain a tag')

tag = tag.replace('+', META_SEPARATOR)

return urljoin(
self.artifact_base_url(image_reference=image_reference),
'manifests',
Expand Down Expand Up @@ -701,7 +707,10 @@ def tags(self, image_reference: str):
method='GET'
)

return res.json()['tags']
return [
tag.replace(META_SEPARATOR, '+')
for tag in res.json()['tags']
]

def has_multiarch(self, image_reference: str) -> bool:
res = self.head_manifest(
Expand Down

0 comments on commit a62fc72

Please sign in to comment.