mirror of
https://github.com/driftywinds/twitchrise-bot.git
synced 2025-12-19 03:33:32 +00:00
Update build.yml
This commit is contained in:
168
.github/workflows/build.yml
vendored
168
.github/workflows/build.yml
vendored
@@ -1,25 +1,34 @@
|
|||||||
name: Multi-Arch Docker Build & Push (debuggable)
|
name: Multi-Arch Docker Build & Push
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
image_name:
|
|
||||||
description: "Base image name (e.g. myuser/myimage or repo/image)"
|
|
||||||
required: true
|
|
||||||
tags:
|
tags:
|
||||||
description: "Image tags (comma or space separated). Example: v1.01 latest beta"
|
description: "Comma-separated list of tags (e.g. v1.0.1,latest,dev,beta)"
|
||||||
required: true
|
required: true
|
||||||
dockerhub_user:
|
type: string
|
||||||
description: "Docker Hub username (if pushing there)"
|
push_dockerhub:
|
||||||
required: false
|
description: "Push to Docker Hub"
|
||||||
registries_to_push:
|
|
||||||
description: "Registries to push to (comma or space separated: dockerhub, ghcr, quay)"
|
|
||||||
required: true
|
required: true
|
||||||
default: "dockerhub, ghcr"
|
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:
|
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@v4
|
||||||
@@ -30,98 +39,79 @@ jobs:
|
|||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Parse tags and compute full image names
|
- name: Parse tags
|
||||||
id: tagger
|
id: tags
|
||||||
env:
|
|
||||||
TAGS_INPUT: ${{ github.event.inputs.tags }}
|
|
||||||
IMAGE_NAME: ${{ github.event.inputs.image_name }}
|
|
||||||
DOCKERHUB_USER: ${{ github.event.inputs.dockerhub_user }}
|
|
||||||
REGISTRIES_INPUT: ${{ github.event.inputs.registries_to_push }}
|
|
||||||
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
|
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
TAGS_INPUT="${{ github.event.inputs.tags }}"
|
||||||
TAGS_INPUT=$(echo "${TAGS_INPUT:-}" | tr ',' ' ')
|
IFS=',' read -ra TAGS_ARRAY <<< "$TAGS_INPUT"
|
||||||
REGISTRIES=$(echo "${REGISTRIES_INPUT:-}" | tr ',' ' ')
|
for i in "${TAGS_ARRAY[@]}"; do
|
||||||
|
CLEAN_TAG="$(echo "$i" | xargs)" # trim spaces
|
||||||
TAG_ARGS=""
|
echo "tag=$CLEAN_TAG" >> "$GITHUB_OUTPUT"
|
||||||
PRINT_LIST=""
|
echo "tags_list=${tags_list} $CLEAN_TAG" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
for TAG in $TAGS_INPUT; do
|
|
||||||
for REG in $REGISTRIES; do
|
|
||||||
case "$REG" in
|
|
||||||
dockerhub)
|
|
||||||
if [ -n "${DOCKERHUB_USER}" ]; then
|
|
||||||
FULL_TAG="docker.io/${DOCKERHUB_USER}/${IMAGE_NAME}:$TAG"
|
|
||||||
else
|
|
||||||
FULL_TAG="docker.io/${IMAGE_NAME}:$TAG"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
ghcr)
|
|
||||||
FULL_TAG="ghcr.io/${GITHUB_REPOSITORY_OWNER}/${IMAGE_NAME}:$TAG"
|
|
||||||
;;
|
|
||||||
quay)
|
|
||||||
FULL_TAG="quay.io/${IMAGE_NAME}:$TAG"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unknown registry: $REG"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
TAG_ARGS="${TAG_ARGS} --tag ${FULL_TAG}"
|
|
||||||
PRINT_LIST="${PRINT_LIST}${FULL_TAG} "
|
|
||||||
done
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "tags=${TAG_ARGS}" >> "$GITHUB_OUTPUT"
|
# Docker Hub login (optional)
|
||||||
echo "computed_tags=${PRINT_LIST}" >> "$GITHUB_OUTPUT"
|
- name: Login to Docker Hub
|
||||||
|
if: ${{ github.event.inputs.push_dockerhub == 'true' }}
|
||||||
- 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
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ github.event.inputs.dockerhub_user }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Log in to GHCR
|
# GHCR login (optional)
|
||||||
if: contains(github.event.inputs.registries_to_push, 'ghcr')
|
- name: Login to GHCR
|
||||||
|
if: ${{ github.event.inputs.push_ghcr == 'true' }}
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GHCR_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Log in to Quay.io
|
# Quay.io login (optional)
|
||||||
if: contains(github.event.inputs.registries_to_push, 'quay')
|
- name: Login to Quay.io
|
||||||
|
if: ${{ github.event.inputs.push_quay == 'true' }}
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: quay.io
|
registry: quay.io
|
||||||
username: ${{ secrets.QUAY_USERNAME }}
|
username: ${{ secrets.QUAY_USERNAME }}
|
||||||
password: ${{ secrets.QUAY_PASSWORD }}
|
password: ${{ secrets.QUAY_TOKEN }}
|
||||||
|
|
||||||
- name: Build and Push Multi-Arch Image
|
# Push to Docker Hub
|
||||||
|
- name: Build & Push to Docker Hub
|
||||||
|
if: ${{ github.event.inputs.push_dockerhub == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
set -x
|
set -e
|
||||||
docker buildx build \
|
for tag in $(echo "${{ github.event.inputs.tags }}" | tr ',' ' '); do
|
||||||
--platform linux/amd64,linux/arm64 \
|
docker buildx build \
|
||||||
${{ steps.tagger.outputs.tags }} \
|
--platform linux/amd64,linux/arm64 \
|
||||||
--push \
|
--push \
|
||||||
-f Dockerfile \
|
-t docker.io/${{ secrets.DOCKERHUB_USERNAME }}/$(basename $GITHUB_REPOSITORY):$(echo "$tag" | xargs) .
|
||||||
.
|
done
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
# Push to GHCR
|
||||||
|
- name: Build & Push to GHCR
|
||||||
|
if: ${{ github.event.inputs.push_ghcr == 'true' }}
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
REPO_NAME=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')
|
||||||
|
for tag in $(echo "${{ github.event.inputs.tags }}" | tr ',' ' '); do
|
||||||
|
docker buildx build \
|
||||||
|
--platform linux/amd64,linux/arm64 \
|
||||||
|
--push \
|
||||||
|
-t ghcr.io/${REPO_NAME}:$(echo "$tag" | xargs) .
|
||||||
|
done
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
# Push to Quay.io
|
||||||
|
- name: Build & Push to Quay.io
|
||||||
|
if: ${{ github.event.inputs.push_quay == 'true' }}
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
for tag in $(echo "${{ github.event.inputs.tags }}" | tr ',' ' '); do
|
||||||
|
docker buildx build \
|
||||||
|
--platform linux/amd64,linux/arm64 \
|
||||||
|
--push \
|
||||||
|
-t quay.io/${{ secrets.QUAY_USERNAME }}/$(basename $GITHUB_REPOSITORY):$(echo "$tag" | xargs) .
|
||||||
|
done
|
||||||
|
continue-on-error: true
|
||||||
|
|||||||
Reference in New Issue
Block a user