Skip to content

Docker

Docker #507

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, 17]
major: [4,5]
include:
- partman_version: v4.7.4
partman_checksum: 28e4fdb83ecc16525959ae9593bfbfd077db429285f5f7d8e2468bfff6cbdbf2c81ace79a9ddeb4f00f51eb709163dbd713fe6b221a432ac2ff766f98d4cf8e4
default: "true"
major: 4
- partman_version: v5.1.0
partman_checksum: 42f527f93c7c4da957a84d4b81dafc4b37beed8fe66d2b4d908386c8ed2256f7356a8af7bdc8b0f4281c65a6ceded8d114a0c7db715dd2cc093a6b15c5ae23f4
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-release.outputs.digest }}
TAGS=$(echo ${{ steps.meta.outputs.tags }} | tr ',' '\n')
for TAG in $TAGS; do
cosign sign -y $TAG
done