Skip to content

fix: bake the public PocketBase URL into the Docker app image (next) - #107

Merged
keyurgolani merged 1 commit into
nextfrom
fix/pocketbase-url-build-arg-next
Nov 13, 2026
Merged

keyurgolani merged 1 commit into
nextfrom
fix/pocketbase-url-build-arg-next

Conversation

@keyurgolani

@keyurgolani keyurgolani commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Cherry-pick of #106 (merged into main as df3baa0) onto next.

Problem

Next.js inlines NEXT_PUBLIC_* variables into the browser bundle at build time. The Dockerfile never receives NEXT_PUBLIC_POCKETBASE_URL, so the published checkmate-app image ships a client bundle that falls back to http://127.0.0.1:8090. Setting the variable on the running container only reaches server-side code; in the browser the dashboard's notifications and realtime fail with ERR_CONNECTION_REFUSED.

Change

  • Dockerfile: the builder stage accepts ARG NEXT_PUBLIC_POCKETBASE_URL before npm run build. It is an ARG without a matching ENV on purpose: an ARG that isn't passed stays unset during RUN, so a .env in the build context still applies.
  • publish-images.yml: the app matrix entry passes NEXT_PUBLIC_POCKETBASE_URL, from the repository variable of the same name when set, otherwise https://checkmate-api.keyurgolani.name; the build step gets build-args: ${{ matrix.image.build-args }}. On next that step has no build cache and is followed by "Move latest to this release", so the conflict with main's version was mechanical: only the build-args line was added, the rest of next's step is unchanged.
  • README: says the variable is a build-time setting.

No application code changes. ci.yml's images job still builds without the arg (a build check only); it doesn't publish.

Testing

  • node scripts/ci/check-workflow.mjs: 2 workflows pass; npx vitest --run scripts/ci/check-workflow.test.ts: 43 passed.
  • npx tsc --noEmit passes.
  • Local docker build --build-arg NEXT_PUBLIC_POCKETBASE_URL=https://checkmate-api.keyurgolani.name . of this branch (nothing pushed): the client chunks contain the URL, none read the variable at runtime, and none reference 127.0.0.1:8090.
  • On main, the same change is live: /demo makes its notifications and realtime calls to checkmate-api.keyurgolani.name and none to 127.0.0.1.

🤖 Generated with Claude Code

Summary by Sourcery

Bake the public PocketBase URL into published app images so browser-side features connect to the deployed API.

Bug Fixes:

  • Ensure published Docker app images use the correct public PocketBase URL in browser-side notifications and realtime functionality instead of defaulting to localhost.

Enhancements:

  • Document that NEXT_PUBLIC_POCKETBASE_URL must be supplied at build time and support values from the build context or repository configuration.

Build:

  • Allow Docker builds to receive NEXT_PUBLIC_POCKETBASE_URL as a build argument.

CI:

  • Pass the configured public PocketBase URL through the app image publishing workflow, with a production URL fallback.

Documentation:

  • Document the build-time configuration and default URL used for published app images.

Cherry-pick of df3baa0 (#106, on main) onto next.

Next.js inlines NEXT_PUBLIC_* variables into the browser bundle at build
time. The Dockerfile never received NEXT_PUBLIC_POCKETBASE_URL, so the
published checkmate-app image fell back to http://127.0.0.1:8090 in the
browser: setting the variable on the running container only reached
server code, and client-side calls (notifications, realtime) failed with
ERR_CONNECTION_REFUSED.

- Dockerfile: accept NEXT_PUBLIC_POCKETBASE_URL as a build arg in the
  builder stage. It is an ARG without ENV on purpose: when it is not
  passed it stays unset, so a .env in the build context still applies.
- publish-images.yml: pass the arg for the app image only, from the
  repository variable NEXT_PUBLIC_POCKETBASE_URL or
  https://checkmate-api.keyurgolani.name. On next the build step has no
  build cache and is followed by the "Move latest" step; the arg is added
  next to its tags and labels, nothing else changes.
- README: note that the variable is a build-time setting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Configuration

Accept and pass NEXT_PUBLIC_POCKETBASE_URL at image build time so the published app’s browser bundle uses the public PocketBase URL.

  • .github/workflows/publish-images.yml L48-51, L118
  • Dockerfile L45-52

Documentation

Document that NEXT_PUBLIC_POCKETBASE_URL must be set when building the app image.

  • README.md L175-182

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@keyurgolani
keyurgolani merged commit 9db4745 into next Nov 13, 2026
10 checks passed
@keyurgolani
keyurgolani deleted the fix/pocketbase-url-build-arg-next branch November 13, 2026 21:14

@sourcery-ai sourcery-ai 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.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="Dockerfile" line_range="51" />
<code_context>
+# Pass it with --build-arg NEXT_PUBLIC_POCKETBASE_URL=https://api.example.com.
+# Deliberately an ARG without ENV: when it isn't passed it stays unset, so a
+# NEXT_PUBLIC_POCKETBASE_URL in a .env inside the build context still applies.
+ARG NEXT_PUBLIC_POCKETBASE_URL
+
 # Build the application with standalone output
</code_context>
<issue_to_address>
**Browser requests use the wrong API**

When an image is built without the deployment URL as a build arg, or with a URL different from the runtime setting, next.js compiles `NEXT_PUBLIC_POCKETBASE_URL` into the browser bundle, so `getClientUrl()` uses the build-time value or localhost fallback instead of the runtime setting, and browser requests reach the wrong PocketBase instance.

Build each image with its deployment URL as a build arg, or move browser URL selection to runtime configuration.

Also at `.github/workflows/publish-images.yml:51`.
</issue_to_address>

### Comment 2
<location path="Dockerfile" line_range="51" />
<code_context>
+# Pass it with --build-arg NEXT_PUBLIC_POCKETBASE_URL=https://api.example.com.
+# Deliberately an ARG without ENV: when it isn't passed it stays unset, so a
+# NEXT_PUBLIC_POCKETBASE_URL in a .env inside the build context still applies.
+ARG NEXT_PUBLIC_POCKETBASE_URL
+
 # Build the application with standalone output
</code_context>
<issue_to_address>
**The `.env` API URL is ignored**

When a Docker or Compose build omits `NEXT_PUBLIC_POCKETBASE_URL` as a build arg while the build context’s `.env` defines it, docker exposes the declared ARG as an empty value during `npm run build`, so Next.js treats the variable as set and skips the `.env` value; `getClientUrl()` then compiles its localhost fallback and browser API calls fail.

Ensure an omitted build arg does not expose an empty `NEXT_PUBLIC_POCKETBASE_URL` during `npm run build`, so Next.js can load the `.env` value.
</issue_to_address>

### Comment 3
<location path="Dockerfile" line_range="51" />
<code_context>
+# Pass it with --build-arg NEXT_PUBLIC_POCKETBASE_URL=https://api.example.com.
+# Deliberately an ARG without ENV: when it isn't passed it stays unset, so a
+# NEXT_PUBLIC_POCKETBASE_URL in a .env inside the build context still applies.
+ARG NEXT_PUBLIC_POCKETBASE_URL
+
 # Build the application with standalone output
</code_context>
<issue_to_address>
**Runtime server URL override is ignored**

When the published image is built with one URL, then run with a different `NEXT_PUBLIC_POCKETBASE_URL` and no `POCKETBASE_URL`, next inlines direct `NEXT_PUBLIC_POCKETBASE_URL` references in the server bundle during this build too. If `POCKETBASE_URL` is unset, `getServerUrl()` uses the baked URL instead of the container's runtime `NEXT_PUBLIC_POCKETBASE_URL`, so server requests go to the wrong API despite the README saying the runtime setting changes server-side code.

Use a separate runtime-only server variable for server requests, or correct the documentation to state that `NEXT_PUBLIC_POCKETBASE_URL` cannot override the server bundle after build.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread Dockerfile
# Pass it with --build-arg NEXT_PUBLIC_POCKETBASE_URL=https://api.example.com.
# Deliberately an ARG without ENV: when it isn't passed it stays unset, so a
# NEXT_PUBLIC_POCKETBASE_URL in a .env inside the build context still applies.
ARG NEXT_PUBLIC_POCKETBASE_URL

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Browser requests use the wrong API

When an image is built without the deployment URL as a build arg, or with a URL different from the runtime setting, next.js compiles NEXT_PUBLIC_POCKETBASE_URL into the browser bundle, so getClientUrl() uses the build-time value or localhost fallback instead of the runtime setting, and browser requests reach the wrong PocketBase instance.

Build each image with its deployment URL as a build arg, or move browser URL selection to runtime configuration.

Also at .github/workflows/publish-images.yml:51.

Prompt for AI agents
In `Dockerfile` at line 51:

**Browser requests use the wrong API**

When an image is built without the deployment URL as a build arg, or with a URL different from the runtime setting, next.js compiles `NEXT_PUBLIC_POCKETBASE_URL` into the browser bundle, so `getClientUrl()` uses the build-time value or localhost fallback instead of the runtime setting, and browser requests reach the wrong PocketBase instance.

Build each image with its deployment URL as a build arg, or move browser URL selection to runtime configuration.

Also at `.github/workflows/publish-images.yml:51`.

Comment thread Dockerfile
# Pass it with --build-arg NEXT_PUBLIC_POCKETBASE_URL=https://api.example.com.
# Deliberately an ARG without ENV: when it isn't passed it stays unset, so a
# NEXT_PUBLIC_POCKETBASE_URL in a .env inside the build context still applies.
ARG NEXT_PUBLIC_POCKETBASE_URL

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · The .env API URL is ignored

When a Docker or Compose build omits NEXT_PUBLIC_POCKETBASE_URL as a build arg while the build context’s .env defines it, docker exposes the declared ARG as an empty value during npm run build, so Next.js treats the variable as set and skips the .env value; getClientUrl() then compiles its localhost fallback and browser API calls fail.

Ensure an omitted build arg does not expose an empty NEXT_PUBLIC_POCKETBASE_URL during npm run build, so Next.js can load the .env value.

Prompt for AI agents
In `Dockerfile` at line 51:

**The `.env` API URL is ignored**

When a Docker or Compose build omits `NEXT_PUBLIC_POCKETBASE_URL` as a build arg while the build context’s `.env` defines it, docker exposes the declared ARG as an empty value during `npm run build`, so Next.js treats the variable as set and skips the `.env` value; `getClientUrl()` then compiles its localhost fallback and browser API calls fail.

Ensure an omitted build arg does not expose an empty `NEXT_PUBLIC_POCKETBASE_URL` during `npm run build`, so Next.js can load the `.env` value.

Comment thread Dockerfile
# Pass it with --build-arg NEXT_PUBLIC_POCKETBASE_URL=https://api.example.com.
# Deliberately an ARG without ENV: when it isn't passed it stays unset, so a
# NEXT_PUBLIC_POCKETBASE_URL in a .env inside the build context still applies.
ARG NEXT_PUBLIC_POCKETBASE_URL

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Runtime server URL override is ignored

When the published image is built with one URL, then run with a different NEXT_PUBLIC_POCKETBASE_URL and no POCKETBASE_URL, next inlines direct NEXT_PUBLIC_POCKETBASE_URL references in the server bundle during this build too. If POCKETBASE_URL is unset, getServerUrl() uses the baked URL instead of the container's runtime NEXT_PUBLIC_POCKETBASE_URL, so server requests go to the wrong API despite the README saying the runtime setting changes server-side code.

Use a separate runtime-only server variable for server requests, or correct the documentation to state that NEXT_PUBLIC_POCKETBASE_URL cannot override the server bundle after build.

Prompt for AI agents
In `Dockerfile` at line 51:

**Runtime server URL override is ignored**

When the published image is built with one URL, then run with a different `NEXT_PUBLIC_POCKETBASE_URL` and no `POCKETBASE_URL`, next inlines direct `NEXT_PUBLIC_POCKETBASE_URL` references in the server bundle during this build too. If `POCKETBASE_URL` is unset, `getServerUrl()` uses the baked URL instead of the container's runtime `NEXT_PUBLIC_POCKETBASE_URL`, so server requests go to the wrong API despite the README saying the runtime setting changes server-side code.

Use a separate runtime-only server variable for server requests, or correct the documentation to state that `NEXT_PUBLIC_POCKETBASE_URL` cannot override the server bundle after build.

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