Skip to content

Commit

Permalink
docker: play nicely with cargo's incremental compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
miraclx committed Apr 14, 2023
1 parent 5114e37 commit 96c3ecb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
.gitattributes

target/
!target/cache
Dockerfile
.dockerignore
18 changes: 12 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
protobuf-compiler libprotobuf-dev
RUN echo "fn main() {}" > dummy.rs
COPY mpc-recovery/Cargo.toml Cargo.toml
RUN sed -i 's#src/main.rs#dummy.rs#' Cargo.toml
RUN sed -i 's#mpc-recovery-gcp = { path = "../mpc-recovery-gcp" }##' Cargo.toml
RUN cargo build --release
COPY . .
RUN cargo build --release --package mpc-recovery
COPY ./targe[t]/cach[e]/us[r]/ /usr/
RUN rm -rf ./target/cache
RUN CARGO_INCREMENTAL=0 cargo build --release --package mpc-recovery

FROM scratch as export-artifacts
COPY --from=builder /usr/src/app/target /usr/src/app/target
COPY --from=builder /usr/local/cargo/bin /usr/local/cargo/bin
COPY --from=builder /usr/local/cargo/git* /usr/local/cargo/git
COPY --from=builder /usr/local/cargo/.crate.toml* /usr/local/cargo/.crate.toml
COPY --from=builder /usr/local/cargo/.crate2.toml* /usr/local/cargo/.crate2.toml
COPY --from=builder /usr/local/cargo/registry/cache /usr/local/cargo/registry/cache
COPY --from=builder /usr/local/cargo/registry/index /usr/local/cargo/registry/index

FROM debian:buster-slim as runtime
RUN apt-get update && apt-get install --assume-yes libssl-dev
Expand Down

0 comments on commit 96c3ecb

Please sign in to comment.