From ab5342c031789a61c3980304d150236f6d88c934 Mon Sep 17 00:00:00 2001 From: Erb3 <49862976+Erb3@users.noreply.github.com> Date: Tue, 20 Aug 2024 19:38:46 +0200 Subject: [PATCH 1/5] feat: initial docker support --- .dockerignore | 12 ++++++++++++ Dockerfile | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..5c5187748 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +# A whitelist of files that should be included into docker +# Put an exclaimation mark before everything to include + +# Ignore everything +* + +# Allow the source code folders +!/pumpkin*/ + +# Dependencies +!Cargo.lock +!Cargo.toml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..ea678f677 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM rust:1.79 AS builder +WORKDIR /usr/src/pumpkin +COPY . . +RUN ls +RUN cargo install --path ./pumpkin + +FROM rust +WORKDIR /pumpkin +RUN apt update && apt-get install -y libssl-dev pkg-config ca-certificates && rm -rf /var/lib/apt/lists/* +COPY --from=builder /usr/local/cargo/bin/pumpkin /pumpkin/pumpkin +CMD ["/pumpkin/pumpkin"] + +# FROM rust:1.79-alpine AS builder +# WORKDIR /usr/src/pumpkin +# COPY . . +# RUN apk add openssl-dev libssl3 ca-certificates pkgconfig musl-dev +# RUN cargo install --path ./pumpkin + +# FROM rust:1.79-alpine +# WORKDIR /pumpkin +# RUN apk add openssl ca-certificates pkgconfig +# COPY --from=builder /usr/local/cargo/bin/pumpkin /pumpkin/pumpkin +# CMD ["/pumpkin/pumpkin"] + +#docker run --rm -v "./world:/pumpkin/world" pumpkin From e6e63c6c1e7c83c398998b33f076e184896947b7 Mon Sep 17 00:00:00 2001 From: Erb3 <49862976+Erb3@users.noreply.github.com> Date: Wed, 21 Aug 2024 18:01:25 +0200 Subject: [PATCH 2/5] docs: simple docker instructions --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index b0c341e70..32f57450d 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,21 @@ Then run: RUSTFLAGS="-C target-cpu=native" cargo run --release ``` +### Docker + +Experimental Docker support is available. +The image is currently not published anywhere, but you can use the following command to build it: + +```shell +docker build . -t pumpkin +``` + +To run it use the following command: + +```shell +docker run --rm -v "./world:/pumpkin/world" pumpkin +``` + ## Contributions Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) From c64cdb23662799a7c9ff28189fab83ed9b7ff149 Mon Sep 17 00:00:00 2001 From: Erb3 <49862976+Erb3@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:00:18 +0200 Subject: [PATCH 3/5] fix: apply patch for command spam --- pumpkin/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index e4db13870..cc9ef23b5 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -94,7 +94,10 @@ fn main() -> io::Result<()> { stdin .read_line(&mut out) .expect("Failed to read console line"); - handle_command(&mut commands::CommandSender::Console, &out); + + if !out.is_empty() { + handle_command(&mut commands::CommandSender::Console, &out); + } } }); } From 303594d908660e8bb2cc9cb16a6665afa568afbe Mon Sep 17 00:00:00 2001 From: Erb3 <49862976+Erb3@users.noreply.github.com> Date: Sat, 24 Aug 2024 13:18:09 +0200 Subject: [PATCH 4/5] refactor(docker): move to alpine for smaller image --- Dockerfile | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index ea678f677..a3dd5b33b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,13 @@ -FROM rust:1.79 AS builder -WORKDIR /usr/src/pumpkin -COPY . . -RUN ls -RUN cargo install --path ./pumpkin - -FROM rust +FROM rust:1-alpine3.19 AS builder +ENV RUSTFLAGS="-C target-feature=-crt-static" +RUN apk add --no-cache musl-dev WORKDIR /pumpkin -RUN apt update && apt-get install -y libssl-dev pkg-config ca-certificates && rm -rf /var/lib/apt/lists/* -COPY --from=builder /usr/local/cargo/bin/pumpkin /pumpkin/pumpkin -CMD ["/pumpkin/pumpkin"] - -# FROM rust:1.79-alpine AS builder -# WORKDIR /usr/src/pumpkin -# COPY . . -# RUN apk add openssl-dev libssl3 ca-certificates pkgconfig musl-dev -# RUN cargo install --path ./pumpkin +COPY . /pumpkin +RUN cargo build --release +RUN strip target/release/pumpkin -# FROM rust:1.79-alpine -# WORKDIR /pumpkin -# RUN apk add openssl ca-certificates pkgconfig -# COPY --from=builder /usr/local/cargo/bin/pumpkin /pumpkin/pumpkin -# CMD ["/pumpkin/pumpkin"] - -#docker run --rm -v "./world:/pumpkin/world" pumpkin +FROM alpine:3.19 +WORKDIR /pumpkin +RUN apk add --no-cache libgcc +COPY --from=builder /pumpkin/target/release/pumpkin /pumpkin/pumpkin +ENTRYPOINT ["/pumpkin/pumpkin"] From a97551583b5c996bdd7b86988cc328909e8f266e Mon Sep 17 00:00:00 2001 From: Erb3 <49862976+Erb3@users.noreply.github.com> Date: Sat, 24 Aug 2024 13:28:04 +0200 Subject: [PATCH 5/5] feat(docker): enable target-cpu=native --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a3dd5b33b..69631ab81 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM rust:1-alpine3.19 AS builder -ENV RUSTFLAGS="-C target-feature=-crt-static" +ENV RUSTFLAGS="-C target-feature=-crt-static -C target-cpu=native" RUN apk add --no-cache musl-dev WORKDIR /pumpkin COPY . /pumpkin