Skip to content

Allow manual image build - #879

Merged
m-Peter merged 3 commits into
mainfrom
bastian/manual-image-build
Sep 12, 2025
Merged

Allow manual image build#879
m-Peter merged 3 commits into
mainfrom
bastian/manual-image-build

Conversation

@turbolent

@turbolent turbolent commented Sep 11, 2025

Copy link
Copy Markdown
Member

Description

Add support for triggering the workflow to build & publish an image manually.

For example, this is useful when the automatic build failed.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • Chores
    • Enabled manual triggering of the build pipeline (workflow_dispatch) to allow ad-hoc runs.
    • No changes to application behavior or public APIs.

@coderabbitai

coderabbitai Bot commented Sep 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The CI workflow now supports manual runs via workflow_dispatch with a required string input version. The “Set Gateway Version” step reads GATEWAY_VERSION from this input instead of git describe, propagating it to downstream steps (e.g., Docker build/push). The git-based fallback is effectively bypassed when input is provided.

Changes

Cohort / File(s) Summary
CI Workflow inputs and version derivation
\.github/workflows/build.yml
Added workflow_dispatch with required version input; updated “Set Gateway Version” to use ${{ inputs.version }} for GATEWAY_VERSION, effectively overriding prior git describe resolution and feeding this value to subsequent build/publish steps.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Dev as Developer
    participant GH as GitHub Actions (build.yml)
    participant Step1 as Set Gateway Version
    participant Build as Docker Build/Push

    Dev->>GH: workflow_dispatch(version)
    GH->>Step1: Run step with inputs.version
    Note over Step1: Set env.GATEWAY_VERSION = inputs.version<br/>(git describe path skipped)
    Step1-->>Build: Expose GATEWAY_VERSION
    Build->>Build: Tag and push using GATEWAY_VERSION
    Build-->>GH: Complete job
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I pressed the button—version in paw,
The pipeline hopped without a flaw.
No tags to chase, no dusty lore,
Just GATEWAY_VERSION at the core.
Docker hums, the carrots build—
A tidy run, a bunny thrilled. 🥕🚀

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Allow manual image build" is concise and accurately summarizes the primary change in the changeset (adding a manual workflow trigger to build/publish the container image), making it clear and relevant for teammates scanning PR history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bastian/manual-image-build

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.

@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

🧹 Nitpick comments (1)
.github/workflows/build.yml (1)

7-11: Manual trigger input looks good; consider adding light validation.

LGTM for enabling workflow_dispatch. Optional: add description: for UX and a short pre-step to validate version format (e.g., require a tag-like v1.2.3) to fail fast if someone passes garbage.

Example validation step (add before “Set Gateway Version”):

+      - name: Validate input version (manual runs)
+        if: ${{ github.event_name == 'workflow_dispatch' }}
+        run: |
+          case "${{ inputs.version }}" in
+            v*[0-9]) : ;;
+            *) echo "Invalid version: ${{ inputs.version }} (expected tag like v1.2.3)"; exit 1 ;;
+          esac
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cdaa9b8 and 16d7682.

📒 Files selected for processing (1)
  • .github/workflows/build.yml (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test

Comment thread .github/workflows/build.yml Outdated
- name: Set Gateway Version
id: set_version
run: echo "GATEWAY_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo 'unknown')" >> $GITHUB_OUTPUT
run: echo "GATEWAY_VERSION=$(echo '${{ inputs.version }}' || git describe --tags --abbrev=0 2>/dev/null || echo 'unknown')" >> $GITHUB_OUTPUT

@coderabbitai coderabbitai Bot Sep 11, 2025

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.

⚠️ Potential issue

Broken fallback: echo always succeeds; tag builds will set an empty GATEWAY_VERSION.

echo '${{ inputs.version }}' || git describe ... never reaches the fallback because echo returns 0 even when empty. On tag pushes (no input) this yields an empty tag and will break Docker build/push.

Use an explicit emptiness check and prefer the event’s tag name when available:

-        run: echo "GATEWAY_VERSION=$(echo '${{ inputs.version }}' || git describe --tags --abbrev=0 2>/dev/null || echo 'unknown')" >> $GITHUB_OUTPUT
+        run: |
+          set -euo pipefail
+          ver="${{ inputs.version || '' }}"
+          # On tag pushes, GitHub exposes the tag as GITHUB_REF_NAME
+          if [ -z "$ver" ]; then
+            ver="${GITHUB_REF_NAME:-}"
+          fi
+          # Fallback to git describe if still empty (e.g., manual run without input)
+          if [ -z "$ver" ]; then
+            ver="$(git describe --tags --abbrev=0 2>/dev/null || true)"
+          fi
+          if [ -z "$ver" ]; then
+            echo "error: GATEWAY_VERSION could not be determined" >&2
+            exit 1
+          fi
+          echo "GATEWAY_VERSION=$ver" >> "$GITHUB_OUTPUT"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
run: echo "GATEWAY_VERSION=$(echo '${{ inputs.version }}' || git describe --tags --abbrev=0 2>/dev/null || echo 'unknown')" >> $GITHUB_OUTPUT
run: |
set -euo pipefail
ver="${{ inputs.version || '' }}"
# On tag pushes, GitHub exposes the tag as GITHUB_REF_NAME
if [ -z "$ver" ]; then
ver="${GITHUB_REF_NAME:-}"
fi
# Fallback to git describe if still empty (e.g., manual run without input)
if [ -z "$ver" ]; then
ver="$(git describe --tags --abbrev=0 2>/dev/null || true)"
fi
if [ -z "$ver" ]; then
echo "error: GATEWAY_VERSION could not be determined" >&2
exit 1
fi
echo "GATEWAY_VERSION=$ver" >> "$GITHUB_OUTPUT"
🤖 Prompt for AI Agents
In .github/workflows/build.yml around line 30, the current command uses "echo
'${{ inputs.version }}' || git describe ..." which always succeeds (even when
empty) and results in an empty GATEWAY_VERSION on tag builds; replace this with
a real emptiness check and an ordered fallback: use the workflow input if
non-empty, otherwise prefer the event/tag name (e.g. github.ref or the release
tag name when present), then fallback to git describe --tags --abbrev=0, and
finally 'unknown'; update the run step to compute the value with those explicit
conditionals and then append "GATEWAY_VERSION=..." to $GITHUB_OUTPUT so the
Docker build receives a non-empty version.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@turbolent Is the AI here right? Have you tried this workflow? Or it needs merge first?

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.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Update: It seems the AI is right indeed.

@j1010001
j1010001 requested a review from manny-yes September 11, 2025 23:19

@m-Peter m-Peter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@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 (2)
.github/workflows/build.yml (2)

24-27: Don’t publish “unknown”; make version resolution robust and explicit.

Current fallback can yield “unknown”, which would produce/push a bogus tag. Prefer input → tag ref → latest reachable tag → short SHA, and hard-fail if still empty.

-      - name: Set Gateway Version
-        id: set_version
-        run: echo "GATEWAY_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo 'unknown')" >> $GITHUB_OUTPUT
+      - name: Set Gateway Version
+        id: set_version
+        shell: bash
+        run: |
+          set -euo pipefail
+          ver="${{ github.event_name == 'workflow_dispatch' && inputs.version || '' }}"
+          # If this is a tag push, prefer the tag from the ref
+          if [ -z "$ver" ] && [[ "${GITHUB_REF:-}" == refs/tags/* ]]; then
+            ver="${GITHUB_REF##refs/tags/}"
+          fi
+          # Fallback to latest reachable tag
+          if [ -z "$ver" ]; then
+            ver="$(git describe --tags --abbrev=0 2>/dev/null || true)"
+          fi
+          # Last resort: short SHA (avoid 'unknown')
+          if [ -z "$ver" ]; then
+            ver="$(git rev-parse --short HEAD)"
+          fi
+          if [ -z "$ver" ]; then
+            echo "error: GATEWAY_VERSION could not be determined" >&2
+            exit 1
+          fi
+          echo "GATEWAY_VERSION=$ver" >> "$GITHUB_OUTPUT"

41-45: Guard against empty/invalid tags before build/push.

Add a strict check so we never publish an image with an empty or “unknown” tag.

-      - name: Docker Auth
-        run: |-
-          gcloud auth configure-docker ${{ vars.GAR_LOCATION }}-docker.pkg.dev
-          docker build --build-arg VERSION="${{ steps.set_version.outputs.GATEWAY_VERSION }}" --build-arg ARCH=amd64 -t ${{ env.DOCKER_IMAGE_URL }}:${{ steps.set_version.outputs.GATEWAY_VERSION }} --file Dockerfile .
-          docker push ${{ env.DOCKER_IMAGE_URL }}:${{ steps.set_version.outputs.GATEWAY_VERSION }}
+      - name: Docker Auth, Build & Push
+        shell: bash
+        run: |
+          set -euo pipefail
+          gcloud auth configure-docker ${{ vars.GAR_LOCATION }}-docker.pkg.dev
+          ver='${{ steps.set_version.outputs.GATEWAY_VERSION }}'
+          if [ -z "$ver" ] || [ "$ver" = "unknown" ]; then
+            echo "error: refusing to publish image with invalid tag: '$ver'" >&2
+            exit 1
+          fi
+          docker build --build-arg VERSION="$ver" --build-arg ARCH=amd64 -t "${{ env.DOCKER_IMAGE_URL }}:$ver" --file Dockerfile .
+          docker push "${{ env.DOCKER_IMAGE_URL }}:$ver"
🧹 Nitpick comments (2)
.github/workflows/build.yml (2)

37-37: Upgrade setup-gcloud to v2 (v1 is legacy).

Use the maintained major for better performance and fixes.

-      - name: Set up Cloud SDK
-        uses: google-github-actions/setup-gcloud@v1
+      - name: Set up Cloud SDK
+        uses: google-github-actions/setup-gcloud@v2

19-19: Pin Actions by commit SHA for supply-chain hardening.

actions/checkout@v4 (and other actions) should be pinned to a specific SHA to prevent supply-chain drift. Optional but recommended.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16d7682 and 2f59024.

📒 Files selected for processing (1)
  • .github/workflows/build.yml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test

Comment thread .github/workflows/build.yml
@m-Peter
m-Peter merged commit fee80d0 into main Sep 12, 2025
2 checks passed
@m-Peter
m-Peter deleted the bastian/manual-image-build branch September 12, 2025 16:59
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.

4 participants