-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDockerfile
More file actions
87 lines (65 loc) · 1.84 KB
/
Dockerfile
File metadata and controls
87 lines (65 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
FROM rust:1.92.0-alpine3.23 AS base
RUN apk add --no-cache \
bash \
curl \
git \
npm \
build-base \
openssl-dev \
pkgconf \
libc-dev \
musl-dev \
binaryen \
perl \
python3 \
cmake
COPY rust-toolchain.toml ./
RUN rustup show
# Install all Rust tools once in base
RUN cargo install cargo-binstall
RUN cargo install cargo-chef
RUN npm install -g sass
RUN cargo install stylance-cli
RUN cargo binstall cargo-leptos -y
RUN cargo install -f wasm-bindgen-cli --version 0.2.105
RUN rustup target add wasm32-unknown-unknown
WORKDIR /work
###### Planner stage ####
FROM base AS planner
# Only copy dependency files, NOT source code
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
###### Chef stage - cook dependencies ####
FROM base AS chef
COPY --from=planner /work/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
###### Builder stage ######
FROM base AS builder
WORKDIR /work
# Copy cooked dependencies
COPY --from=chef /work/target target
COPY --from=chef /usr/local/cargo /usr/local/cargo
# Now copy source code
COPY . .
# Run stylance and build
RUN stylance .
RUN cargo leptos build --release -vv
##### Production runner #####
FROM debian:bookworm-slim AS runner
WORKDIR /app
# Install runtime dependencies
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends openssl ca-certificates \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
# Copy only what's needed for runtime
COPY --from=builder /work/data /app/data
COPY --from=builder /work/target/release/rust-nigeria-website /app/
COPY --from=builder /work/target/site /app/site
COPY --from=builder /work/Cargo.toml /app/
ENV RUST_LOG="debug"
ENV LEPTOS_SITE_ADDR="0.0.0.0:8080"
ENV LEPTOS_SITE_ROOT=./site
EXPOSE 8080
CMD ["/app/rust-nigeria-website"]