Repository navigation
fix: bake the public PocketBase URL into the Docker app image (next) - #107
Conversation
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>
Reviewer's GuideConfigurationAccept and pass
DocumentationDocument that
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>| # 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 |
There was a problem hiding this comment.
🟠 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`.| # 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 |
There was a problem hiding this comment.
🟠 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.| # 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 |
There was a problem hiding this comment.
🟡 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.
Cherry-pick of #106 (merged into
mainas df3baa0) ontonext.Problem
Next.js inlines
NEXT_PUBLIC_*variables into the browser bundle at build time. The Dockerfile never receivesNEXT_PUBLIC_POCKETBASE_URL, so the publishedcheckmate-appimage ships a client bundle that falls back tohttp://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 withERR_CONNECTION_REFUSED.Change
ARG NEXT_PUBLIC_POCKETBASE_URLbeforenpm run build. It is an ARG without a matchingENVon purpose: an ARG that isn't passed stays unset duringRUN, so a.envin the build context still applies.appmatrix entry passesNEXT_PUBLIC_POCKETBASE_URL, from the repository variable of the same name when set, otherwisehttps://checkmate-api.keyurgolani.name; the build step getsbuild-args: ${{ matrix.image.build-args }}. Onnextthat step has no build cache and is followed by "Move latest to this release", so the conflict with main's version was mechanical: only thebuild-argsline was added, the rest of next's step is unchanged.No application code changes.
ci.yml'simagesjob 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 --noEmitpasses.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 reference127.0.0.1:8090.main, the same change is live:/demomakes its notifications and realtime calls tocheckmate-api.keyurgolani.nameand none to127.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:
Enhancements:
Build:
CI:
Documentation: