From 9b4f7ad696b1f4384fd30bc349045db8fc82fa4e Mon Sep 17 00:00:00 2001 From: panasenco Date: Sat, 16 May 2020 15:57:50 -0700 Subject: [PATCH 1/4] Created initial working Docker deployment --- .dockerignore | 6 ++++++ Dockerfile | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100755 .dockerignore create mode 100755 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100755 index 00000000..050103c6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +target +Dockerfile +README.md +.git +.gitignore +.gitmodules diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 00000000..e1681837 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM rust:slim + +WORKDIR ~/scryer-prolog +COPY . . + +RUN cargo --version +RUN cargo install --path . + +CMD ["scryer-prolog"] From 33a8262334d273989167cfa0d2521ad3aae4007c Mon Sep 17 00:00:00 2001 From: panasenco Date: Sat, 16 May 2020 16:30:47 -0700 Subject: [PATCH 2/4] 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 --version -RUN cargo install --path . +RUN cargo build --release -CMD ["scryer-prolog"] +# Size optimization +# RUN strip target/x86_64-unknown-linux-musl/release/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"] From 5639f40994fb47fc2ea717618bea647dd54a1702 Mon Sep 17 00:00:00 2001 From: panasenco Date: Sat, 16 May 2020 21:04:45 -0700 Subject: [PATCH 3/4] Managed to create a 77MB scryer-prolog Docker image --- Dockerfile | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index bdaa9b58..3b2c3a05 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,30 @@ -# Based on https://blog.sedrik.se/posts/my-docker-setup-for-rust/ -FROM ekidd/rust-musl-builder as builder +# Based on https://hub.docker.com/_/rust?tab=description and https://hub.docker.com/_/rust?tab=description -WORKDIR /home/rust/ +# The first container is for build purposes only. +FROM rust as builder -# Install external dependencies -RUN sudo apt-get update -RUN sudo apt-get -y install m4 +WORKDIR /usr/src/scryer-prolog -# Avoid having to install/build all dependencies by copying -# the Cargo files and making a dummy src/main.rs and build.rs +# Using a dummy build.rs and src/main.rs with your Cargo.toml lets Docker cache your Rust dependencies and not rebuild +# them every time. COPY Cargo.toml . COPY Cargo.lock . +RUN mkdir -p src 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. +# docker will use the cached ones. COPY . . -RUN sudo touch src/main.rs -RUN sudo touch build.rs +RUN touch src/main.rs +RUN touch build.rs RUN cargo build --release -# Size optimization -# RUN strip target/x86_64-unknown-linux-musl/release/scryer-prolog +RUN ls ./target/release -# 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"] +# Finally, copy the scryer-prolog executable to a slimmer container. +FROM debian:buster-slim +COPY --from=builder /usr/src/scryer-prolog/target/release/scryer-prolog /usr/local/bin/scryer-prolog +CMD ["scryer-prolog"] From a7fd3c50e5a7dbec2b93cc3e88f39dfdb4199a28 Mon Sep 17 00:00:00 2001 From: panasenco Date: Sun, 17 May 2020 20:49:44 -0700 Subject: [PATCH 4/4] Updated README with Docker install instructions --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index ed9161f5..fbb8bb9a 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,8 @@ strings. ## Installing Scryer Prolog +### Native Install (Unix Only) + First, install the latest stable version of [Rust](https://www.rust-lang.org/en-US/install.html) using your preferred method. Scryer tends to use features from newer Rust @@ -126,6 +128,26 @@ $> cargo run [--release] The optional `--release` flag will perform various optimizations, producing a faster executable. +### Docker Install (All Platforms) + +To automatically download, install, and run Scryer Prolog via Docker, +simply run: +``` +$> docker run -it mthom/scryer-prolog +``` + +To be able to load your program files, bind mount your programs folder +as a Docker volume: + +``` +$> docker run -v /home/user/prolog:/mnt -it mthom/scryer-prolog +?- consult('mnt/program.pl'). +true. +``` + +[Docker](https://hub.docker.com/editions/community/docker-ce-desktop-windows) +is currently the only way to run scryer-prolog on Windows. + ## Tutorial Prolog files are loaded by specifying them as arguments on the command