-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
68 lines (41 loc) · 1.69 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
########################################
# Base Builder Image #
########################################
FROM docker.io/lukemathwalker/cargo-chef:latest-rust-alpine as chef-factory
WORKDIR WORKDIR /workspace
RUN set -eux; apk add --no-cache bash musl-dev \
&& wget -O "/usr/bin/tini" \
"https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-$(uname -m | sed 's#x86_64#amd64#g; s#aarch64#arm64#g')" \
&& chmod +x /usr/bin/tini
########################################
# Build "Planner" #
########################################
FROM chef-factory AS planner
WORKDIR /workspace
COPY . .
SHELL ["/bin/bash", "-o", "errexit", "-o", "pipefail", "-o", "nounset", "-c"]
RUN cargo chef prepare --recipe-path recipe.json
########################################
# Artifact Builder #
########################################
FROM chef-factory AS builder
WORKDIR /workspace
COPY --from=planner /workspace/recipe.json recipe.json
SHELL ["/bin/bash", "-o", "errexit", "-o", "pipefail", "-o", "nounset", "-c"]
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release --bin echo-rs
########################################
# App Image #
########################################
FROM gcr.io/distroless/static-debian11:nonroot AS app-image
# ^ we don't need the Rust toolchain to run the binary
WORKDIR /
COPY --from=builder /usr/bin/tini /bin/tini
COPY --from=builder /workspace/target/release/echo-rs /bin/echo-rs
USER 1000:1000
EXPOSE 8080 9090
ENTRYPOINT ["/bin/tini", "--"]
CMD ["/bin/echo-rs"]