LANCommander.Servers.Counte.../.github/workflows/build-docker.yml
2026-01-19 20:40:03 -06:00

121 lines
3.9 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Build & Push SteamCMD Server (Docker Hub)
on:
workflow_dispatch:
inputs:
image_name:
description: "Docker Hub image name (e.g., lancommander/counterstrikesource)"
required: true
default: "lancommander/counterstrikesource"
version:
description: "Version tag for the image"
required: true
default: "latest"
push_latest:
description: "Also push the :latest tag"
required: true
type: boolean
default: true
platforms:
description: "Build platforms (comma-separated)"
required: true
default: "linux/amd64"
push:
tags:
- "v*"
permissions:
contents: read
concurrency:
group: dockerhub-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# Derive settings from either tag push or workflow_dispatch inputs
- name: Resolve build variables
id: vars
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then
# Tag push, e.g. refs/tags/v3339
TAG_NAME="${GITHUB_REF_NAME}"
VERSION="${TAG_NAME#v}"
# Default image name for tag builds:
# Set this to your preferred repo, or replace with a repo secret if you prefer.
IMAGE_NAME="${{ vars.DOCKERHUB_IMAGE_NAME }}"
if [[ -z "${IMAGE_NAME}" ]]; then
echo "DOCKERHUB_IMAGE_NAME variable is not set. Create it (e.g., 'lancommander/counterstrikesource') or use workflow_dispatch."
exit 1
fi
PUSH_LATEST="true"
PLATFORMS="linux/amd64"
else
IMAGE_NAME="${{ inputs.image_name }}"
VERSION="${{ inputs.version }}"
PUSH_LATEST="${{ inputs.push_latest }}"
PLATFORMS="${{ inputs.platforms }}"
fi
echo "image_name=${IMAGE_NAME}" >> "$GITHUB_OUTPUT"
echo "push_latest=${PUSH_LATEST}" >> "$GITHUB_OUTPUT"
echo "platforms=${PLATFORMS}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Set up QEMU (multi-arch)
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Generates tags/labels. Well produce:
# - :<version>
# - :latest (optional)
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.vars.outputs.image_name }}
tags: |
type=raw,value=${{ steps.vars.outputs.version }}
type=raw,value=latest,enable=${{ steps.vars.outputs.push_latest == 'true' }}
labels: |
org.opencontainers.image.title=Counter-Strike: Source Game Server
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: ${{ steps.vars.outputs.platforms }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Optional: provide a short summary in the GitHub Actions UI
- name: Summary
run: |
echo "Pushed image: ${{ steps.vars.outputs.image_name }}" >> $GITHUB_STEP_SUMMARY
echo "Tags: ${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo "Version: ${{ steps.vars.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "Platforms: ${{ steps.vars.outputs.platforms }}" >> $GITHUB_STEP_SUMMARY