-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
55 lines (45 loc) · 1.88 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
# stage 1 - Setup cargo-chef
FROM --platform=$BUILDPLATFORM rust:1.82.0-alpine3.20 as planner
WORKDIR /app
RUN apk add gcc g++ make
RUN cargo install cargo-chef --locked
COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
COPY ./crates/metrs_stubs ./crates/metrs_stubs
COPY ./crates/metrsd_client ./crates/metrsd_client
COPY ./bin/metrs/Cargo.toml ./bin/metrs/Cargo.toml
COPY ./bin/metrsd/Cargo.toml ./bin/metrsd/Cargo.toml
RUN cargo chef prepare --recipe-path recipe.json --bin ./bin/metrsd
# stage 2 - Cook our dependencies
FROM --platform=$BUILDPLATFORM rust:1.82.0-alpine3.20 as cacher
WORKDIR /app
COPY --from=planner /usr/local/cargo/bin/cargo-chef /usr/local/cargo/bin/cargo-chef
COPY --from=planner /app .
RUN apk add musl-dev libpq-dev openssl-dev
ENV RUSTFLAGS="-C target-feature=+crt-static"
RUN export ARCH=$(uname -m) \
&& cargo chef cook --release --target=$ARCH-unknown-linux-musl --recipe-path recipe.json --bin metrsd
# stage 3 - Build our project
FROM --platform=$BUILDPLATFORM rust:1.82.0-alpine3.20 as builder
## Build our metrs daemon binary
WORKDIR /app
COPY --from=cacher /usr/local/cargo /usr/local/cargo
COPY --from=cacher /app .
COPY ./bin/metrsd/src ./bin/metrsd/src
COPY ./crates/metrs_stubs/src ./crates/metrs_stubs/src
COPY .git ./.git
RUN apk add musl-dev libpq-dev openssl-dev git upx
ENV RUSTFLAGS="-C target-feature=+crt-static"
RUN export ARCH=$(uname -m) \
&& cargo build --release --target=$ARCH-unknown-linux-musl --bin metrsd
## Compress the binary
RUN export ARCH=$(uname -m) \
&& cp /app/target/$ARCH-unknown-linux-musl/release/metrsd /bin/metrsd
# stage 4 - Create runtime image
FROM --platform=$BUILDPLATFORM scratch
## Copy the binary
COPY --from=builder /bin/metrsd /bin/metrsd
LABEL org.opencontainers.image.source https://github.com/next-hat/metrs
LABEL org.opencontainers.image.description Metrics Emitter
## Set entrypoint
ENTRYPOINT ["/bin/metrsd"]