fix(Dockerfile): make combined image work behind reverse proxies — ARG VITE_API_BASE_URL + fix frontend-dist permissions#1581
Open
Yunaido wants to merge 2 commits intoevroon:masterfrom
Open
fix(Dockerfile): make combined image work behind reverse proxies — ARG VITE_API_BASE_URL + fix frontend-dist permissions#1581Yunaido wants to merge 2 commits intoevroon:masterfrom
Yunaido wants to merge 2 commits intoevroon:masterfrom
Conversation
…ist file permissions
|
Ran into the exact same issue deploying behind Traefik with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two bugs in the combined
Dockerfile(the one that builds the single imageserving both frontend and backend via
SERVE_FRONTEND=true) make it brokenfor any deployment where the browser doesn't access the server on
localhost.Bug 1:
VITE_API_BASE_URLbaked ashttp://localhost:8400/apiVite replaces
import.meta.env.*at compile time, not runtime. Theresulting JS bundle contains a literal
http://localhost:8400/apistring.No Docker environment variable or runtime config can override it.
When a browser loads the app from any address other than
localhost(e.g.behind a reverse proxy, on a LAN IP, or a public domain), every API call
goes to the user's own machine and fails with
ERR_CONNECTION_REFUSED.This is the root cause of #1452, #1056, and the original #326.
Bug 2:
frontend-distfiles owned byroot:rootwith770permissionsCOPY --from=builder /app/dist /app/frontend-distruns afterUSER bracket,but Docker always runs
COPYas root. Several files produced by the npm build(all locale
common.jsonfiles, favicons, SVG icons) have770permissions —readable by owner/group only. Since the container runs as the
bracketuserand the files are owned by
root, these assets returnERR_HTTP2_PROTOCOL_ERROR,breaking translations and icons.
Fix
Bug 1: Introduce a build
ARGwith/apias the default. This is thecorrect value for
SERVE_FRONTEND=truedeployments (same-origin, so/apiresolves against whatever the browser's current origin is). Users who want
a different value can override it with
--build-arg VITE_API_BASE_URL=...at build time.
Bug 2: Add
--chown=bracket:bracketto theCOPY --from=builderinstruction so all frontend-dist files are owned by the app user.
Changes
Testing
Tested on TrueNAS SCALE (ZFS) behind Traefik with SERVE_FRONTEND=true and
API_PREFIX=/api. Before this fix: login failed, locales and favicons returned
protocol errors. After: all API calls resolve correctly, all assets load.
Fixes #1452
Fixes #1056