|
| 1 | +name: Docker Build and Push |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + packages: write |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: [main, master] |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + push_to_registry: |
| 13 | + description: "Push to Docker registry" |
| 14 | + required: false |
| 15 | + default: true |
| 16 | + type: boolean |
| 17 | + |
| 18 | +env: |
| 19 | + DOCKER_IMAGE: ${{ vars.DOCKERHUB_USERNAME || 'defaultuser' }}/fullstack-agent |
| 20 | + REGISTRY_GHCR: ghcr.io |
| 21 | + |
| 22 | +jobs: |
| 23 | + build-and-push: |
| 24 | + name: Build and Push Docker Image |
| 25 | + runs-on: ubuntu-latest |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout code |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Set up QEMU |
| 32 | + uses: docker/setup-qemu-action@v3 |
| 33 | + |
| 34 | + - name: Set up Docker Buildx |
| 35 | + uses: docker/setup-buildx-action@v3 |
| 36 | + |
| 37 | + - name: Login to Docker Hub |
| 38 | + if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_to_registry) |
| 39 | + uses: docker/login-action@v3 |
| 40 | + with: |
| 41 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
| 42 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 43 | + |
| 44 | + - name: Login to GitHub Container Registry |
| 45 | + if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_to_registry) |
| 46 | + uses: docker/login-action@v3 |
| 47 | + with: |
| 48 | + registry: ${{ env.REGISTRY_GHCR }} |
| 49 | + username: ${{ github.actor }} |
| 50 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + |
| 52 | + - name: Extract metadata |
| 53 | + id: meta |
| 54 | + uses: docker/metadata-action@v5 |
| 55 | + with: |
| 56 | + images: | |
| 57 | + ${{ env.DOCKER_IMAGE }} |
| 58 | + ${{ env.REGISTRY_GHCR }}/${{ github.repository }} |
| 59 | + tags: | |
| 60 | + type=ref,event=branch |
| 61 | + type=sha,prefix=sha- |
| 62 | + type=semver,pattern={{version}} |
| 63 | + type=semver,pattern={{major}}.{{minor}} |
| 64 | + type=raw,value=latest,enable={{is_default_branch}} |
| 65 | + labels: | |
| 66 | + org.opencontainers.image.title=FullStack Agent |
| 67 | + org.opencontainers.image.description=Full Stack Development Agent |
| 68 | + org.opencontainers.image.vendor=${{ github.repository_owner }} |
| 69 | +
|
| 70 | + - name: Build and push multi-platform image |
| 71 | + uses: docker/build-push-action@v6 |
| 72 | + with: |
| 73 | + context: . |
| 74 | + file: ./Dockerfile |
| 75 | + platforms: linux/amd64,linux/arm64 |
| 76 | + push: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_to_registry) }} |
| 77 | + tags: ${{ steps.meta.outputs.tags }} |
| 78 | + labels: ${{ steps.meta.outputs.labels }} |
| 79 | + cache-from: | |
| 80 | + type=gha,scope=build-amd64 |
| 81 | + type=gha,scope=build-arm64 |
| 82 | + cache-to: type=gha,mode=max,scope=build-multiplatform |
| 83 | + provenance: true |
| 84 | + sbom: true |
| 85 | + |
| 86 | + - name: Generate build summary |
| 87 | + if: always() |
| 88 | + run: | |
| 89 | + echo "## 🚀 Docker Build & Push Report" >> $GITHUB_STEP_SUMMARY |
| 90 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 91 | + echo "### Build Status" >> $GITHUB_STEP_SUMMARY |
| 92 | + if [ "${{ job.status }}" = "success" ]; then |
| 93 | + echo "- ✅ Multi-platform build successful" >> $GITHUB_STEP_SUMMARY |
| 94 | + echo "- ✅ Platforms: \`linux/amd64\`, \`linux/arm64\`" >> $GITHUB_STEP_SUMMARY |
| 95 | + if [ "${{ github.event_name }}" = "push" ] || [ "${{ inputs.push_to_registry }}" = "true" ]; then |
| 96 | + echo "- ✅ Pushed to Docker Hub: \`${{ env.DOCKER_IMAGE }}\`" >> $GITHUB_STEP_SUMMARY |
| 97 | + echo "- ✅ Pushed to GHCR: \`${{ env.REGISTRY_GHCR }}/${{ github.repository }}\`" >> $GITHUB_STEP_SUMMARY |
| 98 | + fi |
| 99 | + else |
| 100 | + echo "- ❌ Build failed" >> $GITHUB_STEP_SUMMARY |
| 101 | + fi |
| 102 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 103 | + echo "### Build Information" >> $GITHUB_STEP_SUMMARY |
| 104 | + echo "- **Commit SHA**: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY |
| 105 | + echo "- **Branch**: \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY |
| 106 | + echo "- **Triggered by**: @${{ github.actor }}" >> $GITHUB_STEP_SUMMARY |
| 107 | + echo "- **Event**: \`${{ github.event_name }}\`" >> $GITHUB_STEP_SUMMARY |
| 108 | + echo "- **Build time**: $(date '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY |
| 109 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 110 | + echo "### Image Tags" >> $GITHUB_STEP_SUMMARY |
| 111 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 112 | + echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY |
| 113 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 114 | +
|
| 115 | + - name: Test image (quick smoke test) |
| 116 | + if: success() |
| 117 | + run: | |
| 118 | + echo "### 🧪 Image Test" >> $GITHUB_STEP_SUMMARY |
| 119 | + echo "Running quick smoke test on built image..." >> $GITHUB_STEP_SUMMARY |
| 120 | + # Pull the image we just built (from cache/local) |
| 121 | + docker images | head -n 5 |
| 122 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 123 | + echo "- ✅ Image built successfully and available locally" >> $GITHUB_STEP_SUMMARY |
0 commit comments