This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
103 lines (84 loc) · 3.41 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#
# Dockerfile of instrumentisto/medea Docker image.
#
#
# Stage 'dist' creates project distribution.
#
# https://hub.docker.com/_/rust
ARG rust_ver=latest
FROM ghcr.io/instrumentisto/rust:${rust_ver} AS dist
ARG rustc_mode=release
ARG rustc_opts=--release
# Create user and group files, which will be used in a running container to
# run the process as an unprivileged user.
RUN mkdir -p /out/etc/ \
&& echo 'nobody:x:65534:65534:nobody:/:' > /out/etc/passwd \
&& echo 'nobody:x:65534:' > /out/etc/group
# Install required system packages for building.
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
cmake
# Prepare Cargo workspace for building dependencies only.
COPY crates/medea-macro/Cargo.toml /app/crates/medea-macro/
COPY crates/medea-reactive/Cargo.toml /app/crates/medea-reactive/
COPY crates/medea-coturn-telnet-client/Cargo.toml \
/app/crates/medea-coturn-telnet-client/
COPY mock/control-api/Cargo.toml /app/mock/control-api/
COPY proto/client-api/Cargo.toml /app/proto/client-api/
COPY proto/control-api/Cargo.toml /app/proto/control-api/
# Required to omit triggering re-compilation for build.rs.
COPY proto/control-api/build.rs /app/proto/control-api/
COPY proto/control-api/src/grpc/api.proto \
proto/control-api/src/grpc/api*.rs \
/app/proto/control-api/src/grpc/
COPY jason/Cargo.toml /app/jason/
COPY e2e/Cargo.toml /app/e2e/
COPY Cargo.toml Cargo.lock /app/
WORKDIR /app/
RUN mkdir -p crates/medea-macro/src/ && touch crates/medea-macro/src/lib.rs \
&& mkdir -p crates/medea-reactive/src/ \
&& touch crates/medea-reactive/src/lib.rs \
&& mkdir -p crates/medea-coturn-telnet-client/src/ \
&& touch crates/medea-coturn-telnet-client/src/lib.rs \
&& mkdir -p mock/control-api/src/ && touch mock/control-api/src/lib.rs \
&& mkdir -p proto/client-api/src/ && touch proto/client-api/src/lib.rs \
&& mkdir -p proto/control-api/src/ && touch proto/control-api/src/lib.rs \
&& mkdir -p jason/src/ && touch jason/src/lib.rs \
&& mkdir -p e2e/src/ && touch e2e/src/lib.rs \
&& mkdir -p src/ && touch src/lib.rs
# Build dependencies only.
RUN cargo build --lib ${rustc_opts}
# Remove fingreprints of pre-built empty project sub-crates
# to rebuild them correctly later.
RUN rm -rf /app/target/${rustc_mode}/.fingerprint/medea*
# Prepare project sources for building.
COPY crates/ /app/crates/
COPY proto/ /app/proto/
COPY src/ /app/src/
# Build project distribution binary.
# TODO: use --out-dir once stabilized
# TODO: https://github.com/rust-lang/cargo/issues/6790
RUN cargo build --bin=medea ${rustc_opts}
# Prepare project distribution binary and all dependent dynamic libraries.
RUN cp /app/target/${rustc_mode}/medea /out/medea \
&& ldd /out/medea \
# These libs are not reported by ldd(1) on binary,
# but are vital for DNS resolution.
# See: https://forums.aws.amazon.com/thread.jspa?threadID=291609
/lib/x86_64-linux-gnu/libnss_dns.so.2 \
/lib/x86_64-linux-gnu/libnss_files.so.2 \
| awk 'BEGIN{ORS=" "}$1~/^\//{print $1}$3~/^\//{print $3}' \
| sed 's/,$/\n/' \
| tr -d ':' \
| tr ' ' "\n" \
| xargs -I '{}' cp -fL --parents '{}' /out/ \
&& rm -rf /out/out
#
# Stage 'runtime' creates final Docker image to use in runtime.
#
# https://hub.docker.com/_/scratch
FROM scratch AS runtime
COPY --from=dist /out/ /
USER nobody:nobody
LABEL org.opencontainers.image.source="https://github.com/instrumentisto/medea"
ENTRYPOINT ["/medea"]