forked from jackyzha0/docker-explained
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
44 lines (38 loc) · 1.01 KB
/
Dockerfile
File metadata and controls
44 lines (38 loc) · 1.01 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
# --- Stage 1 ---
# Rust planning stage, compute recipe
FROM rust:latest as planner
RUN rustup default nightly \
&& rustup update
WORKDIR app
RUN cargo install cargo-chef
# copy source files
COPY . .
# prep recipe to memo deps
RUN cargo chef prepare --recipe-path recipe.json
# --- Stage 2 ---
# Rust deps build caching staging
FROM rust:latest as cacher
RUN rustup default nightly \
&& rustup update
WORKDIR app
RUN cargo install cargo-chef
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
# --- Stage 3 ---
# Rust source code build stage
FROM rust:latest as builder
RUN rustup default nightly \
&& rustup update
WORKDIR app
COPY . .
# copy over the cached dependencies
COPY --from=cacher /app/target target
COPY --from=cacher /usr/local/cargo /usr/local/cargo
RUN cargo build --release --bin app
# --- Stage 4 ---
# Runtime
FROM rust:slim as runtime
WORKDIR app
COPY --from=builder /app/target/release/app /usr/local/bin
EXPOSE 8000
ENTRYPOINT ["./usr/local/bin/app"]