mirror of
https://github.com/driftywinds/image-builder.git
synced 2025-12-19 03:43:33 +00:00
192 lines
6.3 KiB
YAML
192 lines
6.3 KiB
YAML
name: Multi-Registry Docker Build and Push
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
repo_url:
|
|
description: 'Repository URL to clone'
|
|
required: true
|
|
type: string
|
|
default: 'https://git.lolcat.ca/lolcat/4get'
|
|
|
|
image_name:
|
|
description: 'Docker image name (without registry prefix)'
|
|
required: true
|
|
type: string
|
|
default: 'user/image'
|
|
|
|
tags:
|
|
description: 'Comma-separated list of tags'
|
|
required: true
|
|
type: string
|
|
default: 'latest'
|
|
|
|
push_to_dockerhub:
|
|
description: 'Push to Docker Hub'
|
|
required: true
|
|
type: boolean
|
|
default: true
|
|
|
|
push_to_ghcr:
|
|
description: 'Push to GitHub Container Registry'
|
|
required: true
|
|
type: boolean
|
|
default: true
|
|
|
|
push_to_quay:
|
|
description: 'Push to Quay.io'
|
|
required: true
|
|
type: boolean
|
|
default: true
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout workflow repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Clone target repository
|
|
run: |
|
|
git clone ${{ inputs.repo_url }} ./target-repo
|
|
cd ./target-repo
|
|
echo "REPO_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
|
|
echo "REPO_SHORT_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Docker Hub
|
|
if: inputs.push_to_dockerhub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Log in to GitHub Container Registry
|
|
if: inputs.push_to_ghcr
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
- name: Log in to Quay.io
|
|
if: inputs.push_to_quay
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: quay.io
|
|
username: ${{ secrets.QUAY_USERNAME }}
|
|
password: ${{ secrets.QUAY_PASSWORD }}
|
|
|
|
- name: Generate metadata
|
|
id: meta
|
|
run: |
|
|
# Parse comma-separated tags
|
|
IFS=',' read -ra TAG_ARRAY <<< "${{ inputs.tags }}"
|
|
|
|
# Initialize arrays for different registries
|
|
DOCKERHUB_TAGS=""
|
|
GHCR_TAGS=""
|
|
QUAY_TAGS=""
|
|
|
|
# Generate tags for each registry
|
|
for tag in "${TAG_ARRAY[@]}"; do
|
|
# Trim whitespace
|
|
tag=$(echo "$tag" | xargs)
|
|
|
|
if [[ "${{ inputs.push_to_dockerhub }}" == "true" ]]; then
|
|
if [[ -n "$DOCKERHUB_TAGS" ]]; then
|
|
DOCKERHUB_TAGS="$DOCKERHUB_TAGS,"
|
|
fi
|
|
DOCKERHUB_TAGS="$DOCKERHUB_TAGS${{ inputs.image_name }}:$tag"
|
|
fi
|
|
|
|
if [[ "${{ inputs.push_to_ghcr }}" == "true" ]]; then
|
|
if [[ -n "$GHCR_TAGS" ]]; then
|
|
GHCR_TAGS="$GHCR_TAGS,"
|
|
fi
|
|
GHCR_TAGS="$GHCR_TAGS ghcr.io/${{ github.repository_owner }}/${{ inputs.image_name }}:$tag"
|
|
fi
|
|
|
|
if [[ "${{ inputs.push_to_quay }}" == "true" ]]; then
|
|
if [[ -n "$QUAY_TAGS" ]]; then
|
|
QUAY_TAGS="$QUAY_TAGS,"
|
|
fi
|
|
QUAY_TAGS="$QUAY_TAGS quay.io/${{ inputs.image_name }}:$tag"
|
|
fi
|
|
done
|
|
|
|
# Combine all tags
|
|
ALL_TAGS=""
|
|
if [[ -n "$DOCKERHUB_TAGS" ]]; then
|
|
ALL_TAGS="$DOCKERHUB_TAGS"
|
|
fi
|
|
if [[ -n "$GHCR_TAGS" ]]; then
|
|
if [[ -n "$ALL_TAGS" ]]; then
|
|
ALL_TAGS="$ALL_TAGS,$GHCR_TAGS"
|
|
else
|
|
ALL_TAGS="$GHCR_TAGS"
|
|
fi
|
|
fi
|
|
if [[ -n "$QUAY_TAGS" ]]; then
|
|
if [[ -n "$ALL_TAGS" ]]; then
|
|
ALL_TAGS="$ALL_TAGS,$QUAY_TAGS"
|
|
else
|
|
ALL_TAGS="$QUAY_TAGS"
|
|
fi
|
|
fi
|
|
|
|
echo "tags=$ALL_TAGS" >> $GITHUB_OUTPUT
|
|
echo "Generated tags: $ALL_TAGS"
|
|
|
|
- name: Build and push Docker images
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./target-repo
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: |
|
|
org.opencontainers.image.title=${{ inputs.image_name }}
|
|
org.opencontainers.image.description=Built from ${{ inputs.repo_url }}
|
|
org.opencontainers.image.url=${{ inputs.repo_url }}
|
|
org.opencontainers.image.source=${{ inputs.repo_url }}
|
|
org.opencontainers.image.revision=${{ env.REPO_COMMIT }}
|
|
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Summary
|
|
run: |
|
|
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Repository:** ${{ inputs.repo_url }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Commit:** ${{ env.REPO_SHORT_COMMIT }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Image Name:** ${{ inputs.image_name }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Tags:** ${{ inputs.tags }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "### Registries:" >> $GITHUB_STEP_SUMMARY
|
|
|
|
if [[ "${{ inputs.push_to_dockerhub }}" == "true" ]]; then
|
|
echo "- ✅ Docker Hub" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "- ❌ Docker Hub" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
|
|
if [[ "${{ inputs.push_to_ghcr }}" == "true" ]]; then
|
|
echo "- ✅ GitHub Container Registry" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "- ❌ GitHub Container Registry" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
|
|
if [[ "${{ inputs.push_to_quay }}" == "true" ]]; then
|
|
echo "- ✅ Quay.io" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "- ❌ Quay.io" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "### Built Tags:" >> $GITHUB_STEP_SUMMARY
|
|
echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n' | sed 's/^/- /' >> $GITHUB_STEP_SUMMARY
|