ci: add Buildkit workflow for multi-image builds
This commit is contained in:
85
.gitea/workflows/build-images.yml
Normal file
85
.gitea/workflows/build-images.yml
Normal file
@@ -0,0 +1,85 @@
|
||||
name: Build and Push Docker Images
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- 'images/**'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
image:
|
||||
description: 'Image to build (e.g., terraform-ci)'
|
||||
required: false
|
||||
|
||||
env:
|
||||
REGISTRY: gitea.arnodo.fr
|
||||
|
||||
jobs:
|
||||
detect-changes:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: alpine/git:latest
|
||||
outputs:
|
||||
matrix: ${{ steps.changes.outputs.matrix }}
|
||||
has_changes: ${{ steps.changes.outputs.has_changes }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- name: Detect changed images
|
||||
id: changes
|
||||
run: |
|
||||
if [ -n "${{ github.event.inputs.image }}" ]; then
|
||||
# Manual trigger - build specific image
|
||||
echo "matrix=[\"${{ github.event.inputs.image }}\"]" >> $GITHUB_OUTPUT
|
||||
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
# Auto-detect changed images
|
||||
CHANGED=$(git diff --name-only HEAD~1 HEAD -- images/ | cut -d'/' -f2 | sort -u | grep -v '^$' || true)
|
||||
if [ -z "$CHANGED" ]; then
|
||||
echo "has_changes=false" >> $GITHUB_OUTPUT
|
||||
echo "matrix=[]" >> $GITHUB_OUTPUT
|
||||
else
|
||||
# Convert to JSON array
|
||||
JSON=$(echo "$CHANGED" | jq -R -s -c 'split("\n") | map(select(length > 0))')
|
||||
echo "matrix=$JSON" >> $GITHUB_OUTPUT
|
||||
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
fi
|
||||
|
||||
build:
|
||||
needs: detect-changes
|
||||
if: needs.detect-changes.outputs.has_changes == 'true'
|
||||
runs-on: docker
|
||||
strategy:
|
||||
matrix:
|
||||
image: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
run: |
|
||||
docker buildx create --use --name gitea-builder || docker buildx use gitea-builder
|
||||
|
||||
- name: Login to Gitea Registry
|
||||
run: |
|
||||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ env.REGISTRY }} -u ${{ gitea.actor }} --password-stdin
|
||||
|
||||
- name: Build and push
|
||||
run: |
|
||||
IMAGE_NAME="${{ env.REGISTRY }}/damien/${{ matrix.image }}"
|
||||
|
||||
docker buildx build \
|
||||
--platform linux/amd64 \
|
||||
--tag "${IMAGE_NAME}:latest" \
|
||||
--tag "${IMAGE_NAME}:${{ gitea.sha }}" \
|
||||
--push \
|
||||
./images/${{ matrix.image }}
|
||||
|
||||
- name: Summary
|
||||
run: |
|
||||
echo "### ✅ Image built and pushed" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Image**: ${{ env.REGISTRY }}/damien/${{ matrix.image }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Tags**: latest, ${{ gitea.sha }}" >> $GITHUB_STEP_SUMMARY
|
||||
Reference in New Issue
Block a user