Repository navigation
ci(docker): skip Docker Hub login/push when credentials are absent - #359
Conversation
The Docker Publish workflow failed on every push to main (and would fail on release tags) at the login step with "Username and password required" because DOCKERHUB_USERNAME/DOCKERHUB_TOKEN are not configured. Gate login and push on a HAS_DOCKERHUB flag so the image is still built for validation but only pushed when credentials exist; emit a warning when they are missing. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
📝 WalkthroughWalkthroughThe GitHub Actions Docker publish workflow now derives a ChangesDocker Hub Credential Gating
Estimated code review effort: 1 (Trivial) | ~5 minutes Sequence Diagram(s)Not applicable — this is a CI configuration change without multi-component runtime interactions. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
.github/workflows/docker-publish.yml (2)
19-22: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winMissing
persist-credentials: falseon checkout (ArtiPACKED).
actions/checkout@v4defaults to persistingGITHUB_TOKENin.git/config, which remains accessible to every subsequent step (QEMU, Buildx, Docker login/build-push) for the rest of the job. Since this job doesn't push commits back to the repo, disabling persistence removes an unnecessary credential-exposure surface flagged by zizmor'sartipackedcheck.🔒 Proposed fix
- name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 + persist-credentials: false🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/docker-publish.yml around lines 19 - 22, The Checkout repository step in the workflow is leaving the default GitHub token persisted in the local git config, which expands credential exposure for later steps. Update the actions/checkout@v4 usage in the docker-publish job to disable credential persistence by setting persist-credentials to false alongside the existing fetch-depth setting.Source: Linters/SAST tools
34-57: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDuplicated publish guard between login and push steps.
The expression
github.event_name != 'pull_request' && env.HAS_DOCKERHUB == 'true'is repeated verbatim at line 35 and line 57. Consider deriving a singleSHOULD_PUBLISHenv flag alongsideHAS_DOCKERHUBto avoid the two conditions drifting apart if one is edited later.♻️ Proposed refactor
env: HAS_DOCKERHUB: ${{ secrets.DOCKERHUB_TOKEN != '' && secrets.DOCKERHUB_USERNAME != '' }} + SHOULD_PUBLISH: ${{ github.event_name != 'pull_request' && secrets.DOCKERHUB_TOKEN != '' && secrets.DOCKERHUB_USERNAME != '' }}- name: Log in to Docker Hub - if: github.event_name != 'pull_request' && env.HAS_DOCKERHUB == 'true' + if: env.SHOULD_PUBLISH == 'true'- push: ${{ github.event_name != 'pull_request' && env.HAS_DOCKERHUB == 'true' }} + push: ${{ env.SHOULD_PUBLISH == 'true' }}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/docker-publish.yml around lines 34 - 57, The Docker publish condition is duplicated between the login and build/push steps, which can drift over time. Introduce a single publish flag in this workflow, alongside HAS_DOCKERHUB, and use it for both docker/login-action and docker/build-push-action. Update the if/push expressions in docker-publish.yml so the shared condition is defined once and referenced consistently in the metadata/login/build steps.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In @.github/workflows/docker-publish.yml:
- Around line 19-22: The Checkout repository step in the workflow is leaving the
default GitHub token persisted in the local git config, which expands credential
exposure for later steps. Update the actions/checkout@v4 usage in the
docker-publish job to disable credential persistence by setting
persist-credentials to false alongside the existing fetch-depth setting.
- Around line 34-57: The Docker publish condition is duplicated between the
login and build/push steps, which can drift over time. Introduce a single
publish flag in this workflow, alongside HAS_DOCKERHUB, and use it for both
docker/login-action and docker/build-push-action. Update the if/push expressions
in docker-publish.yml so the shared condition is defined once and referenced
consistently in the metadata/login/build steps.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ddc39de2-807d-442f-8c6f-c08b68c2b7ea
📒 Files selected for processing (1)
.github/workflows/docker-publish.yml
Problem
The Docker Publish workflow (added in #352) fails on every push to
main— and would fail on release tags too — at theLog in to Docker Hubstep:Root cause:
DOCKERHUB_USERNAME/DOCKERHUB_TOKENrepository secrets are not configured, sodocker/login-action@v3receives empty credentials. The step ran unconditionally on non-PR events, so it hard-failed. (PR events skipped it, which is why it wasn't caught in review.)This does not affect the npm release (
release.ymlis a separate workflow using OIDC), but it produces a red X onmainand on everyvX.Y.Ztag push.Fix
Gate Docker Hub login and push on a
HAS_DOCKERHUBjob-level flag derived from the secrets:::warning::. No failure.Verification
envreferencingsecretsand stepifreferencingenvis a documented GitHub Actions pattern.🤖 Generated with Claude Code
Summary by CodeRabbit