Skip to content

Commit

Permalink
Set oci base image reference and digest annotations
Browse files Browse the repository at this point in the history
These are available if we build against a released base container
image fetched from the registry. Tumbleweed team does not want
an external registry dependency so we need to make their generation
conditional on that.
  • Loading branch information
dirkmueller committed Sep 25, 2024
1 parent 73ab954 commit 470bbb3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/bci_build/package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ def dockerfile_from_target_ref(self) -> str:
else f"{self.base_image_registry}/{self.from_target_image}"
)

@property
def is_base_container_annotation_available(self) -> bool:
"""return True if the obs-service-kiwi_metainfo_helper can provide base.name/digest annotations."""
return bool(self._from_image and not self.os_version.is_tumbleweed)

@property
def dockerfile_from_line(self) -> str:
if self._from_image is None:
Expand Down
8 changes: 8 additions & 0 deletions src/bci_build/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
LABEL com.suse.release-stage="{{ image.release_stage }}"
{%- endif %}
# endlabelprefix
{%- if image.is_base_container_annotation_available %}
LABEL org.opencontainers.image.base.name="%BASE_REFNAME%"
LABEL org.opencontainers.image.base.digest="%BASE_DIGEST%"
{%- endif %}
LABEL io.artifacthub.package.readme-url="{{ image.readme_url }}"
{%- if image.logo_url %}
LABEL io.artifacthub.package.logo-url="{{ image.logo_url }}"
Expand Down Expand Up @@ -151,6 +155,10 @@
<label name="{% if image.os_version.is_tumbleweed %}org.opensuse{% else %}com.suse{% endif %}.lifecycle-url" value="{{ image.lifecycle_url }}"/>
{{- image.extra_label_xml_lines }}
</suse_label_helper:add_prefix>
{%- if image.is_base_container_annotation_available %}
<label name="org.opencontainers.image.base.name" value="%BASE_REFNAME%"/>
<label name="org.opencontainers.image.base.digest" value="%BASE_DIGEST%"/>
{%- endif %}
<label name="io.artifacthub.package.readme-url" value="{{ image.readme_url }}"/>{% if image.logo_url %}
<label name="io.artifacthub.package.logo-url" value="{{ image.logo_url }}"/>{% endif %}
</labels>
Expand Down
12 changes: 12 additions & 0 deletions tests/test_build_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
LABEL com.suse.lifecycle-url="https://www.suse.com/lifecycle#suse-linux-enterprise-server-15"
LABEL com.suse.release-stage="released"
# endlabelprefix
LABEL org.opencontainers.image.base.name="%BASE_REFNAME%"
LABEL org.opencontainers.image.base.digest="%BASE_DIGEST%"
LABEL io.artifacthub.package.readme-url="%SOURCEURL%/README.md"
COPY test.el .
RUN emacs -Q --batch test.el
Expand Down Expand Up @@ -94,6 +96,8 @@
<label name="com.suse.release-stage" value="released"/>
<label name="com.suse.lifecycle-url" value="https://www.suse.com/lifecycle#suse-linux-enterprise-server-15"/>
</suse_label_helper:add_prefix>
<label name="org.opencontainers.image.base.name" value="%BASE_REFNAME%"/>
<label name="org.opencontainers.image.base.digest" value="%BASE_DIGEST%"/>
<label name="io.artifacthub.package.readme-url" value="%SOURCEURL%/README.md"/>
</labels>
</containerconfig>
Expand Down Expand Up @@ -160,6 +164,8 @@
LABEL com.suse.lifecycle-url="https://www.suse.com/lifecycle#suse-linux-enterprise-server-15"
LABEL com.suse.release-stage="released"
# endlabelprefix
LABEL org.opencontainers.image.base.name="%BASE_REFNAME%"
LABEL org.opencontainers.image.base.digest="%BASE_DIGEST%"
LABEL io.artifacthub.package.readme-url="%SOURCEURL%/README.md"
""",
"""<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -200,6 +206,8 @@
<label name="com.suse.release-stage" value="released"/>
<label name="com.suse.lifecycle-url" value="https://www.suse.com/lifecycle#suse-linux-enterprise-server-15"/>
</suse_label_helper:add_prefix>
<label name="org.opencontainers.image.base.name" value="%BASE_REFNAME%"/>
<label name="org.opencontainers.image.base.digest" value="%BASE_DIGEST%"/>
<label name="io.artifacthub.package.readme-url" value="%SOURCEURL%/README.md"/>
</labels>
</containerconfig>
Expand Down Expand Up @@ -261,6 +269,8 @@
LABEL com.suse.lifecycle-url="https://www.suse.com/lifecycle#suse-linux-enterprise-server-15"
LABEL com.suse.release-stage="released"
# endlabelprefix
LABEL org.opencontainers.image.base.name="%BASE_REFNAME%"
LABEL org.opencontainers.image.base.digest="%BASE_DIGEST%"
LABEL io.artifacthub.package.readme-url="%SOURCEURL%/README.md"
USER emacs""",
"""<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -302,6 +312,8 @@
<label name="com.suse.release-stage" value="released"/>
<label name="com.suse.lifecycle-url" value="https://www.suse.com/lifecycle#suse-linux-enterprise-server-15"/>
</suse_label_helper:add_prefix>
<label name="org.opencontainers.image.base.name" value="%BASE_REFNAME%"/>
<label name="org.opencontainers.image.base.digest" value="%BASE_DIGEST%"/>
<label name="io.artifacthub.package.readme-url" value="%SOURCEURL%/README.md"/>
</labels>
</containerconfig>
Expand Down

0 comments on commit 470bbb3

Please sign in to comment.