-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile
53 lines (37 loc) · 1.47 KB
/
Dockerfile
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
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /app
# stage 1, prepare the recipe for build caching
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# stage 2, copy over source code and build
FROM chef AS rust_builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release
# stage 2b, build our css as we don't have a formal preprocessor
FROM node:buster-slim as node_builder
WORKDIR /app
# we'll use pnpm to ensure we're consistent across the dev and release environments
RUN corepack enable
# copy on over all the dependencies
COPY tailwind.config.cjs .
COPY styles ./styles
COPY assets ./assets
# we'll also copy the templates over so tailwind can scan for unused class utilities, omitting them from the final output
COPY ./templates ./templates
# build our css
RUN pnpm dlx tailwindcss -i ./styles/tailwind.css -o ./assets/main.css
# stage 3, copy over our build artifacts and run
# We do not need the Rust toolchain to run the binary!
FROM debian:buster-slim AS runtime
WORKDIR /app
# we'll copy over the executable from our server builder and the compiled tailwind assets separately - layer caching FTW!
COPY --from=rust_builder /app/target/release/axum-static-web-server ./server
COPY --from=node_builder /app/assets ./assets
EXPOSE 80
EXPOSE 443
ENTRYPOINT ["/app/server"]