Files
twitchrise-bot/.github/workflows/build.yml
2025-08-11 14:39:38 +05:30

131 lines
4.4 KiB
YAML

name: Multi-Arch Docker Build & Push (debuggable)
on:
workflow_dispatch:
inputs:
image_name:
description: "Base image name (e.g. myuser/myimage or repo/image)"
required: true
tags:
description: "Image tags (comma or space separated). Example: v1.01 latest beta"
required: true
dockerhub_user:
description: "Docker Hub username (if pushing there)"
required: false
registries_to_push:
type: choice
description: "Select registries to push to"
options:
- dockerhub
- ghcr
- quay
required: false
default: []
multiple: true # allows checkbox-like UI
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Parse tags and compute full image names
id: tagger
env:
TAGS_INPUT: ${{ github.event.inputs.tags }}
IMAGE_NAME: ${{ github.event.inputs.image_name }}
DOCKERHUB_USER: ${{ github.event.inputs.dockerhub_user }}
REGISTRIES: ${{ github.event.inputs.registries_to_push }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
run: |
set -eu
TAGS_INPUT=$(echo "${TAGS_INPUT:-}" | tr ',' ' ')
TAG_ARGS=""
PRINT_LIST=""
for TAG in $TAGS_INPUT; do
if [[ "${REGISTRIES}" == *"dockerhub"* ]]; then
if [ -n "${DOCKERHUB_USER}" ]; then
FULL_TAG="docker.io/${DOCKERHUB_USER}/${IMAGE_NAME}:$TAG"
else
FULL_TAG="docker.io/${IMAGE_NAME}:$TAG"
fi
TAG_ARGS="${TAG_ARGS} --tag ${FULL_TAG}"
PRINT_LIST="${PRINT_LIST}${FULL_TAG} "
fi
if [[ "${REGISTRIES}" == *"ghcr"* ]]; then
FULL_TAG="ghcr.io/${GITHUB_REPOSITORY_OWNER}/${IMAGE_NAME}:$TAG"
TAG_ARGS="${TAG_ARGS} --tag ${FULL_TAG}"
PRINT_LIST="${PRINT_LIST}${FULL_TAG} "
fi
if [[ "${REGISTRIES}" == *"quay"* ]]; then
FULL_TAG="quay.io/${IMAGE_NAME}:$TAG"
TAG_ARGS="${TAG_ARGS} --tag ${FULL_TAG}"
PRINT_LIST="${PRINT_LIST}${FULL_TAG} "
fi
done
echo "tags=${TAG_ARGS}" >> "$GITHUB_OUTPUT"
echo "computed_tags=${PRINT_LIST}" >> "$GITHUB_OUTPUT"
- name: Show computed tags (action logs)
run: |
echo "----- Computed tag args (passed to docker buildx) -----"
echo "${{ steps.tagger.outputs.tags }}"
echo
echo "----- Computed full image names (human-readable) -----"
echo "${{ steps.tagger.outputs.computed_tags }}"
echo
echo "----- Full docker buildx command that will be executed -----"
echo docker buildx build --platform linux/amd64,linux/arm64 ${{ steps.tagger.outputs.tags }} --push -f Dockerfile .
shell: bash
- name: Fail early if no tags computed
if: ${{ steps.tagger.outputs.computed_tags == '' }}
run: |
echo "ERROR: No tags were computed for any registry. Check inputs." >&2
exit 1
- name: Log in to Docker Hub
if: contains(github.event.inputs.registries_to_push, 'dockerhub')
uses: docker/login-action@v3
with:
username: ${{ github.event.inputs.dockerhub_user }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GHCR
if: contains(github.event.inputs.registries_to_push, 'ghcr')
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Log in to Quay.io
if: contains(github.event.inputs.registries_to_push, 'quay')
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Build and Push Multi-Arch Image
run: |
set -x
docker buildx build \
--platform linux/amd64,linux/arm64 \
${{ steps.tagger.outputs.tags }} \
--push \
-f Dockerfile \
.