Skip to content

ci(docker): skip Docker Hub login/push when credentials are absent - #359

Merged
jo-duchan merged 1 commit into
mainfrom
fix/docker-publish-skip-without-secrets
Jul 2, 2026
Merged

jo-duchan merged 1 commit into
mainfrom
fix/docker-publish-skip-without-secrets

Conversation

@jo-duchan

@jo-duchan jo-duchan commented Jul 2, 2026 •

Copy link
Copy Markdown
Owner

Problem

The Docker Publish workflow (added in #352) fails on every push to main — and would fail on release tags too — at the Log in to Docker Hub step:

##[error]Username and password required

Root cause: DOCKERHUB_USERNAME / DOCKERHUB_TOKEN repository secrets are not configured, so docker/login-action@v3 receives 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.yml is a separate workflow using OIDC), but it produces a red X on main and on every vX.Y.Z tag push.

Fix

Gate Docker Hub login and push on a HAS_DOCKERHUB job-level flag derived from the secrets:

  • No secrets → build the image for validation, skip login and push, emit a ::warning::. No failure.
  • Secrets present → unchanged behavior: login + multi-arch build + push. No extra config needed once secrets are added.
  • Pull requests → unchanged: build only, never push.

Verification

  • YAML parses cleanly; job-level env referencing secrets and step if referencing env is a documented GitHub Actions pattern.
  • pre-commit typecheck + lint pass.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Improved Docker publishing automation to better handle missing registry credentials.
    • Added a clear warning when a publish is expected but credentials are not available.
    • Docker images are now only pushed when publishing is possible; otherwise, the workflow performs a build-only run.

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]>
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
tapflow-docs Ignored Ignored Jul 2, 2026 3:23pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The GitHub Actions Docker publish workflow now derives a HAS_DOCKERHUB environment flag from the presence of Docker Hub secrets, warns when credentials are missing outside pull requests, gates the Docker Hub login step on this flag, and updates the build/push step to push only when not a pull request and credentials are present.

Changes

Docker Hub Credential Gating

Layer / File(s) Summary
Credential flag, warning, and conditional login/push
.github/workflows/docker-publish.yml
Adds HAS_DOCKERHUB env flag based on secret presence, adds a warning step for missing credentials outside pull requests, gates the login step on the flag, and updates the build/push action's push condition to require the flag.

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)
Check name Status Explanation
Title check ✅ Passed It clearly summarizes the main workflow change: skipping Docker Hub login and push when credentials are missing.
Description check ✅ Passed It explains the problem, fix, and verification, though it doesn't follow the template headings exactly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/docker-publish-skip-without-secrets

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
.github/workflows/docker-publish.yml (2)

19-22: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Missing persist-credentials: false on checkout (ArtiPACKED).

actions/checkout@v4 defaults to persisting GITHUB_TOKEN in .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's artipacked check.

🔒 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 value

Duplicated 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 single SHOULD_PUBLISH env flag alongside HAS_DOCKERHUB to 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

📥 Commits

Reviewing files that changed from the base of the PR and between 8571942 and 36c3eb6.

📒 Files selected for processing (1)
  • .github/workflows/docker-publish.yml

@jo-duchan
jo-duchan merged commit 2c73885 into main Jul 2, 2026
3 checks passed
@jo-duchan
jo-duchan deleted the fix/docker-publish-skip-without-secrets branch July 2, 2026 15:33
@coderabbitai coderabbitai Bot mentioned this pull request Aug 15, 2026
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant