Add test to the pipeline before pushing the image #469
Workflow file for this run
This file contains 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: Docker | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
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 | |
# This is used to complete the identity challenge | |
# with sigstore/fulcio when running outside of PRs. | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Install the cosign tool except on PR | |
# https://github.com/sigstore/cosign-installer | |
- name: Install cosign | |
if: github.event_name != 'pull_request' | |
uses: sigstore/cosign-installer@v3.4.0 | |
# Workaround: https://github.com/docker/build-push-action/issues/461 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
# Login against a Docker registry except on PR | |
# https://github.com/docker/login-action | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- 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 (don't push on PR) | |
# https://github.com/docker/build-push-action | |
- name: Build Docker image | |
id: build-and-push | |
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: false | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
load: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Smoke Test - Start and Check Database | |
run: | | |
docker run -d --name postgres-test -e POSTGRES_PASSWORD=mysecretpassword ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ matrix.postgres_version }}-${{ matrix.major }} | |
sleep 10 | |
docker exec postgres-test pg_isready -U postgres | |
docker stop postgres-test | |
docker rm postgres-test | |
- name: Push Docker Image | |
if: ${{ success() && 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. | |
# This will only write to the public Rekor transparency log when the Docker | |
# repository is public to avoid leaking data. If you would like to publish | |
# transparency data ev en for private images, pass --force to cosign below. | |
# https://github.com/sigstore/cosign | |
- name: Sign the published Docker image | |
if: ${{ success() && github.event_name != 'pull_request' }} | |
env: | |
COSIGN_EXPERIMENTAL: "true" | |
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign -y {}@${{ steps.build.outputs.digest }} |