forked from roapi/roapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
51 lines (44 loc) · 1.44 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
ARG RUST_VER=1.78.0-bookworm
ARG RUSTFLAGS='-C target-cpu=skylake'
ARG FEATURES="database"
# Step 0: Install cargo-chef
FROM rust:${RUST_VER} AS chef
# We only pay the installation cost once,
# it will be cached from the second build onwards
RUN cargo install cargo-chef
# install cmake for snmalloc
RUN apt-get update \
&& apt-get install --no-install-recommends -y cmake
# Step 1: Compute a recipe file
FROM chef AS planner
WORKDIR /roapi_src
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# Step 2: Cache project dependencies
FROM chef AS cacher
ARG RUSTFLAGS
ARG FEATURES
WORKDIR /roapi_src
COPY --from=planner /roapi_src/recipe.json recipe.json
RUN RUSTFLAGS=${RUSTFLAGS} \
cargo chef cook --features ${FEATURES} --release --recipe-path recipe.json
# Step 3: Build the release binary
FROM chef AS builder
ARG RUSTFLAGS
ARG FEATURES
WORKDIR /roapi_src
COPY ./ /roapi_src
COPY --from=cacher /roapi_src/target target
COPY --from=cacher /usr/local/cargo /usr/local/cargo
RUN RUSTFLAGS=${RUSTFLAGS} \
cargo build --release --locked --bin roapi --features ${FEATURES}
# Step 4: Assemble the final image
FROM debian:bookworm-slim
LABEL org.opencontainers.image.source https://github.com/roapi/roapi
RUN apt-get update \
&& apt-get install -y libssl-dev ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY test_data /test_data
COPY --from=builder /roapi_src/target/release/roapi /usr/local/bin/roapi
EXPOSE 8080
ENTRYPOINT ["roapi"]