Update build.yml

This commit is contained in:
drifty
2025-08-11 15:12:08 +05:30
committed by GitHub
parent d4726bca97
commit 1d4e726eb9

View File

@@ -1,27 +1,28 @@
name: Build and Push Multi-Arch Docker Images name: Multi-Architecture Docker Build
on: on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
image_name: image_name:
description: 'Docker image name (e.g. user/image)' description: 'Docker image name (e.g., user/image)'
required: true required: true
type: string type: string
tags: image_tag:
description: 'Comma-separated tags (e.g. v1.01,latest,dev,beta)' description: 'Docker image tag (e.g., latest, v1.1.0)'
required: true required: true
type: string type: string
push_dockerhub: default: 'latest'
push_to_dockerhub:
description: 'Push to Docker Hub' description: 'Push to Docker Hub'
required: false required: false
type: boolean type: boolean
default: true default: true
push_ghcr: push_to_ghcr:
description: 'Push to GitHub Container Registry' description: 'Push to GitHub Container Registry'
required: false required: false
type: boolean type: boolean
default: true default: true
push_quay: push_to_quay:
description: 'Push to Quay.io' description: 'Push to Quay.io'
required: false required: false
type: boolean type: boolean
@@ -33,97 +34,136 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub - name: Login to Docker Hub
if: ${{ inputs.push_dockerhub == 'true' }} if: ${{ inputs.push_to_dockerhub }}
uses: docker/login-action@v2 uses: docker/login-action@v3
with: with:
registry: docker.io username: ${{ vars.DOCKERHUB_USERNAME || github.actor }}
username: ${{ github.actor }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
continue-on-error: true
id: dockerhub-login
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
if: ${{ inputs.push_ghcr == 'true' }} if: ${{ inputs.push_to_ghcr }}
uses: docker/login-action@v2 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }} password: ${{ secrets.GHCR_TOKEN }}
continue-on-error: true
id: ghcr-login
- name: Login to Quay.io - name: Login to Quay.io
if: ${{ inputs.push_quay == 'true' }} if: ${{ inputs.push_to_quay }}
uses: docker/login-action@v2 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_PASSWORD }}
continue-on-error: true
id: quay-login
- name: Prepare tags - name: Extract metadata
id: prepare_tags id: meta
run: | uses: docker/metadata-action@v5
echo "IMAGE_NAME=${{ inputs.image_name }}" >> $GITHUB_ENV with:
# Normalize tags: remove spaces and split by comma images: |
TAGS_RAW="${{ inputs.tags }}" name=${{ inputs.image_name }},enable=${{ inputs.push_to_dockerhub && steps.dockerhub-login.outcome == 'success' }}
TAGS=$(echo "$TAGS_RAW" | tr -d ' ' | tr ',' '\n') name=ghcr.io/${{ inputs.image_name }},enable=${{ inputs.push_to_ghcr && steps.ghcr-login.outcome == 'success' }}
echo "TAGS=$TAGS_RAW" >> $GITHUB_ENV name=quay.io/${{ inputs.image_name }},enable=${{ inputs.push_to_quay && steps.quay-login.outcome == 'success' }}
echo "TAGS_LIST<<EOF" >> $GITHUB_ENV tags: |
echo "$TAGS" >> $GITHUB_ENV type=raw,value=${{ inputs.image_tag }}
echo "EOF" >> $GITHUB_ENV
- name: Build & push to Docker Hub - name: Build and push Docker image
if: ${{ inputs.push_dockerhub == 'true' }} uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
continue-on-error: false
- name: Push to Docker Hub (fallback)
if: ${{ inputs.push_to_dockerhub && steps.dockerhub-login.outcome == 'success' && failure() }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ inputs.image_name }}:${{ inputs.image_tag }}
labels: ${{ steps.meta.outputs.labels }}
continue-on-error: true
- name: Push to GHCR (fallback)
if: ${{ inputs.push_to_ghcr && steps.ghcr-login.outcome == 'success' && failure() }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ inputs.image_name }}:${{ inputs.image_tag }}
labels: ${{ steps.meta.outputs.labels }}
continue-on-error: true
- name: Push to Quay.io (fallback)
if: ${{ inputs.push_to_quay && steps.quay-login.outcome == 'success' && failure() }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: quay.io/${{ inputs.image_name }}:${{ inputs.image_tag }}
labels: ${{ steps.meta.outputs.labels }}
continue-on-error: true
- name: Build Summary
if: always()
run: | run: |
set +e echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
for TAG in $(echo $TAGS | tr '\n' ' '); do echo "**Image Name:** ${{ inputs.image_name }}" >> $GITHUB_STEP_SUMMARY
TAGS_ARGS="$TAGS_ARGS -t docker.io/$IMAGE_NAME:$TAG" echo "**Image Tag:** ${{ inputs.image_tag }}" >> $GITHUB_STEP_SUMMARY
done echo "**Platforms:** linux/amd64, linux/arm64" >> $GITHUB_STEP_SUMMARY
echo "Building and pushing to Docker Hub..." echo "" >> $GITHUB_STEP_SUMMARY
docker buildx build \ echo "### Registry Push Status:" >> $GITHUB_STEP_SUMMARY
--platform linux/amd64,linux/arm64 \
$TAGS_ARGS \ if [[ "${{ inputs.push_to_dockerhub }}" == "true" ]]; then
--push \ if [[ "${{ steps.dockerhub-login.outcome }}" == "success" ]]; then
. echo "- ✅ Docker Hub: Attempted" >> $GITHUB_STEP_SUMMARY
if [ $? -ne 0 ]; then else
echo "Warning: Docker Hub push failed." echo "- ❌ Docker Hub: Login failed" >> $GITHUB_STEP_SUMMARY
fi fi
shell: bash else
echo "- ⏭️ Docker Hub: Skipped" >> $GITHUB_STEP_SUMMARY
- 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 fi
shell: bash
- name: Build & push to Quay.io if [[ "${{ inputs.push_to_ghcr }}" == "true" ]]; then
if: ${{ inputs.push_quay == 'true' }} if [[ "${{ steps.ghcr-login.outcome }}" == "success" ]]; then
run: | echo "- ✅ GHCR: Attempted" >> $GITHUB_STEP_SUMMARY
set +e else
for TAG in $(echo $TAGS | tr '\n' ' '); do echo "- ❌ GHCR: Login failed" >> $GITHUB_STEP_SUMMARY
TAGS_ARGS="$TAGS_ARGS -t quay.io/$IMAGE_NAME:$TAG" fi
done else
echo "Building and pushing to Quay.io..." echo "- ⏭️ GHCR: Skipped" >> $GITHUB_STEP_SUMMARY
docker buildx build \ fi
--platform linux/amd64,linux/arm64 \
$TAGS_ARGS \ if [[ "${{ inputs.push_to_quay }}" == "true" ]]; then
--push \ if [[ "${{ steps.quay-login.outcome }}" == "success" ]]; then
. echo "- ✅ Quay.io: Attempted" >> $GITHUB_STEP_SUMMARY
if [ $? -ne 0 ]; then else
echo "Warning: Quay.io push failed." echo "- ❌ Quay.io: Login failed" >> $GITHUB_STEP_SUMMARY
fi
else
echo "- ⏭️ Quay.io: Skipped" >> $GITHUB_STEP_SUMMARY
fi fi
shell: bash