ci(docker): fix image resolution for pull requests - #322
Conversation
📝 WalkthroughWalkthroughThe CI workflow's "set-image" step is updated to use a more robust approach for determining container image tags. It replaces curl-based manifest checking with GitHub CLI API queries, restructures variable setup, and refines the image selection fallback logic for GHCR and Docker Hub. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
/docker-build 096bed |
Previously always fell back to main
b096bed to
e010a1e
Compare
|
/docker-build e010a1e |
🐳 Docker image built successfully!Image
Run it locally:IMG2NUM_IMAGE=ghcr.io/ryan-millard/img2num-dev:pr-322 ./img2num sh |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.github/workflows/ci.yml (1)
20-34:⚠️ Potential issue | 🔴 CriticalAdd pagination to the GHCR package lookup.
Package versions from the GitHub Container Registry API are paginated. Without
--paginateor explicitper_pagehandling, the lookup checks only the first page of results and can miss olderpr-*tags, incorrectly falling back tomain.🔧 Proposed fix
GHCR_IMAGE_EXISTS=$(gh api --paginate \ -H "Accept: application/vnd.github+json" \ - /users/ryan-millard/packages/container/img2num-dev/versions \ - --jq "any(.metadata.container.tags[]? == \"${PR_TAG}\")") + "/users/ryan-millard/packages/container/img2num-dev/versions?per_page=100" \ + --jq ".[] | select(.metadata.container.tags[]? == \"${PR_TAG}\") | .id" | wc -l) + + if [[ "$GHCR_IMAGE_EXISTS" -gt 0 ]]; then + GHCR_IMAGE_EXISTS="true" + else + GHCR_IMAGE_EXISTS="false" + fi🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/ci.yml around lines 20 - 34, The GHCR lookup using the gh api call that sets GHCR_IMAGE_EXISTS only checks the first page and can miss PR_TAG; update the gh api invocation that computes GHCR_IMAGE_EXISTS to include pagination (e.g., add the --paginate flag or use per_page and iterate) so the API searches all pages for any(.metadata.container.tags[]? == "${PR_TAG}"), ensuring the variable GHCR_IMAGE_EXISTS properly detects existing pr-<number> tags instead of falling back to MAIN_IMAGE.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/ci.yml:
- Around line 36-37: Wrap the Docker Hub check so it only runs when
GHCR_IMAGE_EXISTS is not true (i.e., guard the curl that sets DH_STATUS) and add
connection/request timeouts and basic error handling: use curl options like
--connect-timeout and --max-time to avoid hangs and if curl fails set DH_STATUS
to a non-200 sentinel (e.g., 000) or handle the non-zero exit code so the
workflow can continue when GHCR_IMAGE_EXISTS=true; update references to
DH_STATUS and the curl invocation accordingly to implement this conditional
behavior and timeout protection.
---
Outside diff comments:
In @.github/workflows/ci.yml:
- Around line 20-34: The GHCR lookup using the gh api call that sets
GHCR_IMAGE_EXISTS only checks the first page and can miss PR_TAG; update the gh
api invocation that computes GHCR_IMAGE_EXISTS to include pagination (e.g., add
the --paginate flag or use per_page and iterate) so the API searches all pages
for any(.metadata.container.tags[]? == "${PR_TAG}"), ensuring the variable
GHCR_IMAGE_EXISTS properly detects existing pr-<number> tags instead of falling
back to MAIN_IMAGE.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
|
nice! |
|
/docker-build 315790e |
Previously the Docker image being used by CI always fell back to
main. This is a problem if the PR edited the Dockerfile.Important
This does not affect the first time opening the PR - a maintainer must still approve the build of the image before it can be used in CI.
What was changed & why
Fixes the image resolution bug in
ci.ymlfor PRs.Fixes: #none - see this comment on #307.
Changes
ci.yml'sset-imagejobTesting & Verification
Additional Resources
See the workflow run
Summary by CodeRabbit