From 93da346c74159edb52d7f169da0b2959e718bfff Mon Sep 17 00:00:00 2001 From: Alw3ys Date: Thu, 14 Mar 2024 21:40:47 +0100 Subject: [PATCH] feat: use cargo cheff --- Dockerfile | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index ddc40b67..c3151399 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,39 @@ -FROM rust:1.76.0 as builder +ARG RUST_VERSION=1.76.0 +FROM lukemathwalker/cargo-chef:0.1.66-rust-$RUST_VERSION as chef ENV SQLX_OFFLINE=true +WORKDIR /app +RUN apt-get update && apt-get install build-essential protobuf-compiler python3.11-dev -y -WORKDIR /usr/src/dosei - -RUN apt-get update && apt-get install -y build-essential protobuf-compiler python3.11-dev - +FROM chef AS planner COPY . . +RUN cargo chef prepare --recipe-path recipe.json -RUN --mount=type=cache,target=target cargo build --release - -RUN mkdir release -RUN --mount=type=cache,target=target cp target/release/doseid release/doseid -RUN --mount=type=cache,target=target cp target/release/dctl release/dctl -RUN --mount=type=cache,target=target cp target/release/proxy release/proxy +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +# Build dependencies - this is the caching Docker layer! +RUN cargo chef cook --release --recipe-path recipe.json +# Build application +COPY . . +RUN cargo build --release -FROM rust:1.76.0 +FROM debian:12-slim AS runtime -RUN apt-get update && apt-get install -y python3.11-dev +LABEL org.opencontainers.image.title="Dosei" +LABEL org.opencontainers.image.description="Official Dosei image" +LABEL org.opencontainers.image.url="https://dosei.ai" +LABEL org.opencontainers.image.documentation="https://dosei.ai/docs" +LABEL org.opencontainers.image.source="https://github.com/doseiai/dosei" +LABEL org.opencontainers.image.vendor="Dosei" -ARG RELEASE_PATH=/usr/src/dosei/release -ARG DOSEID_INSTALL=/bin/doseid -ARG DOSEI_CLI_INSTALL=/bin/dctl -ARG DOSEI_PROXY_INSTALL=/bin/dosei-proxy +RUN apt-get update && apt-get install python3.11-dev -y -COPY --from=builder ${RELEASE_PATH}/doseid ${DOSEID_INSTALL} -COPY --from=builder ${RELEASE_PATH}/dctl ${DOSEI_CLI_INSTALL} -COPY --from=builder ${RELEASE_PATH}/proxy ${DOSEI_PROXY_INSTALL} +WORKDIR /app +ARG RELEASE_PATH=/app/target/release +ARG TAGET_PATH=/usr/local/bin -RUN chmod +x ${DOSEID_INSTALL} ${DOSEI_CLI_INSTALL} ${DOSEI_PROXY_INSTALL} +COPY --from=builder $RELEASE_PATH/doseid $TAGET_PATH +COPY --from=builder $RELEASE_PATH/dctl $TAGET_PATH +COPY --from=builder $RELEASE_PATH/proxy $TAGET_PATH -CMD ["/bin/doseid"] +ENTRYPOINT ["/usr/local/bin/doseid"]