mirror of
https://github.com/driftywinds/twitchrise-bot.git
synced 2025-12-20 12:03:56 +00:00
Update build.yml
This commit is contained in:
166
.github/workflows/build.yml
vendored
166
.github/workflows/build.yml
vendored
@@ -1,117 +1,153 @@
|
|||||||
name: Multi-Arch Docker Build & Push
|
name: Build and Push Multi-Arch Docker Images
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
image_name:
|
image_name:
|
||||||
description: "Image name without registry (e.g. myuser/myimage)"
|
description: 'Docker image name (e.g. user/image)'
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
tags:
|
tags:
|
||||||
description: "Comma-separated list of tags (e.g. v1.0.1,latest,dev,beta)"
|
description: 'Comma-separated tags (e.g. v1.01,latest,dev,beta)'
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
push_dockerhub:
|
push_dockerhub:
|
||||||
description: "Push to Docker Hub"
|
description: 'Push to Docker Hub'
|
||||||
required: true
|
required: false
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: true
|
||||||
push_ghcr:
|
push_ghcr:
|
||||||
description: "Push to GitHub Container Registry"
|
description: 'Push to GitHub Container Registry'
|
||||||
required: true
|
required: false
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: true
|
||||||
push_quay:
|
push_quay:
|
||||||
description: "Push to Quay.io"
|
description: 'Push to Quay.io'
|
||||||
required: true
|
required: false
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build-and-push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
packages: write
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v3
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
- name: Normalize tags
|
- name: Log in to Docker Hub
|
||||||
id: vars
|
if: ${{ inputs.push_dockerhub == 'true' }}
|
||||||
run: |
|
uses: docker/login-action@v2
|
||||||
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:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
registry: docker.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Login to GHCR
|
- name: Log in to GitHub Container Registry
|
||||||
if: ${{ github.event.inputs.push_ghcr == 'true' }}
|
if: ${{ inputs.push_ghcr == 'true' }}
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GHCR_TOKEN }}
|
password: ${{ secrets.GHCR_TOKEN }}
|
||||||
|
|
||||||
- name: Login to Quay.io
|
- name: Log in to Quay.io
|
||||||
if: ${{ github.event.inputs.push_quay == 'true' }}
|
if: ${{ inputs.push_quay == 'true' }}
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: quay.io
|
registry: quay.io
|
||||||
username: ${{ secrets.QUAY_USERNAME }}
|
username: ${{ secrets.QUAY_USERNAME }}
|
||||||
password: ${{ secrets.QUAY_TOKEN }}
|
password: ${{ secrets.QUAY_PASSWORD }}
|
||||||
|
|
||||||
# Build once and save to local cache
|
- name: Prepare tags
|
||||||
- name: Build multi-arch image
|
id: prepare_tags
|
||||||
run: |
|
run: |
|
||||||
|
I="${{ inputs.image_name }}"
|
||||||
|
# Remove spaces from tags and split by comma
|
||||||
|
TAGS_RAW="${{ inputs.tags }}"
|
||||||
|
TAGS=$(echo $TAGS_RAW | tr -d ' ' | tr ',' '\n')
|
||||||
|
echo "image_name=$I" >> $GITHUB_OUTPUT
|
||||||
|
echo "tags=$TAGS_RAW" >> $GITHUB_OUTPUT
|
||||||
|
echo "::set-output name=tags_list::$TAGS_RAW"
|
||||||
|
echo "tag_array<<EOF" >> $GITHUB_OUTPUT
|
||||||
|
echo "$TAGS" >> $GITHUB_OUTPUT
|
||||||
|
echo "EOF" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Build Docker image (multi-arch)
|
||||||
|
id: build_image
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
image_name="${{ inputs.image_name }}"
|
||||||
|
tags_raw="${{ inputs.tags }}"
|
||||||
|
tags=$(echo $tags_raw | tr -d ' ' | tr ',' ' ')
|
||||||
|
|
||||||
|
# Build with all tags on local docker cache (no push)
|
||||||
|
# Use buildx to build for linux/amd64,linux/arm64
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--platform linux/amd64,linux/arm64 \
|
--platform linux/amd64,linux/arm64 \
|
||||||
--output=type=docker \
|
--load \
|
||||||
-t tempimage:build .
|
$(for t in $tags; do echo "-t $image_name:$t "; done) \
|
||||||
|
.
|
||||||
|
shell: bash
|
||||||
|
|
||||||
# Push to Docker Hub
|
|
||||||
- name: Push to Docker Hub
|
- name: Push to Docker Hub
|
||||||
if: ${{ github.event.inputs.push_dockerhub == 'true' }}
|
if: ${{ inputs.push_dockerhub == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
for tag in ${{ steps.vars.outputs.tags_list }}; do
|
set +e
|
||||||
docker tag tempimage:build docker.io/${{ github.event.inputs.image_name }}:$tag
|
image_name="${{ inputs.image_name }}"
|
||||||
docker push docker.io/${{ github.event.inputs.image_name }}:$tag || echo "Docker Hub push failed for tag $tag"
|
tags_raw="${{ inputs.tags }}"
|
||||||
|
tags=$(echo $tags_raw | tr -d ' ' | tr ',' ' ')
|
||||||
|
error=0
|
||||||
|
for tag in $tags; do
|
||||||
|
docker tag "$image_name:$tag" "docker.io/$image_name:$tag"
|
||||||
done
|
done
|
||||||
continue-on-error: true
|
for tag in $tags; do
|
||||||
|
echo "Pushing docker.io/$image_name:$tag"
|
||||||
|
docker push "docker.io/$image_name:$tag" || error=1
|
||||||
|
done
|
||||||
|
if [ $error -ne 0 ]; then
|
||||||
|
echo "Warning: Some pushes to Docker Hub failed."
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|
||||||
# Push to GHCR
|
- name: Push to GitHub Container Registry
|
||||||
- name: Push to GHCR
|
if: ${{ inputs.push_ghcr == 'true' }}
|
||||||
if: ${{ github.event.inputs.push_ghcr == 'true' }}
|
|
||||||
run: |
|
run: |
|
||||||
for tag in ${{ steps.vars.outputs.tags_list }}; do
|
set +e
|
||||||
docker tag tempimage:build ghcr.io/${{ github.event.inputs.image_name }}:$tag
|
image_name="${{ inputs.image_name }}"
|
||||||
docker push ghcr.io/${{ github.event.inputs.image_name }}:$tag || echo "GHCR push failed for tag $tag"
|
tags_raw="${{ inputs.tags }}"
|
||||||
|
tags=$(echo $tags_raw | tr -d ' ' | tr ',' ' ')
|
||||||
|
error=0
|
||||||
|
for tag in $tags; do
|
||||||
|
docker tag "$image_name:$tag" "ghcr.io/${{ github.repository_owner }}/$image_name:$tag"
|
||||||
done
|
done
|
||||||
continue-on-error: true
|
for tag in $tags; do
|
||||||
|
echo "Pushing ghcr.io/${{ github.repository_owner }}/$image_name:$tag"
|
||||||
|
docker push "ghcr.io/${{ github.repository_owner }}/$image_name:$tag" || error=1
|
||||||
|
done
|
||||||
|
if [ $error -ne 0 ]; then
|
||||||
|
echo "Warning: Some pushes to GHCR failed."
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|
||||||
# Push to Quay.io
|
|
||||||
- name: Push to Quay.io
|
- name: Push to Quay.io
|
||||||
if: ${{ github.event.inputs.push_quay == 'true' }}
|
if: ${{ inputs.push_quay == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
for tag in ${{ steps.vars.outputs.tags_list }}; do
|
set +e
|
||||||
docker tag tempimage:build quay.io/${{ github.event.inputs.image_name }}:$tag
|
image_name="${{ inputs.image_name }}"
|
||||||
docker push quay.io/${{ github.event.inputs.image_name }}:$tag || echo "Quay push failed for tag $tag"
|
tags_raw="${{ inputs.tags }}"
|
||||||
|
tags=$(echo $tags_raw | tr -d ' ' | tr ',' ' ')
|
||||||
|
error=0
|
||||||
|
for tag in $tags; do
|
||||||
|
docker tag "$image_name:$tag" "quay.io/$image_name:$tag"
|
||||||
done
|
done
|
||||||
continue-on-error: true
|
for tag in $tags; do
|
||||||
|
echo "Pushing quay.io/$image_name:$tag"
|
||||||
|
docker push "quay.io/$image_name:$tag" || error=1
|
||||||
|
done
|
||||||
|
if [ $error -ne 0 ]; then
|
||||||
|
echo "Warning: Some pushes to Quay.io failed."
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|||||||
Reference in New Issue
Block a user