Interview Prep/CI/CD/GitHub Actions

A workflow builds a Docker image and pushes to GHCR. Show a secure setup.

IntermediateScenarioGitHub Actions
Answer

Situation read → Image build with minimal credentials.

What I'd do →

permissions: { contents: read, packages: write }
steps:
  - uses: actions/checkout@v4
  - uses: docker/setup-buildx-action@v3
  - uses: docker/login-action@v3
    with: { registry: ghcr.io, username: "${{ github.actor }}", password: "${{ secrets.GITHUB_TOKEN }}" }
  - uses: docker/build-push-action@v6
    with:
      push: true
      tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
      cache-from: type=gha
      cache-to: type=gha,mode=max

Why → GITHUB_TOKEN expires with the job, and the gha cache speeds up layers.

Interview tip → Tag with the commit SHA; add a moving tag only for convenience.

All CI/CD questions

More on GitHub Actions