Update build.yml

This commit is contained in:
drifty
2025-08-11 14:53:37 +05:30
committed by GitHub
parent a2ee0561f6
commit e9c14dd30d

View File

@@ -3,6 +3,10 @@ name: Multi-Arch Docker Build & Push
on: on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
image_name:
description: "Image name without registry (e.g. myuser/myimage)"
required: true
type: string
tags: tags:
description: "Comma-separated list of tags (e.g. v1.0.1,latest,dev,beta)" description: "Comma-separated list of tags (e.g. v1.0.1,latest,dev,beta)"
required: true required: true
@@ -50,7 +54,7 @@ jobs:
done done
echo "tags_list=${CLEAN_TAGS[*]}" >> "$GITHUB_OUTPUT" echo "tags_list=${CLEAN_TAGS[*]}" >> "$GITHUB_OUTPUT"
# Login (optional per registry) # Logins
- name: Login to Docker Hub - name: Login to Docker Hub
if: ${{ github.event.inputs.push_dockerhub == 'true' }} if: ${{ github.event.inputs.push_dockerhub == 'true' }}
uses: docker/login-action@v3 uses: docker/login-action@v3
@@ -74,23 +78,21 @@ jobs:
username: ${{ secrets.QUAY_USERNAME }} username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }} password: ${{ secrets.QUAY_TOKEN }}
# Build once and store in local cache # Build once and save to local cache
- name: Build multi-arch image - name: Build multi-arch image
run: | run: |
docker buildx build \ docker buildx build \
--platform linux/amd64,linux/arm64 \ --platform linux/amd64,linux/arm64 \
--output=type=registry,dest=/tmp/buildcache.tar \ --output=type=docker \
-t tempimage:build . -t tempimage:build .
shell: bash
# Push to Docker Hub # Push to Docker Hub
- name: Push to Docker Hub - name: Push to Docker Hub
if: ${{ github.event.inputs.push_dockerhub == 'true' }} if: ${{ github.event.inputs.push_dockerhub == 'true' }}
run: | run: |
docker load < /tmp/buildcache.tar || true
for tag in ${{ steps.vars.outputs.tags_list }}; do for tag in ${{ steps.vars.outputs.tags_list }}; do
docker tag tempimage:build docker.io/${{ secrets.DOCKERHUB_USERNAME }}/$(basename $GITHUB_REPOSITORY):$tag docker tag tempimage:build docker.io/${{ github.event.inputs.image_name }}:$tag
docker push docker.io/${{ secrets.DOCKERHUB_USERNAME }}/$(basename $GITHUB_REPOSITORY):$tag || echo "Docker Hub push failed for tag $tag" docker push docker.io/${{ github.event.inputs.image_name }}:$tag || echo "Docker Hub push failed for tag $tag"
done done
continue-on-error: true continue-on-error: true
@@ -98,11 +100,9 @@ jobs:
- name: Push to GHCR - name: Push to GHCR
if: ${{ github.event.inputs.push_ghcr == 'true' }} if: ${{ github.event.inputs.push_ghcr == 'true' }}
run: | run: |
docker load < /tmp/buildcache.tar || true
REPO_NAME=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')
for tag in ${{ steps.vars.outputs.tags_list }}; do for tag in ${{ steps.vars.outputs.tags_list }}; do
docker tag tempimage:build ghcr.io/$REPO_NAME:$tag docker tag tempimage:build ghcr.io/${{ github.event.inputs.image_name }}:$tag
docker push ghcr.io/$REPO_NAME:$tag || echo "GHCR push failed for tag $tag" docker push ghcr.io/${{ github.event.inputs.image_name }}:$tag || echo "GHCR push failed for tag $tag"
done done
continue-on-error: true continue-on-error: true
@@ -110,9 +110,8 @@ jobs:
- name: Push to Quay.io - name: Push to Quay.io
if: ${{ github.event.inputs.push_quay == 'true' }} if: ${{ github.event.inputs.push_quay == 'true' }}
run: | run: |
docker load < /tmp/buildcache.tar || true
for tag in ${{ steps.vars.outputs.tags_list }}; do for tag in ${{ steps.vars.outputs.tags_list }}; do
docker tag tempimage:build quay.io/${{ secrets.QUAY_USERNAME }}/$(basename $GITHUB_REPOSITORY):$tag docker tag tempimage:build quay.io/${{ github.event.inputs.image_name }}:$tag
docker push quay.io/${{ secrets.QUAY_USERNAME }}/$(basename $GITHUB_REPOSITORY):$tag || echo "Quay push failed for tag $tag" docker push quay.io/${{ github.event.inputs.image_name }}:$tag || echo "Quay push failed for tag $tag"
done done
continue-on-error: true continue-on-error: true