forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
80 lines (72 loc) · 2.05 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
73
74
75
76
77
78
79
80
FROM clux/muslrust:stable AS chef
WORKDIR /app
RUN cargo install cargo-chef
FROM chef AS planner
WORKDIR /app
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef as development
WORKDIR /app
ARG UID=1000
ARG RUN_AS_USER=appuser
ARG TRACKER_UDP_PORT=6969
ARG TRACKER_HTTP_PORT=7070
ARG TRACKER_API_PORT=1212
# Add the app user for development
ENV USER=appuser
ENV UID=$UID
RUN adduser --uid "${UID}" "${USER}"
# Build dependencies
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --recipe-path recipe.json
# Build the application
COPY . .
RUN cargo build --bin torrust-tracker
USER $RUN_AS_USER:$RUN_AS_USER
EXPOSE $TRACKER_UDP_PORT/udp
EXPOSE $TRACKER_HTTP_PORT/tcp
EXPOSE $TRACKER_API_PORT/tcp
CMD ["cargo", "run"]
FROM chef AS builder
WORKDIR /app
ARG UID=1000
# Add the app user for production
ENV USER=appuser
ENV UID=$UID
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
# Build dependencies
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json
# Build the application
COPY . .
RUN cargo build --release --target x86_64-unknown-linux-musl --bin torrust-tracker
# Strip the binary
# More info: https://github.com/LukeMathWalker/cargo-chef/issues/149
RUN strip /app/target/x86_64-unknown-linux-musl/release/torrust-tracker
FROM alpine:latest
WORKDIR /app
ARG RUN_AS_USER=appuser
ARG TRACKER_UDP_PORT=6969
ARG TRACKER_HTTP_PORT=7070
ARG TRACKER_API_PORT=1212
RUN apk --no-cache add ca-certificates
ENV TZ=Etc/UTC
ENV RUN_AS_USER=$RUN_AS_USER
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder --chown=$RUN_AS_USER \
/app/target/x86_64-unknown-linux-musl/release/torrust-tracker \
/app/torrust-tracker
RUN chown -R $RUN_AS_USER:$RUN_AS_USER /app
USER $RUN_AS_USER:$RUN_AS_USER
EXPOSE $TRACKER_UDP_PORT/udp
EXPOSE $TRACKER_HTTP_PORT/tcp
EXPOSE $TRACKER_API_PORT/tcp
ENTRYPOINT ["/app/torrust-tracker"]