-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
72 lines (51 loc) · 1.55 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
69
70
71
72
#inspiration from: https://youtu.be/xuqolj01D7M?t=2192
#stage 1: generate a recipe file for dependencies
FROM rust:latest as planner
WORKDIR /app
RUN cargo install cargo-chef
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
#stage 2 - build dependencies
FROM rust:latest as cacher
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
FROM rust:latest as builder
#Create a user
ENV USER=web
ENV UID=1001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
COPY . /app
WORKDIR /app
COPY --from=cacher /app/target target
COPY --from=cacher /usr/local/cargo /usr/local/cargo
RUN cargo build --release
FROM debian:stable-slim
#rust:1.66
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /app/public /app/public
COPY --from=builder /app/target/release/server_practice /app/server_practice
WORKDIR /app
USER web:web
#CMD /app
CMD ["./server_practice"]
###################### For production, you use a distroless, but for debugging with distro ######################
# FROM gcr.io/distroless/cc-debian11
# COPY --from=builder /etc/passwd /etc/passwd
# COPY --from=builder /etc/group /etc/group
# COPY --from=builder /app/public /public
# COPY --from=builder /app/target/release/server_practice /app/server_practice
# WORKDIR /app
# USER web:web
# #CMD /app
# CMD ["./server_practice"]