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

118 lines
3.7 KiB
YAML

name: Multi-Arch Docker Build & Push
on:
workflow_dispatch:
inputs:
image_name:
description: "Image name without registry (e.g. myuser/myimage)"
required: true
type: string
tags:
description: "Comma-separated list of tags (e.g. v1.0.1,latest,dev,beta)"
required: true
type: string
push_dockerhub:
description: "Push to Docker Hub"
required: true
type: boolean
default: false
push_ghcr:
description: "Push to GitHub Container Registry"
required: true
type: boolean
default: false
push_quay:
description: "Push to Quay.io"
required: true
type: boolean
default: false
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
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: Normalize tags
id: vars
run: |
TAGS_INPUT="${{ github.event.inputs.tags }}"
IFS=',' read -ra TAGS_ARRAY <<< "$TAGS_INPUT"
CLEAN_TAGS=()
for t in "${TAGS_ARRAY[@]}"; do
CLEAN_TAGS+=("$(echo "$t" | xargs)")
done
echo "tags_list=${CLEAN_TAGS[*]}" >> "$GITHUB_OUTPUT"
# Logins
- name: Login to Docker Hub
if: ${{ github.event.inputs.push_dockerhub == 'true' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR
if: ${{ github.event.inputs.push_ghcr == 'true' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Login to Quay.io
if: ${{ github.event.inputs.push_quay == 'true' }}
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
# Build once and save to local cache
- name: Build multi-arch image
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--output=type=docker \
-t tempimage:build .
# Push to Docker Hub
- name: Push to Docker Hub
if: ${{ github.event.inputs.push_dockerhub == 'true' }}
run: |
for tag in ${{ steps.vars.outputs.tags_list }}; do
docker tag tempimage:build docker.io/${{ github.event.inputs.image_name }}:$tag
docker push docker.io/${{ github.event.inputs.image_name }}:$tag || echo "Docker Hub push failed for tag $tag"
done
continue-on-error: true
# Push to GHCR
- name: Push to GHCR
if: ${{ github.event.inputs.push_ghcr == 'true' }}
run: |
for tag in ${{ steps.vars.outputs.tags_list }}; do
docker tag tempimage:build ghcr.io/${{ github.event.inputs.image_name }}:$tag
docker push ghcr.io/${{ github.event.inputs.image_name }}:$tag || echo "GHCR push failed for tag $tag"
done
continue-on-error: true
# Push to Quay.io
- name: Push to Quay.io
if: ${{ github.event.inputs.push_quay == 'true' }}
run: |
for tag in ${{ steps.vars.outputs.tags_list }}; do
docker tag tempimage:build quay.io/${{ github.event.inputs.image_name }}:$tag
docker push quay.io/${{ github.event.inputs.image_name }}:$tag || echo "Quay push failed for tag $tag"
done
continue-on-error: true