Skip to content

Commit 3bca9b0

Browse files
authored
Set OCI annotations in the manifest so they show up on the webpage for the images (#61)
1 parent 2f56ac4 commit 3bca9b0

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

.github/workflows/build-and-push.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- name: Set Calver Date
2222
run: |
2323
echo "builddate=$(date +'%Y.%m.%d')" >> $GITHUB_OUTPUT
24+
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
2425
id: version
2526
- name: Checkout
2627
uses: actions/checkout@v5
@@ -34,6 +35,69 @@ jobs:
3435
registry: ghcr.io
3536
username: ${{ github.actor }}
3637
password: ${{ secrets.GITHUB_TOKEN }}
38+
# Extract labels from the Dockerfile to use as OCI annotations.
39+
# This allows them to show up on the webpages for the containers on GHCR due to using
40+
# multi-arch images
41+
# (as documented at
42+
# https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#adding-a-description-to-multi-arch-images
43+
# ).
44+
# The pre-defined annotations by the OCI that you can add to a manifest can be found at
45+
# https://specs.opencontainers.org/image-spec/annotations/#pre-defined-annotation-keys
46+
- name: Extract labels from Dockerfile
47+
id: labels
48+
run: |
49+
set -euo pipefail
50+
51+
# Extract labels from the Dockerfile.
52+
DOCKERFILE=./${{ inputs.container }}/Dockerfile
53+
54+
# Function to extract a label value.
55+
extract_label() {
56+
local label_key="$1"
57+
grep "org.opencontainers.image.${label_key}=" "$DOCKERFILE" | \
58+
sed -n 's/.*org\.opencontainers\.image\.'"${label_key}"'="\([^"]*\)".*/\1/p' | \
59+
head -n1 || echo ''
60+
}
61+
62+
# Function to add annotation if value is non-empty.
63+
add_annotation() {
64+
local key="$1"
65+
local value="$2"
66+
if [ -n "$value" ]; then
67+
[ -n "$annotations" ] && annotations="$annotations,"
68+
annotations="${annotations}annotation-index.org.opencontainers.image.${key}=${value}"
69+
fi
70+
}
71+
72+
# Extract static labels from Dockerfile.
73+
source=$(extract_label "source")
74+
description=$(extract_label "description")
75+
title=$(extract_label "title")
76+
authors=$(extract_label "authors")
77+
base_name=$(extract_label "base.name")
78+
licenses=$(extract_label "licenses")
79+
url=$(extract_label "url")
80+
documentation=$(extract_label "documentation")
81+
82+
# Get dynamic values from earlier steps.
83+
created="${{ steps.version.outputs.created }}"
84+
revision="${{ github.sha }}"
85+
86+
# Build annotations string.
87+
annotations=""
88+
add_annotation "source" "$source"
89+
add_annotation "description" "$description"
90+
add_annotation "title" "$title"
91+
add_annotation "authors" "$authors"
92+
add_annotation "base.name" "$base_name"
93+
add_annotation "licenses" "$licenses"
94+
add_annotation "url" "$url"
95+
add_annotation "documentation" "$documentation"
96+
add_annotation "created" "$created"
97+
add_annotation "revision" "$revision"
98+
99+
# Output the complete annotations string.
100+
echo "annotations=$annotations" >> $GITHUB_OUTPUT
37101
- name: Build and push
38102
uses: docker/build-push-action@v6
39103
with:
@@ -43,3 +107,4 @@ jobs:
43107
tags: |
44108
ghcr.io/python/${{ inputs.container }}:${{ steps.version.outputs.builddate }}.${{ github.run_id }}
45109
ghcr.io/python/${{ inputs.container }}:latest
110+
outputs: type=image,name=ghcr.io/python/${{ inputs.container }},${{ steps.labels.outputs.annotations }}

autoconf/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ ARG AUTOMAKE_VERSION="1.16.5"
88
ARG CONFIG_GIT_REV="00b15927496058d23e6258a28d8996f87cf1f191"
99

1010
LABEL org.opencontainers.image.source="https://github.com/python/cpython-devcontainers"
11-
LABEL org.opencontainers.image.base.name="docker.io/library/ubuntu:22.04"
11+
LABEL org.opencontainers.image.base.name="docker.io/library/ubuntu:24.04"
1212
LABEL org.opencontainers.image.authors="Donghee Na"
1313
LABEL org.opencontainers.image.title="GNU Autoconf ${AUTOCONF_VERSION} container for CPython"
1414
LABEL org.opencontainers.image.description="Container image with GNU Autoconf ${AUTOCONF_VERSION}, GNU Automake ${AUTOMAKE_VERSION}, and autoconf-archive ${AUTOCONF_ARCHIVE_VERSION} for generating CPython's configure script."
15+
LABEL org.opencontainers.image.licenses="MIT"
16+
LABEL org.opencontainers.image.url="https://github.com/python/cpython-devcontainers"
17+
LABEL org.opencontainers.image.documentation="https://github.com/python/cpython-devcontainers/blob/main/autoconf/README.md"
1518

1619
RUN apt-get update && \
1720
apt-get install -yq \

autoconf/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Container image for recreating `configure` from `configure.ac` for CPython (via the `make regen-configure` command).

devcontainer/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ LABEL org.opencontainers.image.source="https://github.com/python/cpython-devcont
55
LABEL org.opencontainers.image.title="CPython development container"
66
LABEL org.opencontainers.image.description="CPython development container with the tooling to work on Linux builds."
77
LABEL org.opencontainers.image.authors="Brett Cannon"
8+
LABEL org.opencontainers.image.licenses="MIT"
9+
LABEL org.opencontainers.image.url="https://github.com/python/cpython-devcontainers"
10+
LABEL org.opencontainers.image.documentation="https://github.com/python/cpython-devcontainers/blob/main/devcontainer/README.md"
811

912
ENV CC=clang
1013

wasicontainer/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
FROM ghcr.io/python/devcontainer:latest
22

3-
LABEL org.opencontainers.image.base.name="ghcr.io/python/wasicontainer:latest"
3+
LABEL org.opencontainers.image.base.name="ghcr.io/python/devcontainer:latest"
44
LABEL org.opencontainers.image.source="https://github.com/python/cpython-devcontainers"
55
LABEL org.opencontainers.image.title="CPython WASI development container"
66
LABEL org.opencontainers.image.description="CPython development container with the tooling to work on WASI builds."
77
LABEL org.opencontainers.image.authors="Brett Cannon"
8+
LABEL org.opencontainers.image.licenses="MIT"
9+
LABEL org.opencontainers.image.url="https://github.com/python/cpython-devcontainers"
10+
LABEL org.opencontainers.image.documentation="https://github.com/python/cpython-devcontainers/blob/main/wasicontainer/README.md"
811

912
ARG TARGETARCH
1013

0 commit comments

Comments
 (0)