Skip to content

Commit

Permalink
feat: use cargo cheff
Browse files Browse the repository at this point in the history
  • Loading branch information
Alw3ys committed Mar 14, 2024
1 parent 1dd8ab2 commit 93da346
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 93da346

Please sign in to comment.