chore(docker): R2 application image with the Rust core — wasm stage, precompressed module, CSP proof on the image

Dockerfile stage 0 (rust:1.99.0-bookworm, wasm32 target, wasm-bindgen-cli
at the builder's pinned version, cargo cache mounts) builds the shipped
module with scripts/wasm-build.sh (WASM_BUILD_SHIPPED_ONLY=1); the Node
stage copies packages/core-wasm (manifest + pkg/); the runner gzips the
module and nginx serves it with gzip_static (application/wasm, 1,180,153
bytes raw, 372,275 served). docker/csp-proof/app-image.sh runs the real
image behind the DEPLOY.md CSP in headless Chromium: with
'wasm-unsafe-eval' a report is created and a zone click is applied by the
core with no script or wasm violation; without it the editor shows the
degraded notice, stays put and leaves the draft untouched; /login,
/app/account and / never request the module (15/15 checks).
This commit is contained in:
bchanot committed 2026-10-14 00:45:51 +02:00
1 parent 74fcb37564
commit 7be94d4ce6
5 files changed
+183 -7

No files matched your search

+29 -1
View File
@@ -1,3 +1,28 @@
# ---- stage 0: wasm --------------------------------------------------
# The Rust core compiled to the browser module (R2). Same toolchain and wasm-bindgen CLI
# as docker/rust-builder.Dockerfile (keep the two ARG lines equal); scripts/wasm-build.sh
# refuses a CLI that differs from the wasm-bindgen crate in Cargo.lock. The production VPS
# never builds this image: it pulls it by digest (DEPLOY.md).
FROM rust:1.99.0-bookworm AS wasm
ARG WASM_BINDGEN_VERSION=0.2.129
RUN rustup target add wasm32-unknown-unknown \
&& rustup component add rustfmt clippy \
&& cargo install wasm-bindgen-cli --version "${WASM_BINDGEN_VERSION}" --locked \
&& rm -rf /usr/local/cargo/registry
WORKDIR /w
COPY rust-toolchain.toml Cargo.toml Cargo.lock ./
COPY .cargo .cargo
COPY crates crates
COPY scripts/rust-env.sh scripts/wasm-build.sh scripts/
# The build and wasm-bindgen run in one RUN: the cache-mounted target never reaches the
# layer, the generated packages/core-wasm/pkg does.
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/w/target \
WASM_BUILD_SHIPPED_ONLY=1 bash scripts/wasm-build.sh
# ---- stage 1: builder -----------------------------------------------
# Node 24 LTS (Node 20 reached end-of-life on 2026-04-30). pnpm pinned to the
# same version as package.json "packageManager"; pnpm 11 needs Node >= 22.13
@@ -15,6 +40,7 @@ COPY packages/domain/package.json packages/domain/
COPY packages/anatomy/package.json packages/anatomy/
COPY packages/pdf/package.json packages/pdf/
COPY packages/supabase/package.json packages/supabase/
COPY packages/core-wasm/package.json packages/core-wasm/
RUN pnpm install --frozen-lockfile
@@ -25,13 +51,15 @@ RUN pnpm install --frozen-lockfile
ARG SHEET_BUNDLE=none
ENV SHEET_BUNDLE=$SHEET_BUNDLE
COPY . .
COPY --from=wasm /w/packages/core-wasm/pkg packages/core-wasm/pkg
RUN pnpm --filter @faunosteo/app build
# ---- stage 2: runner ------------------------------------------------
FROM nginx:1.31-alpine AS runner
# Copy built static assets
# Copy built static assets; the core module is served precompressed (gzip_static)
COPY --from=builder /app/apps/app/dist /usr/share/nginx/html
RUN gzip -9 -k /usr/share/nginx/html/assets/*.wasm
# Copy custom nginx config and entrypoint
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf