Update build.yml

This commit is contained in:
drifty
2025-08-11 14:39:38 +05:30
committed by GitHub
parent 0c38fac3dc
commit 0e2937ffeb

View File

@@ -4,26 +4,24 @@ on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
image_name: image_name:
description: "Base image name (e.g. myuser/myimage or repo/image)." description: "Base image name (e.g. myuser/myimage or repo/image)"
required: true required: true
tags: tags:
description: "Image tags (comma or space separated). Example: v1.01 latest beta" description: "Image tags (comma or space separated). Example: v1.01 latest beta"
required: true required: true
dockerhub_user: dockerhub_user:
description: "Docker Hub username (leave empty if not pushing to Docker Hub)" description: "Docker Hub username (if pushing there)"
required: false required: false
push_to_dockerhub: registries_to_push:
description: "Push to Docker Hub? (true/false)" type: choice
description: "Select registries to push to"
options:
- dockerhub
- ghcr
- quay
required: false required: false
default: "false" default: []
push_to_ghcr: multiple: true # allows checkbox-like UI
description: "Push to GHCR? (true/false)"
required: false
default: "false"
push_to_quay:
description: "Push to Quay.io? (true/false)"
required: false
default: "false"
jobs: jobs:
build-and-push: build-and-push:
@@ -44,22 +42,17 @@ jobs:
TAGS_INPUT: ${{ github.event.inputs.tags }} TAGS_INPUT: ${{ github.event.inputs.tags }}
IMAGE_NAME: ${{ github.event.inputs.image_name }} IMAGE_NAME: ${{ github.event.inputs.image_name }}
DOCKERHUB_USER: ${{ github.event.inputs.dockerhub_user }} DOCKERHUB_USER: ${{ github.event.inputs.dockerhub_user }}
PUSH_DOCKERHUB: ${{ github.event.inputs.push_to_dockerhub }} REGISTRIES: ${{ github.event.inputs.registries_to_push }}
PUSH_GHCR: ${{ github.event.inputs.push_to_ghcr }}
PUSH_QUAY: ${{ github.event.inputs.push_to_quay }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
run: | run: |
set -eu set -eu
# normalize commas to spaces
TAGS_INPUT=$(echo "${TAGS_INPUT:-}" | tr ',' ' ') TAGS_INPUT=$(echo "${TAGS_INPUT:-}" | tr ',' ' ')
TAG_ARGS="" TAG_ARGS=""
PRINT_LIST="" PRINT_LIST=""
for TAG in $TAGS_INPUT; do for TAG in $TAGS_INPUT; do
# Docker Hub if [[ "${REGISTRIES}" == *"dockerhub"* ]]; then
if [ "${PUSH_DOCKERHUB}" = "true" ]; then
if [ -n "${DOCKERHUB_USER}" ]; then if [ -n "${DOCKERHUB_USER}" ]; then
FULL_TAG="docker.io/${DOCKERHUB_USER}/${IMAGE_NAME}:$TAG" FULL_TAG="docker.io/${DOCKERHUB_USER}/${IMAGE_NAME}:$TAG"
else else
@@ -69,23 +62,19 @@ jobs:
PRINT_LIST="${PRINT_LIST}${FULL_TAG} " PRINT_LIST="${PRINT_LIST}${FULL_TAG} "
fi fi
# GHCR (use repo owner namespace) if [[ "${REGISTRIES}" == *"ghcr"* ]]; then
if [ "${PUSH_GHCR}" = "true" ]; then
FULL_TAG="ghcr.io/${GITHUB_REPOSITORY_OWNER}/${IMAGE_NAME}:$TAG" FULL_TAG="ghcr.io/${GITHUB_REPOSITORY_OWNER}/${IMAGE_NAME}:$TAG"
TAG_ARGS="${TAG_ARGS} --tag ${FULL_TAG}" TAG_ARGS="${TAG_ARGS} --tag ${FULL_TAG}"
PRINT_LIST="${PRINT_LIST}${FULL_TAG} " PRINT_LIST="${PRINT_LIST}${FULL_TAG} "
fi fi
# Quay if [[ "${REGISTRIES}" == *"quay"* ]]; then
if [ "${PUSH_QUAY}" = "true" ]; then
# If you want an org prefix for quay, include it in IMAGE_NAME when running the workflow
FULL_TAG="quay.io/${IMAGE_NAME}:$TAG" FULL_TAG="quay.io/${IMAGE_NAME}:$TAG"
TAG_ARGS="${TAG_ARGS} --tag ${FULL_TAG}" TAG_ARGS="${TAG_ARGS} --tag ${FULL_TAG}"
PRINT_LIST="${PRINT_LIST}${FULL_TAG} " PRINT_LIST="${PRINT_LIST}${FULL_TAG} "
fi fi
done done
# Export outputs for later steps
echo "tags=${TAG_ARGS}" >> "$GITHUB_OUTPUT" echo "tags=${TAG_ARGS}" >> "$GITHUB_OUTPUT"
echo "computed_tags=${PRINT_LIST}" >> "$GITHUB_OUTPUT" echo "computed_tags=${PRINT_LIST}" >> "$GITHUB_OUTPUT"
@@ -104,18 +93,18 @@ jobs:
- name: Fail early if no tags computed - name: Fail early if no tags computed
if: ${{ steps.tagger.outputs.computed_tags == '' }} if: ${{ steps.tagger.outputs.computed_tags == '' }}
run: | run: |
echo "ERROR: No tags were computed for any registry. Check inputs (image_name, tags, and push_to_* flags)." >&2 echo "ERROR: No tags were computed for any registry. Check inputs." >&2
exit 1 exit 1
- name: Log in to Docker Hub - name: Log in to Docker Hub
if: github.event.inputs.push_to_dockerhub == 'true' 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: ${{ github.event.inputs.dockerhub_user }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GHCR - name: Log in to GHCR
if: github.event.inputs.push_to_ghcr == 'true' if: contains(github.event.inputs.registries_to_push, 'ghcr')
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
@@ -123,7 +112,7 @@ jobs:
password: ${{ secrets.GHCR_TOKEN }} password: ${{ secrets.GHCR_TOKEN }}
- name: Log in to Quay.io - name: Log in to Quay.io
if: github.event.inputs.push_to_quay == 'true' if: contains(github.event.inputs.registries_to_push, 'quay')
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: quay.io registry: quay.io