mirror of
https://github.com/driftywinds/twitchrise-bot.git
synced 2026-01-07 19:13:52 +00:00
130 lines
3.7 KiB
YAML
130 lines
3.7 KiB
YAML
name: Build and Push Multi-Arch Docker Images
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
image_name:
|
|
description: 'Docker image name (e.g. user/image)'
|
|
required: true
|
|
type: string
|
|
tags:
|
|
description: 'Comma-separated tags (e.g. v1.01,latest,dev,beta)'
|
|
required: true
|
|
type: string
|
|
push_dockerhub:
|
|
description: 'Push to Docker Hub'
|
|
required: false
|
|
type: boolean
|
|
default: true
|
|
push_ghcr:
|
|
description: 'Push to GitHub Container Registry'
|
|
required: false
|
|
type: boolean
|
|
default: true
|
|
push_quay:
|
|
description: 'Push to Quay.io'
|
|
required: false
|
|
type: boolean
|
|
default: false
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Log in to Docker Hub
|
|
if: ${{ inputs.push_dockerhub == 'true' }}
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: docker.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Log in to GitHub Container Registry
|
|
if: ${{ inputs.push_ghcr == 'true' }}
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
- name: Log in to Quay.io
|
|
if: ${{ inputs.push_quay == 'true' }}
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: quay.io
|
|
username: ${{ secrets.QUAY_USERNAME }}
|
|
password: ${{ secrets.QUAY_PASSWORD }}
|
|
|
|
- name: Prepare tags
|
|
id: prepare_tags
|
|
run: |
|
|
echo "IMAGE_NAME=${{ inputs.image_name }}" >> $GITHUB_ENV
|
|
# Normalize tags: remove spaces and split by comma
|
|
TAGS_RAW="${{ inputs.tags }}"
|
|
TAGS=$(echo "$TAGS_RAW" | tr -d ' ' | tr ',' '\n')
|
|
echo "TAGS=$TAGS_RAW" >> $GITHUB_ENV
|
|
echo "TAGS_LIST<<EOF" >> $GITHUB_ENV
|
|
echo "$TAGS" >> $GITHUB_ENV
|
|
echo "EOF" >> $GITHUB_ENV
|
|
|
|
- name: Build & push to Docker Hub
|
|
if: ${{ inputs.push_dockerhub == 'true' }}
|
|
run: |
|
|
set +e
|
|
for TAG in $(echo $TAGS | tr '\n' ' '); do
|
|
TAGS_ARGS="$TAGS_ARGS -t docker.io/$IMAGE_NAME:$TAG"
|
|
done
|
|
echo "Building and pushing to Docker Hub..."
|
|
docker buildx build \
|
|
--platform linux/amd64,linux/arm64 \
|
|
$TAGS_ARGS \
|
|
--push \
|
|
.
|
|
if [ $? -ne 0 ]; then
|
|
echo "Warning: Docker Hub push failed."
|
|
fi
|
|
shell: bash
|
|
|
|
- name: Build & push to GitHub Container Registry
|
|
if: ${{ inputs.push_ghcr == 'true' }}
|
|
run: |
|
|
set +e
|
|
for TAG in $(echo $TAGS | tr '\n' ' '); do
|
|
TAGS_ARGS="$TAGS_ARGS -t ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$TAG"
|
|
done
|
|
echo "Building and pushing to GHCR..."
|
|
docker buildx build \
|
|
--platform linux/amd64,linux/arm64 \
|
|
$TAGS_ARGS \
|
|
--push \
|
|
.
|
|
if [ $? -ne 0 ]; then
|
|
echo "Warning: GHCR push failed."
|
|
fi
|
|
shell: bash
|
|
|
|
- name: Build & push to Quay.io
|
|
if: ${{ inputs.push_quay == 'true' }}
|
|
run: |
|
|
set +e
|
|
for TAG in $(echo $TAGS | tr '\n' ' '); do
|
|
TAGS_ARGS="$TAGS_ARGS -t quay.io/$IMAGE_NAME:$TAG"
|
|
done
|
|
echo "Building and pushing to Quay.io..."
|
|
docker buildx build \
|
|
--platform linux/amd64,linux/arm64 \
|
|
$TAGS_ARGS \
|
|
--push \
|
|
.
|
|
if [ $? -ne 0 ]; then
|
|
echo "Warning: Quay.io push failed."
|
|
fi
|
|
shell: bash
|