feat: add on-demand image build pipeline to CircleCI#271
feat: add on-demand image build pipeline to CircleCI#271rshoemaker wants to merge 1 commit intomainfrom
Conversation
📝 WalkthroughWalkthroughA new CircleCI parameter Changes
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
.circleci/config.yml (1)
153-169: Missing environment variable validation before use.The
releasejob (lines 110-118) validates thatIMAGE_PUBLISH_TOKENandIMAGE_PUBLISH_USERare set before attempting Docker login. This job uses the same credentials at lines 164-165 but lacks validation, which would produce a confusing error message if the context secrets are missing.Proposed fix to add validation
- run: name: Build and publish image command: | git checkout -- . + if [[ -z "${IMAGE_PUBLISH_TOKEN}" ]]; then + echo "IMAGE_PUBLISH_TOKEN must be set" + exit 1 + fi + if [[ -z "${IMAGE_PUBLISH_USER}" ]]; then + echo "IMAGE_PUBLISH_USER must be set" + exit 1 + fi + short_sha=$(git rev-parse --short HEAD)Note: The
releasejob's validation also lacksexit 1after the error messages—consider fixing that as well for consistent early termination.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.circleci/config.yml around lines 153 - 169, Add explicit checks for IMAGE_PUBLISH_TOKEN and IMAGE_PUBLISH_USER before using them in the "Build and publish image" run step: test that both environment variables are set and if not print a clear error and exit 1 prior to the docker login and image publish commands; mirror the validation pattern used in the release job (but ensure you include the missing exit 1 there as well) so that the docker login line that pipes "${IMAGE_PUBLISH_TOKEN}" into docker is only executed when IMAGE_PUBLISH_TOKEN and IMAGE_PUBLISH_USER are present.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.circleci/config.yml:
- Around line 148-152: The CI step named "Checkout build ref and rebuild deps"
uses git checkout << pipeline.parameters.build_ref >> which fails for
remote-only refs; update that step to run an explicit git fetch of the provided
pipeline.parameters.build_ref (fetch the remote ref from origin, e.g. fetch
refs/heads/... or origin/<build_ref> into FETCH_HEAD or a temporary branch)
before attempting checkout, then checkout the fetched ref (keeping the existing
go mod download afterwards) so remote branch names and other ref types work
reliably.
---
Nitpick comments:
In @.circleci/config.yml:
- Around line 153-169: Add explicit checks for IMAGE_PUBLISH_TOKEN and
IMAGE_PUBLISH_USER before using them in the "Build and publish image" run step:
test that both environment variables are set and if not print a clear error and
exit 1 prior to the docker login and image publish commands; mirror the
validation pattern used in the release job (but ensure you include the missing
exit 1 there as well) so that the docker login line that pipes
"${IMAGE_PUBLISH_TOKEN}" into docker is only executed when IMAGE_PUBLISH_TOKEN
and IMAGE_PUBLISH_USER are present.
Summary
build_imagejob to CircleCI that builds and pushes a control-plane Docker image from any git ref (commit SHA, branch, or tag)v0.0.0-<short-sha>and pushed to GHCRcircleci pipeline trigger --parameter build_ref=<ref>goreleaser-buildandcontrol-plane-imagesMakefile targetstestworkflow withunlessso it doesn't run during image buildsHow to Use
Pre-requisites: install CircleCI CLI (
brew install circleci) and authenticate viacircleci setupwhich will install the required token.By branch name:
By commit SHA:
Both produce an image tagged
v0.0.0-<short-sha>. The branch field tells CircleCI where to read the config from; build_ref is what actually gets checked out and built.Test plan
build_refset to a branch namebuild_refset to a commit SHAPLAT-431