feat: add embedded web image build option#210
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the --embed-web flag to the image build system, enabling the embedding of web client assets into the scion binary for local Docker and Podman builds. The changes include updates to the build scripts, documentation, and the scion-base Dockerfile to handle conditional frontend compilation and Go build tags. Feedback was provided to optimize the Dockerfile by separating npm dependency installation from the source code copy to improve layer caching and ensuring that frontend file changes do not unnecessarily invalidate Go build caches when the embedding feature is disabled.
| COPY web/package.json web/package-lock.json web/vite.config.ts web/tsconfig.json web/tsconfig.client.json web/index.html ./web/ | ||
| COPY web/scripts/ ./web/scripts/ | ||
| COPY web/public/ ./web/public/ | ||
| COPY web/src/ ./web/src/ | ||
|
|
||
| RUN if [ "${EMBED_WEB}" = "true" ]; then \ | ||
| cd web && npm ci && npm run build; \ | ||
| fi |
There was a problem hiding this comment.
The current structure of the web asset build process has two significant efficiency issues:
- Layer Caching for Dependencies: By copying all web source files (including
src/) before runningnpm ci, any change to a source file will invalidate the cache for the dependency installation step.npm ciis typically slow and should only be re-run whenpackage.jsonorpackage-lock.jsonchanges. - Go Build Invalidation: Because the Go build step (line 52) follows the web asset
COPYandRUNcommands, any change to a frontend file (e.g., a CSS or TS file) will invalidate the cache for the Go build, even ifEMBED_WEBis set tofalse. This causes unnecessary full rebuilds of thescionandsciontoolbinaries during local development.
To optimize this, split the dependency installation from the build step. For a more robust fix to the Go build invalidation, consider using a separate build stage for the web assets and copying the results back into the main builder stage only if EMBED_WEB is true.
COPY web/package.json web/package-lock.json ./web/
RUN if [ "${EMBED_WEB}" = "true" ]; then \
cd web && npm ci; \
fi
COPY web/vite.config.ts web/tsconfig.json web/tsconfig.client.json web/index.html ./web/
COPY web/scripts/ ./web/scripts/
COPY web/public/ ./web/public/
COPY web/src/ ./web/src/
RUN if [ "${EMBED_WEB}" = "true" ]; then \
cd web && npm run build; \
fi
Fixes #<issue_number_goes_here>