From 7bc15f97de13b08fc0372cddd281820bc0488b2b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 22 Feb 2025 03:13:43 +0100 Subject: [PATCH 1/4] docker: viewer: use nginx:alpine-slim as base --- viewer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/viewer/Dockerfile b/viewer/Dockerfile index 794bcf5..524fd4c 100644 --- a/viewer/Dockerfile +++ b/viewer/Dockerfile @@ -1,3 +1,3 @@ -FROM docker.io/library/nginx:alpine +FROM docker.io/library/nginx:alpine-slim COPY . /usr/share/nginx/html # datadir should be mounted to: /usr/share/nginx/html/data From 282f62fc30352fa1ea801c2ae7652e538a922eb4 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 22 Feb 2025 04:02:10 +0100 Subject: [PATCH 2/4] docker: run minedmap as unpriviledged user --- Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index e052309..bb0e0ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,12 @@ RUN strip target/release/minedmap FROM docker.io/library/alpine:latest +RUN addgroup -g 1000 -S minedmap \ + && adduser -S -D -H -u 1000 -h /output -s /sbin/nologin -G minedmap -g minedmap minedmap + RUN apk add --no-cache libgcc tini COPY --from=builder /build/target/release/minedmap /bin/minedmap ENTRYPOINT [ "/sbin/tini", "--", "/bin/minedmap" ] + +USER minedmap:minedmap From 8cb1eee60b82b0bfe00f3260ece281b269cd04fb Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 22 Feb 2025 11:06:46 +0100 Subject: [PATCH 3/4] docker, ci: fix --version output When building the docker image manually, MINEDMAP_VERSION needs to be set explicitly to get a proper version string. --- .github/workflows/MinedMap.yml | 12 ++++++++++++ Dockerfile | 2 ++ src/core/mod.rs | 18 ++++++++++++------ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.github/workflows/MinedMap.yml b/.github/workflows/MinedMap.yml index 2aef1ec..24895c9 100644 --- a/.github/workflows/MinedMap.yml +++ b/.github/workflows/MinedMap.yml @@ -154,6 +154,16 @@ jobs: needs: - test steps: + - name: 'Checkout' + uses: 'actions/checkout@v4' + + - name: 'Get version' + id: 'tag' + run: | + set -o pipefail + git fetch --prune --unshallow --tags -f + echo "tag=$(git describe --abbrev=7 --match='v*' | sed 's/^v//')" >> $GITHUB_OUTPUT + - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -182,6 +192,8 @@ jobs: - name: Build uses: docker/build-push-action@v6 with: + build-args: | + MINEDMAP_VERSION=${{ steps.tag.outputs.tag }} push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index bb0e0ad..49965db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM docker.io/library/alpine:latest AS builder +ARG MINEDMAP_VERSION + WORKDIR /build RUN apk add --no-cache build-base cmake cargo diff --git a/src/core/mod.rs b/src/core/mod.rs index 202d017..a16f620 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -33,17 +33,23 @@ use tracing::{info, warn}; use self::entity_collector::EntityCollector; -/// MinedMap version number -const VERSION: &str = git_version!( - args = ["--abbrev=7", "--match=v*", "--dirty=-modified"], - cargo_prefix = "v", -); +/// Returns the MinedMap version number +fn version() -> &'static str { + option_env!("MINEDMAP_VERSION").unwrap_or( + git_version!( + args = ["--abbrev=7", "--match=v*", "--dirty=-modified"], + cargo_prefix = "v", + ) + .strip_prefix("v") + .unwrap(), + ) +} /// Command line arguments for minedmap CLI #[derive(Debug, Parser)] #[command( about, - version = VERSION.strip_prefix("v").unwrap(), + version = version(), max_term_width = 100, )] pub struct Args { From 90f2c5fdd05286037512380950a9fe076fe26600 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 22 Feb 2025 04:03:08 +0100 Subject: [PATCH 4/4] docker: add example docker-compose.yml --- docker-compose.yml | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5954ba7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,51 @@ +# This is an example docker-compose configuration providing a Minecraft server, +# map generator and webserver. Visit http://localhost:8080 to view the map. +# +# See https://docker-minecraft-server.readthedocs.io/ for more information on +# the itzg/minecraft-server image and its configuration. + +services: + mc: + image: docker.io/itzg/minecraft-server + environment: + EULA: 'true' + ports: + - '25565:25565' + volumes: + - data:/data + stdin_open: true + tty: true + restart: unless-stopped + + minedmap: + image: ghcr.io/neocturne/minedmap/minedmap + command: + - '--jobs-initial=2' + - '--image-format=webp' + - '--sign-filter=\[Map\]' + - '--sign-transform=s/\[Map\]//' + - '--watch' + - '/input/world' + - '/output' + volumes: + - data:/input + - output:/output + - processed:/output/processed + network_mode: 'none' + depends_on: + mc: + condition: service_healthy + restart: unless-stopped + + viewer: + image: ghcr.io/neocturne/minedmap/viewer + ports: + - '8080:80' + volumes: + - output:/usr/share/nginx/html/data + restart: unless-stopped + +volumes: + data: {} + processed: {} + output: {}