Publish #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish | |
| on: | |
| push: | |
| tags: ["v*.*.*"] | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository_owner }}/${{ github.event.repository.name }} | |
| jobs: | |
| load-versions: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| build-matrix: ${{ steps.set-matrix.outputs.build_matrix }} | |
| merge-matrix: ${{ steps.set-matrix.outputs.merge_matrix }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - id: set-matrix | |
| run: | | |
| RUNNERS='[{"runner":"ubuntu-latest","platform":"linux/amd64"},{"runner":"ubuntu-24.04-arm","platform":"linux/arm64"}]' | |
| BUILD_MATRIX=$(jq -c --argjson runners "$RUNNERS" '{include: [.[] | . as $v | $runners[] | . + $v]}' versions.json) | |
| echo "build_matrix=$BUILD_MATRIX" >> "$GITHUB_OUTPUT" | |
| echo "merge_matrix=$(jq -c '{include: .}' versions.json)" >> "$GITHUB_OUTPUT" | |
| build: | |
| needs: load-versions | |
| runs-on: ${{ matrix.runner }} | |
| timeout-minutes: 30 | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJSON(needs.load-versions.outputs.build-matrix) }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| - name: Build and push by digest | |
| id: build | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| platforms: ${{ matrix.platform }} | |
| provenance: false | |
| sbom: false | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| PG_VERSION=${{ matrix.pg_version }} | |
| POSTGIS_VERSION=${{ matrix.postgis_version }} | |
| PGVECTOR_VERSION=${{ matrix.pgvector_version }} | |
| cache-from: type=gha,scope=${{ matrix.pg_version }}-${{ matrix.runner }} | |
| outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true | |
| - name: Export digest | |
| env: | |
| DIGEST: ${{ steps.build.outputs.digest }} | |
| run: | | |
| mkdir -p /tmp/digests | |
| touch "/tmp/digests/${DIGEST#sha256:}" | |
| - name: Upload digest | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digest-${{ matrix.pg_version }}-${{ matrix.runner }} | |
| path: /tmp/digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| merge: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| needs: [load-versions, build] | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJSON(needs.load-versions.outputs.merge-matrix) }} | |
| steps: | |
| - name: Download digests | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: digest-${{ matrix.pg_version }}-* | |
| merge-multiple: true | |
| path: /tmp/digests | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=postgres-${{ matrix.pg_version }}-postgis-${{ matrix.postgis_version }}-pgvector-${{ matrix.pgvector_version }} | |
| type=raw,value=latest,enable=${{ matrix.latest }} | |
| type=ref,event=tag,enable=${{ matrix.latest }} | |
| - name: Create multi-arch manifest and push | |
| working-directory: /tmp/digests | |
| env: | |
| REGISTRY: ${{ env.REGISTRY }} | |
| IMAGE: ${{ env.IMAGE_NAME }} | |
| run: | | |
| docker buildx imagetools create \ | |
| $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
| $(printf "${REGISTRY}/${IMAGE}@sha256:%s " *) | |
| - name: Verify multi-arch manifest | |
| run: | | |
| docker buildx imagetools inspect $(jq -cr '.tags[0]' <<< "$DOCKER_METADATA_OUTPUT_JSON") |