1 | FROM rust:1.73 as build |
2 | |
3 | ENV CARGO_BUILD_TARGET=x86_64-unknown-linux-musl |
4 | |
5 | ENV DEBIAN_FRONTEND=noninteractive |
6 | RUN \ |
7 | apt-get update && \ |
8 | apt-get -y install ca-certificates musl-tools && \ |
9 | rustup target add ${CARGO_BUILD_TARGET} |
10 | |
11 | ENV PKG_CONFIG_ALLOW_CROSS=1 |
12 | |
13 | # Use Tini as our PID 1. This will enable signals to be handled more correctly. |
14 | # |
15 | # Note that this can't be downloaded inside the scratch container as we have no |
16 | # chmod command. |
17 | # |
18 | # TODO: Use `--init` instead when it is more well-supported (this should be the |
19 | # case by Jan 1, 2020). |
20 | ENV TINI_VERSION v0.18.0 |
21 | ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static /tini |
22 | RUN chmod +x /tini |
23 | |
24 | # Build the real project. |
25 | COPY ./ ./ |
26 | |
27 | RUN cargo build --release |
28 | |
29 | RUN \ |
30 | mkdir -p /build && \ |
31 | cp target/${CARGO_BUILD_TARGET}/release/rudolfs /build/ && \ |
32 | strip /build/rudolfs |
33 | |
34 | # Use scratch so we can get an itty-bitty-teeny-tiny image. This requires us to |
35 | # use musl when building the application. |
36 | FROM scratch |
37 | |
38 | EXPOSE 8080 |
39 | VOLUME ["/data"] |
40 | |
41 | COPY --from=build /tini /tini |
42 | |
43 | COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt |
44 | |
45 | COPY --from=build /build/ / |
46 | |
47 | ENTRYPOINT ["/tini", "--", "/rudolfs"] |
48 | CMD ["--cache-dir", "/data"] |