Skip to content

ci(docker): fix image resolution for pull requests - #322

Merged
Ryan-Millard merged 3 commits into
mainfrom
fix/ci/docker-image-resolution
Apr 22, 2026
Merged

ci(docker): fix image resolution for pull requests#322
Ryan-Millard merged 3 commits into
mainfrom
fix/ci/docker-image-resolution

Conversation

@Ryan-Millard

@Ryan-Millard Ryan-Millard commented Apr 22, 2026

Copy link
Copy Markdown
Owner

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.yml for PRs.

Fixes: #none - see this comment on #307.

Changes

  • ci.yml's set-image job

Testing & Verification

Additional Resources

See the workflow run

image

Summary by CodeRabbit

  • Chores
    • Enhanced CI pipeline container image detection logic to provide more robust and reliable handling across deployment scenarios.

@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
CI Image Selection Logic
.github/workflows/ci.yml
Replaces curl-based GHCR manifest check with guarded PR number extraction and gh api GitHub container package queries. Restructures variable initialization and updates image selection priority to check GHCR first, then Docker Hub, with main image fallback.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

ci

Poem

🐰 In workflows of build, we hop with delight,
API queries shine where curl's checks held tight,
From GHCR to Hub, we pick with finesse,
Each image selected with robust success!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'ci(docker): fix image resolution for pull requests' accurately reflects the main change in the pull request, which updates CI configuration to fix image resolution for PR builds.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ci/docker-image-resolution

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.

❤️ Share

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

@Ryan-Millard

Copy link
Copy Markdown
Owner Author

/docker-build 096bed

  Previously always fell back to main
@Ryan-Millard
Ryan-Millard force-pushed the fix/ci/docker-image-resolution branch from b096bed to e010a1e Compare April 22, 2026 21:09
@Ryan-Millard

Copy link
Copy Markdown
Owner Author

/docker-build e010a1e

@github-actions

github-actions Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

🐳 Docker image built successfully!

Image

ghcr.io/ryan-millard/img2num-dev:pr-322

Run it locally:

IMG2NUM_IMAGE=ghcr.io/ryan-millard/img2num-dev:pr-322 ./img2num sh

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 | 🔴 Critical

Add pagination to the GHCR package lookup.

Package versions from the GitHub Container Registry API are paginated. Without --paginate or explicit per_page handling, the lookup checks only the first page of results and can miss older pr-* tags, incorrectly falling back to main.

🔧 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

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: abf79725-bfcb-45b4-8e09-ab9ff30fb827

📥 Commits

Reviewing files that changed from the base of the PR and between ea80726 and b096bed.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml

Comment thread .github/workflows/ci.yml
@Ryan-Millard
Ryan-Millard requested a review from Krasner April 22, 2026 21:14
@Krasner

Krasner commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

nice!

@Ryan-Millard

Copy link
Copy Markdown
Owner Author

/docker-build 315790e

@Ryan-Millard
Ryan-Millard merged commit 8ea6b19 into main Apr 22, 2026
17 checks passed
@Ryan-Millard
Ryan-Millard deleted the fix/ci/docker-image-resolution branch April 22, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants