-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
62 lines (44 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
56
57
58
59
60
61
62
### Build arguments
ARG APP_NAME=snmp_sim
ARG BASE_IMAGE=debian:10-slim
ARG BUILDER_IMAGE=lukemathwalker/cargo-chef:latest-rust-1.62-buster
ARG CARGO_REGISTRY_URL=
ARG RELEASE_OR_DEBUG=release
FROM ${BUILDER_IMAGE} as custom_builder
ARG CARGO_REGISTRY_URL
# Install git - debian
RUN apt update && apt install -y python3 python3-pip git jq pkg-config libssl-dev && git config --global credential.helper store && echo "${CARGO_REGISTRY_URL}" > ~/.git-credentials
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
### Analyze the current project to determine the minimum subset of files (Cargo.lock
### and Cargo.toml manifests) required to build it and cache dependencies
FROM custom_builder as planner
ARG APP_NAME
WORKDIR /${APP_NAME}/
COPY . .
COPY .cargo/config .cargo/config
RUN cargo chef prepare --recipe-path recipe.json
### Re-hydrate the minimum project identified by `cargo chef prepare` and
### build it to cache dependencies
FROM custom_builder as builder
ARG APP_NAME
ARG RELEASE_OR_DEBUG
WORKDIR /${APP_NAME}/
COPY --from=planner /${APP_NAME}/recipe.json recipe.json
COPY .cargo/config .cargo/config
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release --bin "${APP_NAME}"
WORKDIR /${APP_NAME}/snmp-sim-cli/
RUN cargo build --release
WORKDIR /${APP_NAME}/target/${RELEASE_OR_DEBUG}
### Minimal runtime image
FROM ${BASE_IMAGE} as runtime
ARG RELEASE_OR_DEBUG
ARG APP_NAME
COPY --from=builder /${APP_NAME}/target/${RELEASE_OR_DEBUG}/${APP_NAME} /service
COPY --from=builder /${APP_NAME}/target/${RELEASE_OR_DEBUG}/snmp-sim-cli /snmp-sim-cli
COPY --from=builder /${APP_NAME}/configuration/base.yaml /configuration/base.yaml
COPY --from=builder /${APP_NAME}/os-linux-std.txt /os-linux-std.txt
COPY --from=builder /usr/lib/x86_64-linux-gnu/libssl* /lib/x86_64-linux-gnu
COPY --from=builder /usr/lib/x86_64-linux-gnu/libcrypto* /lib/x86_64-linux-gnu
ENTRYPOINT ["/service"]