Refactor Dockerfile comments and user setup #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
| name: Build and Publish to GHCR | |
| # 1. Trigger the workflow on push to main branch | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| workflow_dispatch: # Allows you to run this manually from the Actions tab | |
| env: | |
| REGISTRY: ghcr.io | |
| # github.repository returns "owner/repo" (e.g., "yourname/sam3-project") | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| # 2. Permissions required to write to GHCR | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # 3. Set up Docker Buildx (Critical for caching and platform support) | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # 4. Log in to the Container registry | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # 5. Extract metadata (tags, labels) for Docker | |
| # This automatically tags the image as 'latest' on main branch push | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=sha,prefix=sha- | |
| # 6. Build and push Docker image | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| # FORCE linux/amd64 to ensure NVIDIA compatibility | |
| platforms: linux/amd64 | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| # 7. Enable caching to speed up future builds | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |