FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.67.0 as chef FROM chef as diesel RUN cargo install diesel_cli --no-default-features --features postgres FROM chef as planner WORKDIR /usr/src/backend RUN mkdir src && touch src/main.rs COPY ./Cargo.toml ./Cargo.lock ./ RUN cargo chef prepare --recipe-path recipe.json FROM chef as builder WORKDIR /usr/src/backend COPY --from=planner /usr/src/backend/recipe.json . RUN cargo chef cook --release --recipe-path recipe.json RUN rm -rf ./src COPY ./src ./src RUN cargo build --release FROM docker.io/debian:bullseye-slim as runner RUN apt update RUN apt install -y libpq5 RUN apt install -y ca-certificates RUN apt-get clean RUN apt-get autoremove -y RUN rm -rf /var/lib/{apt,dpkg,cache,log}/ WORKDIR /usr/local/bin ENV RUST_BACKTRACE=full COPY --from=diesel /usr/local/cargo/bin/diesel . WORKDIR /usr/src/backend COPY ./run.sh . RUN chmod +x ./run.sh COPY ./migrations ./migrations COPY --from=builder /usr/src/backend/target/release/backend /usr/src/backend/target/release/blogctl ./bin/ EXPOSE 80 ENTRYPOINT [ "./run.sh" ]