Files
docker-swarm-termina/.github/workflows/docker-publish.yml
Claude 0733058349 Improve workflow logging and test dependency
- Add workflow_run trigger to ensure tests pass before building/pushing
- Add test status check to fail early if tests don't pass
- Add pre-build logging steps showing context and tags
- Add step IDs to capture build outputs (digest, metadata)
- Add comprehensive build summary showing digests and tags
- Add GitHub Actions job summary for better UI visibility

This ensures:
1. Untested code is never pushed to GHCR
2. Build progress is clearly visible in logs
3. Final artifacts (digests, tags) are easy to find
4. Workflow status can be quickly assessed from summary

https://claude.ai/code/session_01Kk7x2VdyXfayHqjuw8rqXe
2026-02-01 18:08:50 +00:00

150 lines
5.1 KiB
YAML

name: Build and Push to GHCR
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main
workflow_run:
workflows: ["Run Tests"]
types:
- completed
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME_BACKEND: ${{ github.repository }}-backend
IMAGE_NAME_FRONTEND: ${{ github.repository }}-frontend
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check test workflow status
if: github.event_name == 'workflow_run' && github.event.workflow_run.conclusion != 'success'
run: |
echo "❌ Test workflow failed. Cancelling build and push."
exit 1
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for backend
id: meta-backend
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_BACKEND }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Log backend build information
run: |
echo "=== Building Backend Docker Image ==="
echo "Context: ./backend"
echo "Tags to apply:"
echo "${{ steps.meta-backend.outputs.tags }}" | tr ',' '\n'
echo ""
- name: Build and push backend image
id: build-backend
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: ${{ steps.meta-backend.outputs.tags }}
labels: ${{ steps.meta-backend.outputs.labels }}
outputs: type=registry,push=true
- name: Extract metadata for frontend
id: meta-frontend
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_FRONTEND }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Log frontend build information
run: |
echo "=== Building Frontend Docker Image ==="
echo "Context: ./frontend"
echo "Tags to apply:"
echo "${{ steps.meta-frontend.outputs.tags }}" | tr ',' '\n'
echo "Build args: NEXT_PUBLIC_API_URL=http://backend:5000"
echo ""
- name: Build and push frontend image
id: build-frontend
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: ${{ steps.meta-frontend.outputs.tags }}
labels: ${{ steps.meta-frontend.outputs.labels }}
outputs: type=registry,push=true
build-args: |
NEXT_PUBLIC_API_URL=http://backend:5000
- name: Build summary
run: |
echo "=================================="
echo " Docker Build & Push Complete"
echo "=================================="
echo ""
echo "✅ Backend Image:"
echo " Digest: ${{ steps.build-backend.outputs.digest }}"
echo " Tags:"
echo "${{ steps.meta-backend.outputs.tags }}" | tr ',' '\n' | sed 's/^/ - /'
echo ""
echo "✅ Frontend Image:"
echo " Digest: ${{ steps.build-frontend.outputs.digest }}"
echo " Tags:"
echo "${{ steps.meta-frontend.outputs.tags }}" | tr ',' '\n' | sed 's/^/ - /'
echo ""
echo "📦 Images pushed to: ${{ env.REGISTRY }}"
echo "=================================="
- name: Add job summary
run: |
echo "## 🐳 Docker Build & Push Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Backend Image" >> $GITHUB_STEP_SUMMARY
echo "- **Digest:** \`${{ steps.build-backend.outputs.digest }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Tags:**" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta-backend.outputs.tags }}" | tr ',' '\n' | sed 's/^/ - `/' | sed 's/$/`/' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Frontend Image" >> $GITHUB_STEP_SUMMARY
echo "- **Digest:** \`${{ steps.build-frontend.outputs.digest }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Tags:**" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta-frontend.outputs.tags }}" | tr ',' '\n' | sed 's/^/ - `/' | sed 's/$/`/' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Registry" >> $GITHUB_STEP_SUMMARY
echo "📦 Images pushed to: \`${{ env.REGISTRY }}\`" >> $GITHUB_STEP_SUMMARY