Design a GitHub Actions workflow that builds, scans and pushes an image.
IntermediateScenarioCI/CD and production rollouts
Answer
Situation read → Standard CI for containers.
What I'd do →
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: false
load: true
tags: ghcr.io/acme/app:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- run: trivy image --exit-code 1 --severity CRITICAL ghcr.io/acme/app:${{ github.sha }}
- run: docker push ghcr.io/acme/app:${{ github.sha }}
Why → Scan before push so bad images never reach the registry.
Interview tip → Pin actions by SHA in sensitive repos.
More on CI/CD and production rollouts
Zero-downtime deploy on a single Docker host.AdvancedDeploy via GitOps with image digests.IntermediateCanary a new image on a Swarm service.AdvancedDocker build is flaky in CI due to network errors on package installs.IntermediateRun database migrations in the deploy flow of containerized apps.IntermediateHow do you keep dev, CI and prod consistent?Beginner