Switched to cargo-chef for preparing the Docker image

This commit is contained in:
panasenco
2021-04-12 14:54:15 -07:00
parent 8188e3d0cf
commit bec8d36961

View File

@@ -1,30 +1,24 @@
# Based on https://hub.docker.com/_/rust?tab=description and https://blog.sedrik.se/posts/my-docker-setup-for-rust/ # See https://github.com/LukeMathWalker/cargo-chef
FROM lukemathwalker/cargo-chef as planner
# The first container is for build purposes only. WORKDIR /scryer-prolog
FROM rust as builder COPY . .
RUN cargo chef prepare --recipe-path recipe.json
WORKDIR /usr/src/scryer-prolog
FROM lukemathwalker/cargo-chef as cacher
# Using a dummy build.rs and src/main.rs with your Cargo.toml lets Docker cache your Rust dependencies and not rebuild WORKDIR /scryer-prolog
# them every time. COPY --from=planner /scryer-prolog/recipe.json recipe.json
COPY Cargo.toml . RUN cargo chef cook --release --recipe-path recipe.json
COPY Cargo.lock .
RUN mkdir -p src FROM rust as builder
RUN echo "fn main() {}" > src/main.rs WORKDIR /scryer-prolog
RUN echo "fn main() {}" > build.rs COPY . .
RUN cargo build --release # Copy over the cached dependencies
COPY --from=cacher /scryer-prolog/target target
# We need to touch our real main.rs and build.rs files or else COPY --from=cacher $CARGO_HOME $CARGO_HOME
# docker will use the cached ones. RUN cargo build --release --bin scryer-prolog
COPY . .
RUN touch src/main.rs FROM debian:stable-slim
RUN touch build.rs WORKDIR scryer-prolog
COPY --from=builder /scryer-prolog/target/release/scryer-prolog /usr/local/bin
RUN cargo build --release ENV RUST_BACKTRACE=1
ENTRYPOINT ["/usr/local/bin/scryer-prolog"]
RUN ls ./target/release
# Finally, copy the scryer-prolog executable to a slimmer container.
FROM debian:buster-slim
COPY --from=builder /usr/src/scryer-prolog/target/release/scryer-prolog /usr/local/bin/scryer-prolog
CMD ["scryer-prolog"]