Merge pull request #1 from alihaidar0/dependabot/github_actions/main/… #3
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
| # ============================================================ | |
| # .github/workflows/docker.yml | |
| # | |
| # Builds the Django dev container image and pushes to Docker Hub. | |
| # Cross-platform: linux/amd64 (Windows/Linux) + linux/arm64 (Apple Silicon) | |
| # | |
| # Triggers: | |
| # - Push to main → builds + pushes :latest + :sha-xxx | |
| # - PR targeting main → builds only (no push) — validates Dockerfile | |
| # - Manual dispatch → optional push, optional force rebuild | |
| # | |
| # Required GitHub Secrets: | |
| # DOCKERHUB_USERNAME Docker Hub username | |
| # DOCKERHUB_TOKEN Docker Hub access token (Read/Write) | |
| # | |
| # Platforms: | |
| # linux/amd64 — Windows / Linux / GCP | |
| # linux/arm64 — Apple Silicon Macs | |
| # ============================================================ | |
| name: Docker | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "docker/Dockerfile.dev" | |
| - "scripts/**" | |
| - ".github/workflows/docker.yml" | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - "docker/Dockerfile.dev" | |
| - "scripts/**" | |
| - ".github/workflows/docker.yml" | |
| workflow_dispatch: | |
| inputs: | |
| push_image: | |
| description: "Push image to Docker Hub?" | |
| required: true | |
| default: "true" | |
| type: choice | |
| options: | |
| - "true" | |
| - "false" | |
| force_rebuild: | |
| description: "Bypass layer cache (full rebuild)" | |
| required: false | |
| type: boolean | |
| default: false | |
| concurrency: | |
| group: docker-${{ github.ref }} | |
| cancel-in-progress: false | |
| env: | |
| IMAGE_NAME: alihaidar199527/django-devcontainer | |
| jobs: | |
| build-and-push: | |
| name: Build & Push Dev Image | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Log in to Docker Hub | |
| # Skip login on PR builds — we are not pushing, no credentials needed | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract image metadata | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} | |
| type=sha,prefix=sha-,format=short | |
| - name: Build and push | |
| id: build | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| file: docker/Dockerfile.dev | |
| platforms: linux/amd64,linux/arm64 | |
| # Push only on a real push to main or an approved manual dispatch | |
| # PR builds compile the image to validate it but never push | |
| push: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_image == 'true') }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| no-cache: ${{ inputs.force_rebuild == true }} | |
| provenance: true | |
| sbom: true | |
| - name: Write job summary | |
| if: always() | |
| run: | | |
| echo "## 🐳 Docker Build Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY | |
| echo "|-------|-------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| **Image** | \`${{ env.IMAGE_NAME }}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| **Digest** | \`${{ steps.build.outputs.digest }}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| **Tags** | \`${{ steps.meta.outputs.tags }}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| **Platforms** | \`linux/amd64, linux/arm64\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| **Triggered by** | \`${{ github.event_name }}\` on \`${{ github.ref_name }}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| **Commit** | \`${{ github.sha }}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| **Pushed to Docker Hub** | \`${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.push_image == 'true') }}\` |" >> $GITHUB_STEP_SUMMARY |