Skip to content

Docker

Docker #485

name: Docker
on:
schedule:
- cron: '18 2 * * *'
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: dbsystel/postgresql-partman
jobs:
build:
strategy:
matrix:
postgres_version: [13, 14, 15, 16]
major: [4,5]
include:
- partman_version: v4.7.4
partman_checksum: 28e4fdb83ecc16525959ae9593bfbfd077db429285f5f7d8e2468bfff6cbdbf2c81ace79a9ddeb4f00f51eb709163dbd713fe6b221a432ac2ff766f98d4cf8e4
default: "true"
major: 4
- partman_version: v5.0.0
partman_checksum: 7a1b41732eb063a94cee7a589a252055e3a33ccf0ddfe5cddba22978ffd306cf263312b172355c930d355aea0f5f5530fd2344520791df9cb05a38614c521f9f
default: "false"
major: 5
exclude:
- major: 5
postgres_version: 13 # partman 5.x does not support postgres 13
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Install the cosign tool except on PR
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/[email protected]
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
# Login against a Docker registry except on PR
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ matrix.postgres_version == '15' && matrix.default == 'true' }}
type=raw,value=${{ matrix.postgres_version }},enable=${{ matrix.default == 'true'}}
${{ matrix.postgres_version }}-${{ matrix.major }}
# Build and push Docker image with Buildx, using only the digest
- name: Build and push Docker image with digest
id: build-and-push-digest
uses: docker/build-push-action@v5
with:
context: .
build-args: |
POSTGRESQL_VERSION=${{ matrix.postgres_version }}
PARTMAN_VERSION=${{ matrix.partman_version }}
PARTMAN_CHECKSUM=${{ matrix.partman_checksum }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pipeline
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Test the built Docker image using the digest
- name: Test Docker image
env:
POSTGRES_PASSWORD: examplepassword
run: |
DIGEST=${{ steps.build-and-push-digest.outputs.digest }}
docker run -d --name test-db -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@$DIGEST
sleep 30
docker exec test-db pg_isready -U postgres
docker stop test-db
docker rm test-db
# Build and push Docker image with Buildx,this time using the final tags
- name: Build and push Docker image with final tags (release)
id: build-and-push-release
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v5
with:
context: .
build-args: |
POSTGRESQL_VERSION=${{ matrix.postgres_version }}
PARTMAN_VERSION=${{ matrix.partman_version }}
PARTMAN_CHECKSUM=${{ matrix.partman_checksum }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Sign the resulting Docker image digest except on PRs
- name: Sign the published Docker image
if: github.event_name != 'pull_request'
env:
COSIGN_EXPERIMENTAL: "true"
run: |
DIGEST=${{ steps.build-and-push.outputs.digest }}
TAGS=$(echo ${{ steps.meta.outputs.tags }} | tr ',' '\n')
for TAG in $TAGS; do
cosign sign -y ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$TAG
done