Build and push Docker images for testing #76
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: Build and push Docker images for testing | |
on: | |
workflow_dispatch: | |
inputs: | |
owner: | |
description: The owner of the VMaNGOS code repository to use | |
default: vmangos | |
required: true | |
type: string | |
repository: | |
description: The VMaNGOS code repository to use | |
default: core | |
required: true | |
type: string | |
revision: | |
description: The VMaNGOS code repository revision to use | |
default: development | |
required: true | |
type: string | |
client-version: | |
description: The client version for which to build VMaNGOS | |
default: 5875 | |
required: true | |
type: number | |
db-owner: | |
description: The owner of the VMaNGOS database repository to use | |
default: brotalnia | |
required: true | |
type: string | |
db-repository: | |
description: The VMaNGOS database repository to use | |
default: database | |
required: true | |
type: string | |
db-dump: | |
description: The VMaNGOS database dump to use | |
default: world_full_14_june_2021 | |
required: true | |
type: string | |
custom-name: | |
description: (Optional) A custom name to use as part of the image tags (when provided, this overrides the default `{ owner }-{ repository }-{ revision }` naming scheme) | |
required: false | |
type: string | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME_SERVER: ${{ github.repository_owner }}/vmangos-server-testing | |
IMAGE_NAME_DATABASE: ${{ github.repository_owner }}/vmangos-database-testing | |
jobs: | |
setup: | |
name: Setup | |
runs-on: ubuntu-24.04 | |
outputs: | |
commit-hash: ${{ steps.latest-commit-hash.outputs.result }} | |
already-built: ${{ steps.already-built.outputs.result }} | |
steps: | |
# If the original MariaDB entrypoint script changes, we can't guarantee | |
# that our custom version (which relies on functions defined in the | |
# original) will still work, so we fail the workflow run at this point. | |
- name: Check if MariaDB entrypoint script has been updated | |
id: mariadb-entrypoint-check | |
run: | | |
known_entrypoint=https://raw.githubusercontent.com/MariaDB/mariadb-docker/29f8caccc4790118489524b3f1ee1aa73a2bd760/11.4/docker-entrypoint.sh | |
latest_entrypoint=https://raw.githubusercontent.com/MariaDB/mariadb-docker/master/11.4/docker-entrypoint.sh | |
curl -o known-entrypoint.sh $known_entrypoint | |
curl -o latest-entrypoint.sh $latest_entrypoint | |
diff known-entrypoint.sh latest-entrypoint.sh | |
build-and-push-server-images: | |
name: Build and push server images | |
needs: setup | |
runs-on: ubuntu-24.04 | |
strategy: | |
fail-fast: true | |
matrix: | |
use-anticheat: [0, 1] | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Generate tags | |
uses: actions/github-script@v7 | |
id: generate-tags | |
env: | |
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_SERVER }} | |
OWNER: ${{ github.event.inputs.owner }} | |
REPOSITORY: ${{ github.event.inputs.repository }} | |
REVISION: ${{ github.event.inputs.revision }} | |
CLIENT_VERSION: ${{ github.event.inputs.client-version }} | |
USE_ANTICHEAT: ${{ matrix.use-anticheat }} | |
CUSTOM_NAME: ${{ github.event.inputs.custom-name }} | |
with: | |
result-encoding: string | |
script: | | |
const tags = [] | |
const useAnticheat = parseInt(process.env.USE_ANTICHEAT) === 1 | |
const potentialAnticheatSuffix = useAnticheat | |
? '-anticheat' | |
: '' | |
if (process.env.CUSTOM_NAME.trim() !== '') { | |
tags.push(`${process.env.IMAGE}:${process.env.CUSTOM_NAME}-${process.env.CLIENT_VERSION}${potentialAnticheatSuffix}`) | |
return tags.join(',') | |
} | |
tags.push(`${process.env.IMAGE}:${process.env.OWNER}-${process.env.REPOSITORY}-${process.env.REVISION}-${process.env.CLIENT_VERSION}${potentialAnticheatSuffix}`) | |
return tags.join(',') | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push images | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/amd64, linux/arm64 | |
file: ./docker/server/Dockerfile | |
push: true | |
provenance: false | |
build-args: | | |
VMANGOS_OWNER=${{ github.event.inputs.owner }} | |
VMANGOS_REPOSITORY=${{ github.event.inputs.repository }} | |
VMANGOS_REVISION=${{ github.event.inputs.revision }} | |
VMANGOS_CLIENT_VERSION=${{ github.event.inputs.client-version }} | |
VMANGOS_USE_ANTICHEAT=${{ matrix.use-anticheat }} | |
tags: ${{ steps.generate-tags.outputs.result }} | |
# Since the database image builds only take a few minutes (and therefore | |
# always complete before the server image builds), we need to build after the | |
# server images; otherwise, we would push new database images without knowing | |
# if the server image builds will succeed (and if there is, e.g., a | |
# compilation error due to a bug upstream we would end up with a version | |
# mismatch between the latest database images and the latest server images). | |
build-and-push-database-images: | |
name: Build and push database images | |
needs: [setup, build-and-push-server-images] | |
runs-on: ubuntu-24.04 | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Generate tags | |
uses: actions/github-script@v7 | |
id: generate-tags | |
env: | |
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_DATABASE }} | |
OWNER: ${{ github.event.inputs.owner }} | |
REPOSITORY: ${{ github.event.inputs.repository }} | |
REVISION: ${{ github.event.inputs.revision }} | |
CUSTOM_NAME: ${{ github.event.inputs.custom-name }} | |
with: | |
result-encoding: string | |
script: | | |
const tags = [] | |
if (process.env.CUSTOM_NAME.trim() !== '') { | |
tags.push(`${process.env.IMAGE}:${process.env.CUSTOM_NAME}`) | |
return tags.join(',') | |
} | |
tags.push(`${process.env.IMAGE}:${process.env.OWNER}-${process.env.REPOSITORY}-${process.env.REVISION}`) | |
return tags.join(',') | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push images | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/amd64, linux/arm64 | |
file: ./docker/database/Dockerfile | |
push: true | |
provenance: false | |
build-args: | | |
VMANGOS_OWNER=${{ github.event.inputs.owner }} | |
VMANGOS_REPOSITORY=${{ github.event.inputs.repository }} | |
VMANGOS_REVISION=${{ github.event.inputs.revision }} | |
VMANGOS_DB_OWNER=${{ github.event.inputs.db-owner }} | |
VMANGOS_DB_REPOSITORY=${{ github.event.inputs.db-repository }} | |
VMANGOS_DB_DUMP=${{ github.event.inputs.db-dump }} | |
tags: ${{ steps.generate-tags.outputs.result }} |