The personal finance app for everyone (by everyone)
Ruby
build: allow main branch publishing and add comprehensive OCI metadata for multi-arch images (#65)
Himank Daveeba42e2f718f
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.ymlindex 8ec5747449..cc7427dec5 100644--- a/.github/workflows/publish.yml+++ b/.github/workflows/publish.yml@@ -1,12 +1,13 @@# Reference: https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners# Conditions for pushing the image to GHCR:+# - Triggered by push to default branch (`main`)# - Triggered by push to a version tag (`v*`)# - Triggered by a scheduled run# - Triggered manually via `workflow_dispatch` with `push: true`## Conditional expression:-# startsWith(github.ref, 'refs/tags/v') || github.event_name == 'schedule' || github.event.inputs.push+# github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'schedule' || github.event.inputs.pushname: Publish Docker image@@ -84,6 +85,7 @@ jobs:BASE_CONFIG="type=sha,format=long"if [[ $GITHUB_EVENT_NAME == "schedule" ]]; thenBASE_CONFIG+=$'\n'"type=schedule,pattern=nightly"+ BASE_CONFIG+=$'\n'"type=schedule,pattern=nightly-{{date 'ddd'}}"elif [[ "$GITHUB_REF" == refs/tags/v* ]]; thenBASE_CONFIG="type=semver,pattern={{version}}"BASE_CONFIG+=$'\n'"type=raw,value=stable"@@ -94,6 +96,10 @@ jobs:echo EOF} >> $GITHUB_ENV+ - name: Get current date (RFC 3339 format)+ id: date+ run: echo "date=$(date -Iseconds)" >> $GITHUB_OUTPUT+- name: Extract metadata for Dockerid: metauses: docker/[email protected]@@ -101,6 +107,13 @@ jobs:images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}flavor: latest=falsetags: ${{ env.TAGS_SPEC }}+ labels: |+ org.opencontainers.image.version=${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || '' }}+ org.opencontainers.image.created=${{ steps.date.outputs.date }}+ org.opencontainers.image.ref.name=${{ github.ref_name }}+ org.opencontainers.image.vendor=we-promise+ org.opencontainers.image.title=Sure+ org.opencontainers.image.description=A multi-arch Docker image for the Sure Rails app- name: Publish 'linux/${{ matrix.platform }}' image by digestuses: docker/[email protected]@@ -119,7 +132,7 @@ jobs:outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},name-canonical=true,push-by-digest=true,oci-mediatypes=true- name: Export the Docker image digest- if: ${{ startsWith(github.ref, 'refs/tags/v') || github.event_name == 'schedule' || github.event.inputs.push }}+ if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'schedule' || github.event.inputs.push }}run: |mkdir -p "${RUNNER_TEMP}"/digestsecho "${DIGEST#sha256:}" > "${RUNNER_TEMP}/digests/digest-${PLATFORM}"@@ -128,7 +141,7 @@ jobs:PLATFORM: ${{ matrix.platform }}- name: Upload the Docker image digest- if: ${{ startsWith(github.ref, 'refs/tags/v') || github.event_name == 'schedule' || github.event.inputs.push }}+ if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'schedule' || github.event.inputs.push }}uses: actions/[email protected]with:name: digest-${{ matrix.platform }}@@ -138,7 +151,7 @@ jobs:merge:name: Merge multi-arch manifest & push multi-arch tag- if: ${{ startsWith(github.ref, 'refs/tags/v') || github.event_name == 'schedule' || github.event.inputs.push }}+ if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'schedule' || github.event.inputs.push }}needs: [build]timeout-minutes: 60@@ -182,10 +195,29 @@ jobs:image_args+=("${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:$(<"${DIGESTS_DIR}/digest-${PLATFORM}")")done+ annotations=(+ "index:org.opencontainers.image.created=$(date -Iseconds)"+ 'index:org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}'+ 'index:org.opencontainers.image.revision=${{ github.sha }}'+ 'index:org.opencontainers.image.ref.name=${{ github.ref_name }}'+ 'index:org.opencontainers.image.vendor=we-promise'+ 'index:org.opencontainers.image.licenses=AGPL-3.0'+ 'index:org.opencontainers.image.title=Sure'+ 'index:org.opencontainers.image.description=A multi-arch Docker image for the Sure Rails app'+ )+ annotation_args=()+ for annotation in "${annotations[@]}"; do+ annotation_args+=("--annotation=${annotation}")+ done+ if [[ $GITHUB_REF_TYPE == "tag" ]]; then+ annotation_args+=("--annotation=index:org.opencontainers.image.version=$GITHUB_REF_NAME")+ fi+attempts=0until docker buildx imagetools create \- --annotation "index:org.opencontainers.image.description=A multi-arch Docker image for the Sure Rails app" \- "${tag_args[@]}" "${image_args[@]}" \+ "${annotation_args[@]}" \+ "${tag_args[@]}" \+ "${image_args[@]}" \; doattempts=$((attempts + 1))if [[ $attempts -ge 3 ]]; then