forked from gbip/sentry_tunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
69 lines (56 loc) · 1.97 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
####################################################################################################
## Builder
####################################################################################################
FROM rust:1.75 AS builder
ARG ARCH=x86_64
RUN rustup target add ${ARCH}-unknown-linux-musl
RUN apt update && apt install -y musl-tools musl-dev libssl-dev pkg-config curl g++
RUN update-ca-certificates
# Create appuser
ENV USER=sentry_tunnel
ENV UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
# Create an empty application to cache dependency build
RUN cargo new /sentry_tunnel --bin
WORKDIR /sentry_tunnel
RUN touch src/lib.rs
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml
RUN cargo build --target ${ARCH}-unknown-linux-musl --release
# Dependency have been built, remove the empty app and copy real source
RUN rm src/*.rs
COPY ./src ./src
RUN touch src/main.rs
RUN touch src/lib.rs
RUN rm -f ./target/release/deps/sentry_tunnel*
RUN rm -f ./target/release/deps/libsentry_tunnel*
RUN cargo build --target ${ARCH}-unknown-linux-musl --release
RUN mkdir /release/
RUN cp ./target/${ARCH}-unknown-linux-musl/release/sentry_tunnel /release/sentry_tunnel
#===========================#
# Install ssl certificates #
#===========================#
FROM alpine:3.14 as alpine
RUN apk add -U --no-cache ca-certificates
# ==========================#
# Final image #
# ==========================#
FROM scratch
# Import from builder.
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
WORKDIR /sentry_tunnel
# Copy our build
COPY --from=builder /release/sentry_tunnel ./
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Use an unprivileged user.
USER sentry_tunnel:sentry_tunnel
CMD ["/sentry_tunnel/sentry_tunnel"]