1
+ # Stage 1: Build WASM
2
+ # Use a specific Rust version for reproducibility
3
+ FROM rust:1.78 as wasm-builder
4
+
5
+ WORKDIR /usr/src/app
6
+
7
+ # Install wasm-pack
8
+ # cargo install is slow, consider using a pre-built image with wasm-pack or installing from binary if speed is critical
9
+ RUN cargo install wasm-pack
10
+
11
+ # Copy wasm source code
12
+ # Only copy what's needed for the WASM build to leverage Docker cache
13
+ COPY ./md-wasm ./md-wasm
14
+
15
+ # Build the wasm package
16
+ # The output will be in ./md-wasm/pkg by default
17
+ RUN wasm-pack build ./md-wasm --target web
18
+
19
+ # Stage 2: Build Astro application
20
+ FROM node:20-slim as builder
21
+
22
+ WORKDIR /app
23
+
24
+ # Install pnpm
25
+ RUN npm install -g pnpm
26
+
27
+ # Copy package.json and lock file
28
+ COPY package.json pnpm-lock.yaml ./
29
+
30
+ # Copy WASM build artifacts from wasm-builder stage to the public directory
31
+ # Astro will serve files from the public directory automatically.
32
+ # The WASM module can then be imported from /md-wasm-pkg/your_module_name.js
33
+ COPY --from=wasm-builder /usr/src/app/md-wasm/pkg ./public/md-wasm-pkg
34
+
35
+ # Install dependencies
36
+ RUN pnpm install
37
+
38
+ # Copy the rest of the application source code
39
+ COPY . .
40
+
41
+ # Build the Astro application
42
+ # The `build:wasm` script in package.json might be redundant now,
43
+ # or could be removed/modified if it conflicts.
44
+ # For now, we assume Astro's build will pick up the WASM from public.
45
+ RUN pnpm build
46
+
47
+ # Stage 3: Production image
48
+ FROM node:20-slim
49
+
50
+ WORKDIR /app
51
+
52
+ # Copy built application from the builder stage
53
+ COPY --from=builder /app/dist /app/dist
54
+ # Copy package.json for running the app (Astro's node adapter might need it)
55
+ COPY --from=builder /app/package.json /app/
56
+
57
+ # Install production dependencies only
58
+ # Astro's standalone mode for the node adapter bundles dependencies,
59
+ # but following the original Dockerfile's pattern.
60
+ RUN npm install --omit=dev
61
+
62
+ EXPOSE 4321
63
+
64
+ # Start the application
65
+ CMD ["node" , "./dist/server/entry.mjs" ]
0 commit comments