-
Notifications
You must be signed in to change notification settings - Fork 9
/
Dockerfile
74 lines (60 loc) · 2.59 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
################################################################################
#
# Install cargo-chef
#
################################################################################
FROM rust:buster AS chef
WORKDIR /app
RUN cargo install cargo-chef
################################################################################
#
# Generate recipe file
#
################################################################################
FROM chef AS plan
WORKDIR /app
COPY Cargo.lock Cargo.toml ./
COPY src ./src
COPY crates ./crates
RUN cargo chef prepare --recipe-path recipe.json
################################################################################
#
# Build the binary
#
################################################################################
FROM chef AS build
ENV TINI_VERSION v0.19.0
# This is a build requirement of `opentelemetry-otlp`. Once the new version
# is rolled out, which no longer requires the `protoc`, we'll be able to
# get rid of this.
RUN apt-get update \
&& apt-get install -y --no-install-recommends protobuf-compiler
RUN apt-get update \
&& apt-get install -y --no-install-recommends lld llvm
WORKDIR /app
# Cache dependencies
COPY --from=plan /app/recipe.json recipe.json
COPY --from=plan /app/crates ./crates
# Install init to be used in runtime container
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static /tini
RUN chmod +x /tini
RUN cargo chef cook --recipe-path recipe.json --release --features multitenant,analytics,cloud
# Build the local binary
COPY . .
RUN cargo build --bin echo-server --release --features multitenant,analytics,cloud
################################################################################
#
# Runtime image
#
################################################################################
FROM debian:buster-slim AS runtime
COPY --from=build /tini /tini
WORKDIR /app
COPY --from=build /app/target/release/echo-server /usr/local/bin/echo-server
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates libssl-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
USER 1001:1001
ENTRYPOINT ["/tini", "--"]
CMD ["/usr/local/bin/echo-server"]