Skip to content

Docker Multi-Platform Build #36

Docker Multi-Platform Build

Docker Multi-Platform Build #36

name: Docker Multi-Platform Build
on:
workflow_dispatch:
inputs:
version:
description: 'Version tag to publish alongside latest/beta/alpha (e.g. 0.1.0)'
required: false
workflow_call:
inputs:
version:
description: 'Version tag to publish alongside latest/beta/alpha (e.g. 0.1.0)'
type: string
required: false
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
#- name: Log in to Docker Hub
#uses: docker/login-action@v4
#with:
#username: ${{ secrets.DOCKERHUB_USERNAME }}
#password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Quay.io
uses: docker/login-action@v4
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Compute image tags
id: tags
env:
VERSION: ${{ inputs.version }}
run: |
if [ -n "$VERSION" ] && ! echo "$VERSION" | grep -qE '^[a-zA-Z0-9._-]+$'; then
echo "::error::Invalid version input '$VERSION' (allowed: [a-zA-Z0-9._-])"
exit 1
fi
TAGS="ghcr.io/openrtmp/librtmp2-server-panel:latest
ghcr.io/openrtmp/librtmp2-server-panel:beta
ghcr.io/openrtmp/librtmp2-server-panel:alpha
quay.io/openrtmp/librtmp2-server-panel:latest
quay.io/openrtmp/librtmp2-server-panel:beta
quay.io/openrtmp/librtmp2-server-panel:alpha"
APP_VERSION=""
if [ -n "$VERSION" ]; then
# Only treat this as a "v"-prefixed release version (and mirror
# it under both the bare and v-prefixed tag) when it actually
# has a semver-like "vX.Y" shape, e.g. v0.1.1 -> 0.1.1 + v0.1.1.
# Requiring the dot (not just a leading digit) avoids
# mis-stripping arbitrary tags like "version1", "vprod", or
# "v1prod" that merely start with "v<digit>".
if echo "$VERSION" | grep -qE '^v[0-9]+\.[0-9]'; then
BARE_VERSION="${VERSION#v}"
else
BARE_VERSION="$VERSION"
fi
if ! echo "$BARE_VERSION" | grep -qE '^[A-Za-z0-9_][A-Za-z0-9_.-]{0,126}$'; then
echo "::error::Invalid version input '$VERSION' (normalized '$BARE_VERSION' must be a valid Docker tag: start with an alphanumeric or '_', then up to 126 more [A-Za-z0-9_.-] chars)"
exit 1
fi
APP_VERSION="$BARE_VERSION"
TAGS="$TAGS
ghcr.io/openrtmp/librtmp2-server-panel:$BARE_VERSION
quay.io/openrtmp/librtmp2-server-panel:$BARE_VERSION"
# Publish the v-prefixed alias too whenever this looks like a
# semver-shaped release version (0.1.1 or v0.1.1 alike), so a
# single dispatch always produces both tags regardless of which
# form was typed. Tags that don't match this shape (e.g.
# "version1", "vprod", "1prod") only get their own literal tag,
# not an invented alias.
if echo "$BARE_VERSION" | grep -qE '^[0-9]+\.[0-9]'; then
TAGS="$TAGS
ghcr.io/openrtmp/librtmp2-server-panel:v$BARE_VERSION
quay.io/openrtmp/librtmp2-server-panel:v$BARE_VERSION"
fi
fi
{
echo "tags<<EOF"
echo "$TAGS"
echo "EOF"
echo "app_version=$APP_VERSION"
} >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64/v8,linux/riscv64
push: true
tags: ${{ steps.tags.outputs.tags }}
build-args: |
APP_VERSION=${{ steps.tags.outputs.app_version }}