Build and Push Docker Image #30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Docker Image | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to build (e.g., v1.0.4)' | |
| required: true | |
| type: string | |
| force_rebuild: | |
| description: 'Force rebuild (ignore cache)' | |
| required: false | |
| type: boolean | |
| default: false | |
| env: | |
| REGISTRY: ghcr.io | |
| jobs: | |
| info: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| image_name: ${{ steps.meta.outputs.image_name }} | |
| version: ${{ steps.meta.outputs.version }} | |
| ref: ${{ steps.meta.outputs.ref }} | |
| steps: | |
| - name: Show build info | |
| id: meta | |
| run: | | |
| IMAGE_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') | |
| # Determine version and git ref | |
| if [ -n "${{ github.event.inputs.version }}" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| REF="${{ github.event.inputs.version }}" | |
| TRIGGER="Manual (workflow_dispatch)" | |
| else | |
| VERSION="${{ github.ref_name }}" | |
| REF="${{ github.ref }}" | |
| TRIGGER="Tag push" | |
| fi | |
| echo "🚀 Docker Build Starting" | |
| echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" | |
| echo "📦 Repository: ${{ github.repository }}" | |
| echo "🏷️ Version: $VERSION" | |
| echo "🎯 Trigger: $TRIGGER" | |
| echo "🐳 Registry: ${{ env.REGISTRY }}" | |
| echo "" | |
| echo "📋 Will be tagged as:" | |
| echo " • ${{ env.REGISTRY }}/$IMAGE_NAME:$VERSION" | |
| echo " • ${{ env.REGISTRY }}/$IMAGE_NAME:latest" | |
| echo "" | |
| echo "🏗️ Platforms: linux/amd64, linux/arm64" | |
| echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" | |
| echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "ref=$REF" >> $GITHUB_OUTPUT | |
| build-amd64: | |
| needs: info | |
| uses: ./.github/workflows/build-platform.yml | |
| with: | |
| platform: 'linux/amd64' | |
| image_name: ${{ needs.info.outputs.image_name }} | |
| version: ${{ needs.info.outputs.version }} | |
| ref: ${{ needs.info.outputs.ref }} | |
| no_cache: ${{ inputs.force_rebuild || false }} | |
| build-arm64: | |
| needs: info | |
| uses: ./.github/workflows/build-platform.yml | |
| with: | |
| platform: 'linux/arm64' | |
| image_name: ${{ needs.info.outputs.image_name }} | |
| version: ${{ needs.info.outputs.version }} | |
| ref: ${{ needs.info.outputs.ref }} | |
| no_cache: ${{ inputs.force_rebuild || false }} | |
| create-manifest: | |
| needs: [info, build-amd64, build-arm64] | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create and push multi-arch manifest | |
| run: | | |
| # Create manifest for version tag | |
| docker buildx imagetools create \ | |
| -t ${{ env.REGISTRY }}/${{ needs.info.outputs.image_name }}:${{ needs.info.outputs.version }} \ | |
| ${{ env.REGISTRY }}/${{ needs.info.outputs.image_name }}:${{ needs.info.outputs.version }}-amd64 \ | |
| ${{ env.REGISTRY }}/${{ needs.info.outputs.image_name }}:${{ needs.info.outputs.version }}-arm64 | |
| # Create manifest for latest tag | |
| docker buildx imagetools create \ | |
| -t ${{ env.REGISTRY }}/${{ needs.info.outputs.image_name }}:latest \ | |
| ${{ env.REGISTRY }}/${{ needs.info.outputs.image_name }}:${{ needs.info.outputs.version }}-amd64 \ | |
| ${{ env.REGISTRY }}/${{ needs.info.outputs.image_name }}:${{ needs.info.outputs.version }}-arm64 | |
| - name: Summary | |
| run: | | |
| echo "## 🚀 Docker Image Built Successfully!" >> $GITHUB_STEP_SUMMARY | |
| echo "**Image:** \`${{ env.REGISTRY }}/${{ needs.info.outputs.image_name }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "**Version:** \`${{ needs.info.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "**Tags:** \`${{ needs.info.outputs.version }}\`, \`latest\`" >> $GITHUB_STEP_SUMMARY | |
| echo "**Platforms:** linux/amd64, linux/arm64" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Pull:**" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| echo "docker pull ${{ env.REGISTRY }}/${{ needs.info.outputs.image_name }}:${{ needs.info.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |