]> Repositorios git - scryer-prolog.git/commitdiff
Managed to create a 77MB scryer-prolog Docker image
authorpanasenco <[email protected]>
Sun, 17 May 2020 04:04:45 +0000 (21:04 -0700)
committerpanasenco <[email protected]>
Mon, 18 May 2020 03:50:34 +0000 (20:50 -0700)
Dockerfile

index bdaa9b5833afc4a063b19aede5fbe2f4c343ae0c..3b2c3a05837fd2135d45b745c9092758a6fd90f8 100755 (executable)
@@ -1,33 +1,30 @@
-# Based on https://blog.sedrik.se/posts/my-docker-setup-for-rust/\r
-FROM ekidd/rust-musl-builder as builder\r
+# Based on https://hub.docker.com/_/rust?tab=description and https://hub.docker.com/_/rust?tab=description\r
 \r
-WORKDIR /home/rust/\r
+# The first container is for build purposes only.\r
+FROM rust as builder\r
 \r
-# Install external dependencies\r
-RUN sudo apt-get update\r
-RUN sudo apt-get -y install m4\r
+WORKDIR /usr/src/scryer-prolog\r
 \r
-# Avoid having to install/build all dependencies by copying\r
-# the Cargo files and making a dummy src/main.rs and build.rs\r
+# Using a dummy build.rs and src/main.rs with your Cargo.toml lets Docker cache your Rust dependencies and not rebuild\r
+# them every time.\r
 COPY Cargo.toml .\r
 COPY Cargo.lock .\r
+RUN mkdir -p src\r
 RUN echo "fn main() {}" > src/main.rs\r
 RUN echo "fn main() {}" > build.rs\r
 RUN cargo build --release\r
 \r
 # We need to touch our real main.rs and build.rs files or else\r
-# docker will use the cached one.\r
+# docker will use the cached ones.\r
 COPY . .\r
-RUN sudo touch src/main.rs\r
-RUN sudo touch build.rs\r
+RUN touch src/main.rs\r
+RUN touch build.rs\r
 \r
 RUN cargo build --release\r
 \r
-# Size optimization\r
-# RUN strip target/x86_64-unknown-linux-musl/release/scryer-prolog\r
+RUN ls ./target/release\r
 \r
-# Start building the final image\r
-FROM scratch\r
-WORKDIR /home/rust/\r
-COPY --from=builder /home/rust/target/x86_64-unknown-linux-musl/release/scryer-prolog .\r
-ENTRYPOINT ["./scryer-prolog"]\r
+# Finally, copy the scryer-prolog executable to a slimmer container.\r
+FROM debian:buster-slim\r
+COPY --from=builder /usr/src/scryer-prolog/target/release/scryer-prolog /usr/local/bin/scryer-prolog\r
+CMD ["scryer-prolog"]\r