Skip to content

Build and Push Docker Image for PMM QA Framework #3

Build and Push Docker Image for PMM QA Framework

Build and Push Docker Image for PMM QA Framework #3

name: Build and Push Docker Image for PMM QA Framework
on:
workflow_dispatch:
inputs:
image:
description: 'Which image to build'
required: true
type: choice
options:
- percona-server-mysql
- mysql-community
- percona-distribution-postgresql
- postgresql-community
- percona-server-mongodb
- mongodb
- valkey
db_version:
description: 'Database version to build/tag (e.g. 8.0, 8.4, 5.7). Applies to any image.'
required: false
default: ''
env:
REGISTRY: ghcr.io
IMAGE_NAME: percona/pmm-qa
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve image config
id: cfg
run: |
BASE="qa_framework/docker_images"
# inputs are absent on push / pull_request events -> default the image
IMAGE="${{ github.event.inputs.image }}"
IMAGE="${IMAGE:-percona-server-mysql}"
case "$IMAGE" in
percona-server-mysql)
NAME="percona-server-mysql"
DIR="$BASE/percona_server_for_mysql"
;;
mysql-community)
NAME="mysql-community"
DIR="$BASE/mysql-community"
;;
percona-distribution-postgresql)
NAME="percona-distribution-postgresql"
DIR="$BASE/percona-distribution-postgresql"
;;
postgresql-community)
NAME="postgresql-community"
DIR="$BASE/postgresql-community"
;;
percona-server-mongodb)
NAME="percona-server-mongodb"
DIR="$BASE/percona-server-mongodb"
;;
mongodb)
NAME="mongodb"
DIR="$BASE/mongodb"
;;
valkey)
NAME="valkey"
DIR="$BASE/valkey"
;;
*)
echo "Unknown image: $IMAGE"
exit 1
;;
esac
FILE="$DIR/Dockerfile"
CONTEXT="$DIR"
echo "name=$NAME" >> "$GITHUB_OUTPUT"
echo "file=$FILE" >> "$GITHUB_OUTPUT"
echo "context=$CONTEXT" >> "$GITHUB_OUTPUT"
# Version handling: db_version is free-text and usable by any image.
# Every image receives DB_VERSION as a build arg (Dockerfiles may ignore it);
# percona-server-mysql additionally derives its repo/base/package args.
DBV="${{ github.event.inputs.db_version }}"
FLAVOR="$DBV"
{
echo "build_args<<EOF"
[ -n "$DBV" ] && echo "DB_VERSION=${DBV}"
if [ "$NAME" = "percona-server-mysql" ]; then
PSV="${DBV:-8.0}"
case "$PSV" in
8.4) echo "BASE_IMAGE=antmelekhin/docker-systemd:ubuntu-24.04"; echo "PS_REPO=ps-84-lts"; echo "PS_PKG_SUFFIX=" ;;
5.7) echo "BASE_IMAGE=antmelekhin/docker-systemd:ubuntu-22.04"; echo "PS_REPO=ps-57"; echo "PS_PKG_SUFFIX=-5.7" ;;
*) echo "BASE_IMAGE=antmelekhin/docker-systemd:ubuntu-24.04"; echo "PS_REPO=ps-80"; echo "PS_PKG_SUFFIX=" ;;
esac
FLAVOR="$PSV"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
echo "flavor=$FLAVOR" >> "$GITHUB_OUTPUT"
echo "Resolved: image=$NAME file=$FILE context=$CONTEXT flavor=${FLAVOR:-none}"
- name: Assemble tags
id: tags
run: |
IMG="${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ steps.cfg.outputs.name }}"
FLAVOR="${{ steps.cfg.outputs.flavor }}"
# Two tags only: latest, plus the db_version (flavor) when set.
{
echo "tags<<EOF"
echo "${IMG}:latest"
[ -n "$FLAVOR" ] && echo "${IMG}:${FLAVOR}"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Set up Docker Build
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
# Pull requests only validate the build; no push, so no login needed.
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build (and push on non-PR events)
uses: docker/build-push-action@v6
with:
context: ${{ steps.cfg.outputs.context }}
file: ${{ steps.cfg.outputs.file }}
push: ${{ github.event_name != 'pull_request' }}
build-args: ${{ steps.cfg.outputs.build_args }}
tags: ${{ steps.tags.outputs.tags }}