|
21 | 21 | - name: Set Calver Date |
22 | 22 | run: | |
23 | 23 | echo "builddate=$(date +'%Y.%m.%d')" >> $GITHUB_OUTPUT |
| 24 | + echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT |
24 | 25 | id: version |
25 | 26 | - name: Checkout |
26 | 27 | uses: actions/checkout@v5 |
|
34 | 35 | registry: ghcr.io |
35 | 36 | username: ${{ github.actor }} |
36 | 37 | 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 |
37 | 101 | - name: Build and push |
38 | 102 | uses: docker/build-push-action@v6 |
39 | 103 | with: |
|
43 | 107 | tags: | |
44 | 108 | ghcr.io/python/${{ inputs.container }}:${{ steps.version.outputs.builddate }}.${{ github.run_id }} |
45 | 109 | ghcr.io/python/${{ inputs.container }}:latest |
| 110 | + outputs: type=image,name=ghcr.io/python/${{ inputs.container }},${{ steps.labels.outputs.annotations }} |
0 commit comments