-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
37 lines (31 loc) · 1010 Bytes
/
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
FROM gcr.io/distroless/cc
LABEL maintainer "sksat <[email protected]>"
FROM ghcr.io/sksat/cargo-chef-docker:1.79.0-bullseye as chef
WORKDIR /build
# get package name
FROM chef as metadata
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN apt-get update -y && apt-get install -y jq
ADD . .
RUN basename "$(cargo metadata --format-version=1 | jq --raw-output '.workspace_members[0]' | sed 's|.*://||')" | cut -d'@' -f 1 | cut -d'#' -f 2 > app_name
FROM chef as planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# build
FROM chef as builder
COPY --from=planner /build/recipe.json recipe.json
# build deps(cached)
RUN cargo chef cook --release --recipe-path recipe.json
# build bin
COPY . .
RUN cargo build --release
# change binary name to /app/bin
FROM alpine as tmp
WORKDIR /app
COPY --from=metadata /build/app_name /tmp
COPY --from=builder /build/target/release /build
RUN cp /build/$(cat /tmp/app_name) bin
FROM gcr.io/distroless/cc
WORKDIR /app
COPY --from=tmp /app/bin .
CMD ["/app/bin"]