1+ # Stage 1: Builder
2+ # This stage installs all dependencies and builds the application.
3+ FROM debian:bookworm-slim AS builder
4+
5+ # Install essential build tools, clang, and nodejs for sass
6+ RUN apt-get update && \
7+ apt-get install -y --no-install-recommends \
8+ build-essential \
9+ clang-16 \
10+ llvm-16 \
11+ curl \
12+ pkg-config \
13+ libssl-dev \
14+ ca-certificates \
15+ nodejs \
16+ npm && \
17+ rm -rf /var/lib/apt/lists/*
18+
19+ # Install Rust and the wasm32 target
20+ ENV RUSTUP_HOME=/usr/local/rustup \
21+ CARGO_HOME=/usr/local/cargo \
22+ PATH=/usr/local/cargo/bin:$PATH
23+ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable && \
24+ rustup target add wasm32-unknown-unknown
25+
26+ # Install Trunk and Dart Sass
27+ RUN cargo install trunk && \
28+ npm install -g sass
29+
30+ # Set environment variables for the Wasm C compiler, mimicking the Nix setup.
31+ # This tells Rust's build scripts to use clang-16 when compiling C code for Wasm.
32+ ENV CC_wasm32_unknown_unknown=clang-16
33+ ENV AR_wasm32_unknown_unknown=llvm-ar-16
34+ ENV CFLAGS_wasm32_unknown_unknown="-I/usr/lib/clang/16/include"
35+
36+ # Copy the application source code
37+ WORKDIR /app
38+ COPY . .
39+
40+ # Build the application
41+ RUN trunk build --release && \
42+ sh fix-links.sh
43+
44+ # Stage 2: Final Image
45+ # This stage creates a minimal image to serve the built static files.
46+ FROM nginx:1.27-alpine-slim
47+
48+ # Copy the built assets from the builder stage
49+ COPY --from=builder /app/dist /usr/share/nginx/html
50+
51+ # Expose port 80 and start Nginx
52+ EXPOSE 80
53+ CMD ["nginx" , "-g" , "daemon off;" ]
0 commit comments