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