From 1ae9c99b2db1e893c6f703f2b1c59b2c954de783 Mon Sep 17 00:00:00 2001 From: Andreas Maerten <24669514+Yimura@users.noreply.github.com> Date: Thu, 14 Nov 2024 19:17:48 +0100 Subject: [PATCH] fix(Docker): improve build and compose files (#255) * fix(Docker): improve build and compose files - Adapted `Dockerfile` so the PWD will point to the `/config` folder in the image - Modified the `docker-compose.yml` to follow the Dockerfile logic - Added a LABEL to the docker image so it points to the source code * refactor(Dockerfile): comment WORKDIR /config instruction * feat(Dockerfile): move back to `/pumpkin` as root folder --- Dockerfile | 21 ++++++++++++++++++--- docker-compose.yml | 3 +-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index ffc927100..886b5200b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,33 @@ FROM rust:1-alpine3.20 AS builder ENV RUSTFLAGS="-C target-feature=-crt-static -C target-cpu=native" RUN apk add --no-cache musl-dev + WORKDIR /pumpkin COPY . /pumpkin + +# build release RUN --mount=type=cache,sharing=private,target=/pumpkin/target \ --mount=type=cache,target=/usr/local/cargo/git/db \ --mount=type=cache,target=/usr/local/cargo/registry/ \ cargo build --release && cp target/release/pumpkin ./pumpkin.release + +# strip debug symbols from binary RUN strip pumpkin.release FROM alpine:3.20 -WORKDIR /pumpkin + +# Identifying information for registries like ghcr.io +LABEL org.opencontainers.image.source=https://github.com/Snowiiii/Pumpkin + RUN apk add --no-cache libgcc -COPY --from=builder /pumpkin/pumpkin.release /pumpkin/pumpkin + +COPY --from=builder /pumpkin/pumpkin.release /bin/pumpkin + +# set workdir to /pumpkin, this is required to influence the PWD environment variable +# it allows for bind mounting the server files without overwriting the pumpkin +# executable (without requiring an `docker cp`-ing the binary to the host folder) +WORKDIR /pumpkin + ENV RUST_BACKTRACE=1 EXPOSE 25565 -ENTRYPOINT ["/pumpkin/pumpkin"] +ENTRYPOINT [ "/bin/pumpkin" ] diff --git a/docker-compose.yml b/docker-compose.yml index e559259ba..a8c019a08 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,5 +4,4 @@ services: ports: - 25565:25565 volumes: - - ./configuration.toml:/pumpkin/configuration.toml - - ./features.toml:/pumpkin/features.toml + - ./data:/pumpkin