Skip to content

.github/workflows/build-postgres.yaml #11

.github/workflows/build-postgres.yaml

.github/workflows/build-postgres.yaml #11

# https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images
on:
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/postgres
POSTGRES_MAJOR: 17
POSTGRES_MINOR: 5
jobs:
build:
strategy:
fail-fast: false
matrix:
os:
- runner: ubuntu-24.04
platform: linux/amd64
arch: amd64
- runner: ubuntu-24.04-arm
platform: linux/arm64
arch: arm64
runs-on: ${{ matrix.os.runner }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=raw,value=${{ env.POSTGRES_MAJOR }}.${{ env.POSTGRES_MINOR }}-{{commit_date 'YYYYMMDD'}}-{{sha}}-${{ matrix.os.arch }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/postgres/Dockerfile
build-args: |
postgresql_major=${{ env.POSTGRES_MAJOR }}
postgresql_minor=${{ env.POSTGRES_MINOR }}
push: true
platforms: ${{ matrix.os.platform }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ matrix.os.platform }}
cache-to: type=gha,mode=max,scope=${{ matrix.os.platform }}
provenance: false
sbom: false
merge-manifests:
runs-on: ubuntu-24.04
needs: build
permissions:
packages: write
contents: read # Needed to get repository owner and name
steps:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=raw,value=${{ env.POSTGRES_MAJOR }}.${{ env.POSTGRES_MINOR }}-{{commit_date 'YYYYMMDD'}}-{{sha}}
- name: Create and push manifest
run: |
docker manifest create $DOCKER_METADATA_OUTPUT_TAGS \
--amend $DOCKER_METADATA_OUTPUT_TAGS-amd64 \
--amend $DOCKER_METADATA_OUTPUT_TAGS-arm64
docker manifest push $DOCKER_METADATA_OUTPUT_TAGS