From cb5b3798b0dcac17c59751b00b625d9dbdc58078 Mon Sep 17 00:00:00 2001 From: Miraculous Owonubi Date: Mon, 17 Apr 2023 23:12:09 +0100 Subject: [PATCH] docker: util RUN --mount=type=cache... downside is this doesn't play well with BuildKit's cache-to, cache-from. affecting our ability to push cache to GH https://github.com/moby/buildkit/issues/1673 --- .dockerignore | 1 - Dockerfile | 21 ++++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.dockerignore b/.dockerignore index afef96a88..18f93b5bb 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,6 +4,5 @@ .gitattributes target/ -!target/cache Dockerfile .dockerignore diff --git a/Dockerfile b/Dockerfile index 9ea80c6f4..0804e0dbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,22 +5,17 @@ RUN apt-get update \ apt-get install --no-install-recommends --assume-yes \ protobuf-compiler libprotobuf-dev COPY . . -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 +RUN --mount=type=cache,target=/usr/src/app/target \ + --mount=type=cache,target=/usr/local/cargo/git \ + --mount=type=cache,target=/usr/local/cargo/registry/cache \ + --mount=type=cache,target=/usr/local/cargo/registry/index \ + CARGO_INCREMENTAL=0 cargo build --release --package mpc-recovery \ + && \ + cp ./target/release/mpc-recovery /usr/local/bin/mpc-recovery FROM debian:buster-slim as runtime RUN apt-get update && apt-get install --assume-yes libssl-dev -COPY --from=builder /usr/src/app/target/release/mpc-recovery /usr/local/bin/mpc-recovery +COPY --from=builder /usr/local/bin/mpc-recovery /usr/local/bin/mpc-recovery WORKDIR /usr/local/bin ENTRYPOINT [ "mpc-recovery" ]