|
| 1 | +# .github/workflows/release.yml |
| 2 | + |
| 3 | +name: Secure Release Publisher |
| 4 | + |
| 5 | +# This workflow is triggered ONLY when a new release is created in the GitHub UI. |
| 6 | +# This provides a manual gate for production releases. |
| 7 | +on: |
| 8 | + release: |
| 9 | + types: [created] |
| 10 | + |
| 11 | +# CRITICAL: Define the permissions for the job. |
| 12 | +# This enforces the Principle of Least Privilege. The GITHUB_TOKEN will have ONLY these permissions. |
| 13 | +permissions: |
| 14 | + contents: read # Required to check out the repository's code. |
| 15 | + packages: write # Required to publish packages (Docker images) to GHCR. |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-and-publish: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + # 1. Check out the repository code |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + # 2. Log in to the Container Registry |
| 26 | + # --- CHOOSE ONE OF THE FOLLOWING TWO OPTIONS --- |
| 27 | + |
| 28 | + # OPTION A: Log in to GitHub Container Registry (GHCR) |
| 29 | + # This is the most secure and integrated method if using GHCR. |
| 30 | + - name: Log in to GHCR |
| 31 | + uses: docker/login-action@v3 |
| 32 | + with: |
| 33 | + registry: ghcr.io |
| 34 | + username: ${{ github.repository_owner }} |
| 35 | + password: ${{ secrets.GITHUB_TOKEN }} # Use the auto-generated, scoped token |
| 36 | + |
| 37 | + # OPTION B: Log in to Docker Hub |
| 38 | + # Uncomment this step if you are using Docker Hub. |
| 39 | + # - name: Log in to Docker Hub |
| 40 | + # uses: docker/login-action@v3 |
| 41 | + # with: |
| 42 | + # username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 43 | + # password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 44 | + |
| 45 | + # 3. Generate metadata for the Docker image (tags, labels) |
| 46 | + # This action creates tags based on the Git release version (e.g., v1.0.0) |
| 47 | + - name: Extract Docker metadata |
| 48 | + id: meta |
| 49 | + uses: docker/metadata-action@v5 |
| 50 | + with: |
| 51 | + images: | |
| 52 | + # For GHCR, format is ghcr.io/OWNER/REPO_NAME |
| 53 | + ghcr.io/${{ github.repository }} |
| 54 | + # For Docker Hub, format is USERNAME/REPO_NAME |
| 55 | + # kalvinparker/secure-gemini |
| 56 | +
|
| 57 | + # 4. Build and Push the Docker Image |
| 58 | + # This step re-uses our approved, secure Dockerfile. It will run 'npm audit' as a security gate. |
| 59 | + # If the audit fails, this step will fail, and the insecure image will not be published. |
| 60 | + - name: Build and push Docker image |
| 61 | + uses: docker/build-push-action@v5 |
| 62 | + with: |
| 63 | + context: . |
| 64 | + push: true |
| 65 | + tags: ${{ steps.meta.outputs.tags }} |
| 66 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments