From 33a8262334d273989167cfa0d2521ad3aae4007c Mon Sep 17 00:00:00 2001 From: panasenco Date: Sat, 16 May 2020 16:30:47 -0700 Subject: [PATCH] New Dockerfile based on Fredrik Park's blog post - compilation fails with linker error --- Dockerfile | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index e1681837..bdaa9b58 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,33 @@ -FROM rust:slim +# Based on https://blog.sedrik.se/posts/my-docker-setup-for-rust/ +FROM ekidd/rust-musl-builder as builder -WORKDIR ~/scryer-prolog +WORKDIR /home/rust/ + +# Install external dependencies +RUN sudo apt-get update +RUN sudo apt-get -y install m4 + +# Avoid having to install/build all dependencies by copying +# the Cargo files and making a dummy src/main.rs and build.rs +COPY Cargo.toml . +COPY Cargo.lock . +RUN echo "fn main() {}" > src/main.rs +RUN echo "fn main() {}" > build.rs +RUN cargo build --release + +# We need to touch our real main.rs and build.rs files or else +# docker will use the cached one. COPY . . +RUN sudo touch src/main.rs +RUN sudo touch build.rs + +RUN cargo build --release -RUN cargo --version -RUN cargo install --path . +# Size optimization +# RUN strip target/x86_64-unknown-linux-musl/release/scryer-prolog -CMD ["scryer-prolog"] +# Start building the final image +FROM scratch +WORKDIR /home/rust/ +COPY --from=builder /home/rust/target/x86_64-unknown-linux-musl/release/scryer-prolog . +ENTRYPOINT ["./scryer-prolog"] -- 2.54.0