From 7ac4f82a859c35ad68780aff140d99dfb65bc2a2 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Wed, 13 Jan 2021 14:21:38 +0100 Subject: [PATCH 1/5] Updated papermc --- minecraft/papermc/.env.example | 4 ++-- minecraft/papermc/Dockerfile | 17 ++++++++++------- minecraft/papermc/docker-compose.yml | 22 +++++++++++++--------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/minecraft/papermc/.env.example b/minecraft/papermc/.env.example index 71b3bdf..a9aa5f8 100644 --- a/minecraft/papermc/.env.example +++ b/minecraft/papermc/.env.example @@ -23,8 +23,8 @@ XMS=4 XMX=4 # Mount points -CONFIG_DIR= -WORLDS_DIR= +CONFIG_DIR=config +WORLDS_DIR=worlds # Other PORT=25565 diff --git a/minecraft/papermc/Dockerfile b/minecraft/papermc/Dockerfile index 75fa54f..6952e3c 100644 --- a/minecraft/papermc/Dockerfile +++ b/minecraft/papermc/Dockerfile @@ -21,23 +21,26 @@ ARG MC_VERSION ARG PAPERMC_VERSION # Create worlds and config directory -WORKDIR /mc +WORKDIR /app RUN mkdir worlds config # Download server file ADD "https://papermc.io/api/v1/paper/$MC_VERSION/$PAPERMC_VERSION/download" server.jar # Store the cache in an anonymous volume, which means it won't get stored in the other volumes -VOLUME /mc/config/cache +VOLUME /app/config/cache -WORKDIR /mc/config +WORKDIR /app/config # Default value to keep users from eating up all ram accidentally ENV XMS=4 +# Document exposed ports +EXPOSE 25565 + # We copy over the server jar(s) as well to make the backup more reproducible to deploy -ENTRYPOINT mv -n /mc/*.jar /mc/config && \ -echo "eula=true" > /mc/config/eula.txt && \ +ENTRYPOINT mv -n /app/*.jar /app/config && \ +echo "eula=true" > /app/config/eula.txt && \ java \ -Xms"${XMS}G" \ -Xmx"${XMX:-$XMS}G" \ @@ -61,6 +64,6 @@ java \ -XX:MaxTenuringThreshold=1 \ -Dusing.aikars.flags=https://mcflags.emc.gs \ -Daikars.new.flags=true \ --jar /mc/server.jar \ ---universe /mc/worlds \ +-jar /app/server.jar \ +--universe /app/worlds \ --nogui diff --git a/minecraft/papermc/docker-compose.yml b/minecraft/papermc/docker-compose.yml index b0dd0d1..0ecdaa8 100644 --- a/minecraft/papermc/docker-compose.yml +++ b/minecraft/papermc/docker-compose.yml @@ -19,21 +19,25 @@ services: papermc: build: context: . - dockerfile: Dockerfile args: - - 'MC_VERSION=${MC_VERSION}' - - 'PAPERMC_VERSION=${PAPERMC_VERSION}' - image: 'mc-papermc-server:${MC_VERSION}-${PAPERMC_VERSION}' + - 'MC_VERSION' + - 'PAPERMC_VERSION' + image: 'chewingbever/mc-papermc-server:${MC_VERSION}-${PAPERMC_VERSION}' + restart: 'always' - restart: unless-stopped + # Needed to interact with server console stdin_open: true tty: true environment: - - XMS - - XMX + - 'XMS' + - 'XMX' ports: - '$PORT:25565' volumes: - - '$CONFIG_DIR:/minecraft/config' - - '$WORLDS_DIR:/minecraft/worlds' + - '$CONFIG_DIR:/app/config' + - '$WORLDS_DIR:/app/worlds' + +volumes: + config: + worlds: From 493db5690ef72c6333ea17caa1373cbbd47c0dcd Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Tue, 26 Jan 2021 12:57:29 +0100 Subject: [PATCH 2/5] Updated PaperMC config --- minecraft/papermc/.env.example | 19 +-------- minecraft/papermc/Dockerfile | 62 +++++++--------------------- minecraft/papermc/docker-compose.yml | 3 +- 3 files changed, 19 insertions(+), 65 deletions(-) diff --git a/minecraft/papermc/.env.example b/minecraft/papermc/.env.example index a9aa5f8..84ca0db 100644 --- a/minecraft/papermc/.env.example +++ b/minecraft/papermc/.env.example @@ -1,25 +1,10 @@ -# Copyright (C) 2020 Jef Roosens - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - # Build arguments MC_VERSION= PAPERMC_VERSION= # Environment variables -XMS=4 +# If XMS is left blank, it uses the same value as XMX +XMS= XMX=4 # Mount points diff --git a/minecraft/papermc/Dockerfile b/minecraft/papermc/Dockerfile index 6952e3c..24bf0de 100644 --- a/minecraft/papermc/Dockerfile +++ b/minecraft/papermc/Dockerfile @@ -1,25 +1,16 @@ -# Copyright (C) 2020 Jef Roosens - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - -FROM openjdk:8-slim +FROM openjdk:11-jre-slim # Build arguments ARG MC_VERSION ARG PAPERMC_VERSION +# Install mcstatus for healthchecks +RUN apt update && \ + apt install --no-install-recommends -y python3-minimal python3-setuptools python3-pip && \ + python3 -m pip install mcstatus && \ + apt --purge remove -y python3-pip python3-setuptools && \ + apt clean + # Create worlds and config directory WORKDIR /app RUN mkdir worlds config @@ -30,7 +21,6 @@ ADD "https://papermc.io/api/v1/paper/$MC_VERSION/$PAPERMC_VERSION/download" serv # Store the cache in an anonymous volume, which means it won't get stored in the other volumes VOLUME /app/config/cache -WORKDIR /app/config # Default value to keep users from eating up all ram accidentally ENV XMS=4 @@ -38,32 +28,10 @@ ENV XMS=4 # Document exposed ports EXPOSE 25565 -# We copy over the server jar(s) as well to make the backup more reproducible to deploy -ENTRYPOINT mv -n /app/*.jar /app/config && \ -echo "eula=true" > /app/config/eula.txt && \ -java \ --Xms"${XMS}G" \ --Xmx"${XMX:-$XMS}G" \ --XX:+UseG1GC \ --XX:+ParallelRefProcEnabled \ --XX:MaxGCPauseMillis=200 \ --XX:+UnlockExperimentalVMOptions \ --XX:+DisableExplicitGC \ --XX:+AlwaysPreTouch \ --XX:G1NewSizePercent="$([ $XMS -gt 12 ] && echo 40 || echo 30)" \ --XX:G1MaxNewSizePercent="$([ $XMS -gt 12 ] && echo 50 || echo 40)" \ --XX:G1HeapRegionSize="$([ $XMS -gt 12 ] && echo 16 || echo 8)"M \ --XX:G1ReservePercent="$([ $XMS -gt 12 ] && echo 15 || echo 20)" \ --XX:G1HeapWastePercent=5 \ --XX:G1MixedGCCountTarget=4 \ --XX:InitiatingHeapOccupancyPercent="$([ $XMS -gt 12 ] && echo 20 || echo 15)" \ --XX:G1MixedGCLiveThresholdPercent=90 \ --XX:G1RSetUpdatingPauseTimePercent=5 \ --XX:SurvivorRatio=32 \ --XX:+PerfDisableSharedMem \ --XX:MaxTenuringThreshold=1 \ --Dusing.aikars.flags=https://mcflags.emc.gs \ --Daikars.new.flags=true \ --jar /app/server.jar \ ---universe /app/worlds \ ---nogui +# Entrypoint runs in /app/config +COPY entrypoint.sh /entrypoint.sh +WORKDIR /app/config +ENTRYPOINT /entrypoint.sh + +HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ + CMD mcstatus localhost:25565 ping diff --git a/minecraft/papermc/docker-compose.yml b/minecraft/papermc/docker-compose.yml index 0ecdaa8..bf70e07 100644 --- a/minecraft/papermc/docker-compose.yml +++ b/minecraft/papermc/docker-compose.yml @@ -16,7 +16,7 @@ version: '3.5' services: - papermc: + app: build: context: . args: @@ -38,6 +38,7 @@ services: - '$CONFIG_DIR:/app/config' - '$WORLDS_DIR:/app/worlds' +# These volumes only get created if you use them in the env file volumes: config: worlds: From 11029c3b43949a2145172b90838caf23e2b8e59d Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Tue, 26 Jan 2021 12:58:55 +0100 Subject: [PATCH 3/5] Updated PaperMC READMe --- minecraft/papermc/README.md | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/minecraft/papermc/README.md b/minecraft/papermc/README.md index 335d03c..bfcbed7 100644 --- a/minecraft/papermc/README.md +++ b/minecraft/papermc/README.md @@ -1,23 +1,3 @@ - - - # Build arguments Two build arguments are required, namely `MC_VERSION` and `PAPERMC_VERSION`. You can find your required versions [here](https://papermc.io/downloads). The @@ -36,15 +16,15 @@ Note that the leading `#` doesn't need to be added to the variable. # Environment variables The two possible environment variables are `XMS` and `XMX`. These specify the -initial RAM & maximum RAM usage respectively. Only `XMS` is required; `XMX` is -just set to the same value as `XMS` if not specified. You must specify them as +initial RAM & maximum RAM usage respectively. Only `XMX` is required; `XMS` is +just set to the same value as `XMX` if not specified. You must specify them as a number, e.g. `XMS=4`. This number represents a quantity of gigabytes. # Mount points There a two useful mount points defined: -* `/mc/config`: this is where all server config files reside. -* `/mc/worlds`: this is where the world files are stored. +* `/app/config`: this is where all server config files reside. +* `/app/worlds`: this is where the world files are stored. You can mount these directories somewhere in the host file system by specifying the mount paths in the `.env` file. These can be both absolute or relative @@ -65,8 +45,8 @@ end of the `Dockerfile` to the following: ENTRYPOINT java \ -Xms"${XMS}G" \ -Xmx"${XMX:-$XMS}G" \ --jar /mc/server.jar \ ---universe /mc/worlds \ +-jar /app/server.jar \ +--universe /app/worlds \ --nogui ``` From 67af9ed723a5072d41c7c9d39cda9876b22498f4 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Tue, 26 Jan 2021 13:45:30 +0100 Subject: [PATCH 4/5] Renewed Forge setup --- minecraft/forge/.env.example | 21 ++------ minecraft/forge/Dockerfile | 74 +++++++++------------------- minecraft/forge/docker-compose.yml | 36 +++++--------- minecraft/forge/entrypoint.sh | 37 ++++++++++++++ minecraft/papermc/Dockerfile | 4 +- minecraft/papermc/docker-compose.yml | 18 +------ minecraft/papermc/entrypoint.sh | 37 ++++++++++++++ 7 files changed, 115 insertions(+), 112 deletions(-) create mode 100755 minecraft/forge/entrypoint.sh create mode 100755 minecraft/papermc/entrypoint.sh diff --git a/minecraft/forge/.env.example b/minecraft/forge/.env.example index 3fdd8b5..2669eef 100644 --- a/minecraft/forge/.env.example +++ b/minecraft/forge/.env.example @@ -1,30 +1,15 @@ -# Copyright (C) 2020 Jef Roosens - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - # Build arguments MC_VERSION= FORGE_VERSION= # Environment variables -XMS=4 +# If XMS is left blank, it uses the same value as XMX +XMS= XMX=4 # Mount points +# The mods should be placed inside the CONFIG_DIR under `mods` CONFIG_DIR= -MODS_DIR= WORLDS_DIR= # Other diff --git a/minecraft/forge/Dockerfile b/minecraft/forge/Dockerfile index c398484..796426b 100644 --- a/minecraft/forge/Dockerfile +++ b/minecraft/forge/Dockerfile @@ -1,27 +1,18 @@ -# Copyright (C) 2020 Jef Roosens - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - -FROM openjdk:8-slim +FROM openjdk:8-jre-slim # Build arguments ARG MC_VERSION ARG FORGE_VERSION +# Install mcstatus for healthchecks +RUN apt update && \ + apt install --no-install-recommends -y python3-minimal python3-setuptools python3-pip && \ + python3 -m pip install mcstatus && \ + apt --purge remove -y python3-pip python3-setuptools && \ + apt clean + # Create worlds and config directory -WORKDIR /mc +WORKDIR /app RUN mkdir worlds config # Download installer jar @@ -29,10 +20,7 @@ ADD "https://files.minecraftforge.net/maven/net/minecraftforge/forge/${MC_VERSIO # Install forge & remove installer RUN java -jar installer.jar server --installServer && \ -rm installer.jar installer.jar.log - -# Forge doesn't use one single name, so this is needed to know the name of the executable -ENV FORGE_JAR="forge-${MC_VERSION}-${FORGE_VERSION}.jar" + rm installer.jar installer.jar.log # Store the cache in an anonymous volume, which means it won't get stored in the other volumes VOLUME /mc/config/cache @@ -40,34 +28,16 @@ VOLUME /mc/config/cache WORKDIR /mc/config # Default value to keep users from eating up all ram accidentally -ENV XMS=4 +ENV XMX=4 +ENV MC_VERSION="${MC_VERSION}" +ENV FORGE_VERSION="${FORGE_VERSION}" +# Forge doesn't use one single name, so this is needed to know the name of the executable +ENV FORGE_JAR="forge-${MC_VERSION}-${FORGE_VERSION}.jar" -# We copy over the server jar(s) as well to make the backup more reproducible to deploy -ENTRYPOINT mv -n /mc/*.jar /mc/*.json /mc/libraries /mc/config && \ -echo "eula=true" > /mc/config/eula.txt && \ -java \ --Xms"${XMS}G" \ --Xmx"${XMX:-$XMS}G" \ --XX:+UseG1GC \ --XX:+ParallelRefProcEnabled \ --XX:MaxGCPauseMillis=200 \ --XX:+UnlockExperimentalVMOptions \ --XX:+DisableExplicitGC \ --XX:+AlwaysPreTouch \ --XX:G1NewSizePercent="$([ $XMS -gt 12 ] && echo 40 || echo 30)" \ --XX:G1MaxNewSizePercent="$([ $XMS -gt 12 ] && echo 50 || echo 40)" \ --XX:G1HeapRegionSize="$([ $XMS -gt 12 ] && echo 16 || echo 8)"M \ --XX:G1ReservePercent="$([ $XMS -gt 12 ] && echo 15 || echo 20)" \ --XX:G1HeapWastePercent=5 \ --XX:G1MixedGCCountTarget=4 \ --XX:InitiatingHeapOccupancyPercent="$([ $XMS -gt 12 ] && echo 20 || echo 15)" \ --XX:G1MixedGCLiveThresholdPercent=90 \ --XX:G1RSetUpdatingPauseTimePercent=5 \ --XX:SurvivorRatio=32 \ --XX:+PerfDisableSharedMem \ --XX:MaxTenuringThreshold=1 \ --Dusing.aikars.flags=https://mcflags.emc.gs \ --Daikars.new.flags=true \ --jar "$FORGE_JAR" \ ---universe /mc/worlds \ ---nogui +# Entrypoint runs in /app/config +COPY entrypoint.sh /entrypoint.sh +WORKDIR /app/config +ENTRYPOINT /entrypoint.sh + +HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ + CMD mcstatus localhost:25565 ping diff --git a/minecraft/forge/docker-compose.yml b/minecraft/forge/docker-compose.yml index e2a78b5..5bd5cdf 100644 --- a/minecraft/forge/docker-compose.yml +++ b/minecraft/forge/docker-compose.yml @@ -1,30 +1,14 @@ -# Copyright (C) 2020 Jef Roosens - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - version: '3.5' services: - forge: + app: build: context: . args: - - 'MC_VERSION=${MC_VERSION}' - - 'FORGE_VERSION=${FORGE_VERSION}' - image: 'mc-forge-server:${MC_VERSION}-${FORGE_VERSION}' + - 'MC_VERSION' + - 'FORGE_VERSION' + image: 'chewingbever/mc-forge:${MC_VERSION}-${FORGE_VERSION}' - restart: 'unless-stopped' + restart: 'always' stdin_open: true tty: true @@ -34,6 +18,10 @@ services: ports: - '$PORT:25565' volumes: - - '$CONFIG_DIR:/mc/config' - - '$MODS_DIR:/mc/config/mods' - - '$WORLDS_DIR:/mc/worlds' + - '$CONFIG_DIR:/app/config' + - '$WORLDS_DIR:/app/worlds' + +# These volumes only get created if you use them in the env file +volumes: + config: + worlds: diff --git a/minecraft/forge/entrypoint.sh b/minecraft/forge/entrypoint.sh new file mode 100755 index 0000000..3765418 --- /dev/null +++ b/minecraft/forge/entrypoint.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Accept the EULA +echo "eula=true" > /app/config/eula.txt + +# Log the last-used version, so we know which version to use when running it again (e.g. loading the backup) +echo "${MC_VERSION}, Forge v${FORGE_VERSION}" >> /app/config/versions.txt + +XMS="${XMS:-$XMX}" + +# Launch the actual server +exec java \ + -Xms"${XMS}G" \ + -Xmx"${XMX:-$XMS}G" \ + -XX:+UseG1GC \ + -XX:+ParallelRefProcEnabled \ + -XX:MaxGCPauseMillis=200 \ + -XX:+UnlockExperimentalVMOptions \ + -XX:+DisableExplicitGC \ + -XX:+AlwaysPreTouch \ + -XX:G1NewSizePercent="$([ $XMS -gt 12 ] && echo 40 || echo 30)" \ + -XX:G1MaxNewSizePercent="$([ $XMS -gt 12 ] && echo 50 || echo 40)" \ + -XX:G1HeapRegionSize="$([ $XMS -gt 12 ] && echo 16 || echo 8)"M \ + -XX:G1ReservePercent="$([ $XMS -gt 12 ] && echo 15 || echo 20)" \ + -XX:G1HeapWastePercent=5 \ + -XX:G1MixedGCCountTarget=4 \ + -XX:InitiatingHeapOccupancyPercent="$([ $XMS -gt 12 ] && echo 20 || echo 15)" \ + -XX:G1MixedGCLiveThresholdPercent=90 \ + -XX:G1RSetUpdatingPauseTimePercent=5 \ + -XX:SurvivorRatio=32 \ + -XX:+PerfDisableSharedMem \ + -XX:MaxTenuringThreshold=1 \ + -Dusing.aikars.flags=https://mcflags.emc.gs \ + -Daikars.new.flags=true \ + -jar /app/"$FORGE_JAR" \ + --universe /app/worlds \ + --nogui diff --git a/minecraft/papermc/Dockerfile b/minecraft/papermc/Dockerfile index 24bf0de..291e717 100644 --- a/minecraft/papermc/Dockerfile +++ b/minecraft/papermc/Dockerfile @@ -23,7 +23,9 @@ VOLUME /app/config/cache # Default value to keep users from eating up all ram accidentally -ENV XMS=4 +ENV XMX=4 +ENV MC_VERSION="${MC_VERSION}" +ENV PAPERMC_VERSION="${PAPERMC_VERSION}" # Document exposed ports EXPOSE 25565 diff --git a/minecraft/papermc/docker-compose.yml b/minecraft/papermc/docker-compose.yml index bf70e07..4e77ba5 100644 --- a/minecraft/papermc/docker-compose.yml +++ b/minecraft/papermc/docker-compose.yml @@ -1,19 +1,3 @@ -# Copyright (C) 2020 Jef Roosens - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - version: '3.5' services: app: @@ -22,7 +6,7 @@ services: args: - 'MC_VERSION' - 'PAPERMC_VERSION' - image: 'chewingbever/mc-papermc-server:${MC_VERSION}-${PAPERMC_VERSION}' + image: 'chewingbever/mc-papermc:${MC_VERSION}-${PAPERMC_VERSION}' restart: 'always' # Needed to interact with server console diff --git a/minecraft/papermc/entrypoint.sh b/minecraft/papermc/entrypoint.sh new file mode 100755 index 0000000..1876d54 --- /dev/null +++ b/minecraft/papermc/entrypoint.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Accept the EULA +echo "eula=true" > /app/config/eula.txt + +# Log the last-used version, so we know which version to use when running it again (e.g. loading the backup) +echo "${MC_VERSION}, PaperMC v${PAPERMC_VERSION}" >> /app/config/versions.txt + +XMS="${XMS:-$XMX}" + +# Launch the actual server +java \ + -Xms"${XMS}G" \ + -Xmx"${XMX:-$XMS}G" \ + -XX:+UseG1GC \ + -XX:+ParallelRefProcEnabled \ + -XX:MaxGCPauseMillis=200 \ + -XX:+UnlockExperimentalVMOptions \ + -XX:+DisableExplicitGC \ + -XX:+AlwaysPreTouch \ + -XX:G1NewSizePercent="$([ $XMS -gt 12 ] && echo 40 || echo 30)" \ + -XX:G1MaxNewSizePercent="$([ $XMS -gt 12 ] && echo 50 || echo 40)" \ + -XX:G1HeapRegionSize="$([ $XMS -gt 12 ] && echo 16 || echo 8)"M \ + -XX:G1ReservePercent="$([ $XMS -gt 12 ] && echo 15 || echo 20)" \ + -XX:G1HeapWastePercent=5 \ + -XX:G1MixedGCCountTarget=4 \ + -XX:InitiatingHeapOccupancyPercent="$([ $XMS -gt 12 ] && echo 20 || echo 15)" \ + -XX:G1MixedGCLiveThresholdPercent=90 \ + -XX:G1RSetUpdatingPauseTimePercent=5 \ + -XX:SurvivorRatio=32 \ + -XX:+PerfDisableSharedMem \ + -XX:MaxTenuringThreshold=1 \ + -Dusing.aikars.flags=https://mcflags.emc.gs \ + -Daikars.new.flags=true \ + -jar /app/server.jar \ + --universe /app/worlds \ + --nogui From 2f9490cef6c1bda3e89551fd8c5f15b57131dae6 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Tue, 26 Jan 2021 14:05:59 +0100 Subject: [PATCH 5/5] Updated Fabric & some other stuff --- minecraft/fabric/.env.example | 26 +++------- minecraft/fabric/Dockerfile | 75 +++++++++-------------------- minecraft/fabric/README.md | 52 ++++++++------------ minecraft/fabric/docker-compose.yml | 35 +++++--------- minecraft/fabric/entrypoint.sh | 40 +++++++++++++++ minecraft/forge/README.md | 36 +++----------- minecraft/papermc/README.md | 10 ++-- minecraft/papermc/entrypoint.sh | 2 +- 8 files changed, 116 insertions(+), 160 deletions(-) create mode 100755 minecraft/fabric/entrypoint.sh diff --git a/minecraft/fabric/.env.example b/minecraft/fabric/.env.example index 39b7cb7..08e197c 100644 --- a/minecraft/fabric/.env.example +++ b/minecraft/fabric/.env.example @@ -1,30 +1,16 @@ -# Copyright (C) 2020 Jef Roosens - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - # Build arguments +MC_VERSION= FABRIC_VERSION= # Environment variables -XMS=4 +# If XMS is left blank, it uses the same value as XMX +XMS= XMX=4 # Mount points -CONFIG_DIR= -MODS_DIR= -WORLDS_DIR= +# The mods should be placed inside the CONFIG_DIR under `mods` +CONFIG_DIR=config +WORLDS_DIR=worlds # Other PORT=25565 diff --git a/minecraft/fabric/Dockerfile b/minecraft/fabric/Dockerfile index 3558f9f..35926a5 100644 --- a/minecraft/fabric/Dockerfile +++ b/minecraft/fabric/Dockerfile @@ -1,69 +1,40 @@ -# Copyright (C) 2020 Jef Roosens - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - -FROM openjdk:8-slim +FROM openjdk:8-jre-slim # Build arguments +ARG MC_VERSION ARG FABRIC_VERSION +# Install mcstatus for healthchecks +RUN apt update && \ + apt install --no-install-recommends -y python3-minimal python3-setuptools python3-pip && \ + python3 -m pip install mcstatus && \ + apt --purge remove -y python3-pip python3-setuptools && \ + apt clean + # Create worlds and config directory -WORKDIR /mc +WORKDIR /app RUN mkdir worlds config # Download installer jar ADD "https://maven.fabricmc.net/net/fabricmc/fabric-installer/$FABRIC_VERSION/fabric-installer-$FABRIC_VERSION.jar" installer.jar # Install fabric & remove installer -RUN java -jar installer.jar server -downloadMinecraft && \ -rm installer.jar +RUN java -jar installer.jar server -downloadMinecraft -mcversion "$MC_VERSION" && \ + rm installer.jar # Store the cache in an anonymous volume, which means it won't get stored in the other volumes -VOLUME /mc/config/cache +VOLUME /app/config/cache -WORKDIR /mc/config # Default value to keep users from eating up all ram accidentally -ENV XMS=4 +ENV XMX=4 +ENV MC_VERSION="${MC_VERSION}" +ENV FABRIC_VERSION="${FABRIC_VERSION}" -# We copy over the server jar(s) as well to make the backup more reproducible to deploy -ENTRYPOINT mv -n /mc/*.jar /mc/config && \ -echo "eula=true" > /mc/config/eula.txt && \ -java \ --Xms"${XMS}G" \ --Xmx"${XMX:-$XMS}G" \ --XX:+UseG1GC \ --XX:+ParallelRefProcEnabled \ --XX:MaxGCPauseMillis=200 \ --XX:+UnlockExperimentalVMOptions \ --XX:+DisableExplicitGC \ --XX:+AlwaysPreTouch \ --XX:G1NewSizePercent="$([ $XMS -gt 12 ] && echo 40 || echo 30)" \ --XX:G1MaxNewSizePercent="$([ $XMS -gt 12 ] && echo 50 || echo 40)" \ --XX:G1HeapRegionSize="$([ $XMS -gt 12 ] && echo 16 || echo 8)"M \ --XX:G1ReservePercent="$([ $XMS -gt 12 ] && echo 15 || echo 20)" \ --XX:G1HeapWastePercent=5 \ --XX:G1MixedGCCountTarget=4 \ --XX:InitiatingHeapOccupancyPercent="$([ $XMS -gt 12 ] && echo 20 || echo 15)" \ --XX:G1MixedGCLiveThresholdPercent=90 \ --XX:G1RSetUpdatingPauseTimePercent=5 \ --XX:SurvivorRatio=32 \ --XX:+PerfDisableSharedMem \ --XX:MaxTenuringThreshold=1 \ --Dusing.aikars.flags=https://mcflags.emc.gs \ --Daikars.new.flags=true \ --jar fabric-server-launch.jar \ ---universe /mc/worlds \ ---nogui +# Entrypoint runs in /app/config +COPY entrypoint.sh /entrypoint.sh +WORKDIR /app/config +ENTRYPOINT /entrypoint.sh + +HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ + CMD mcstatus localhost:25565 ping diff --git a/minecraft/fabric/README.md b/minecraft/fabric/README.md index f4575f0..1d98505 100644 --- a/minecraft/fabric/README.md +++ b/minecraft/fabric/README.md @@ -1,41 +1,21 @@ - - - # Build arguments -Only one build argument is required, namely `FABRIC_VERSION`. This is the -version of Fabric you wish to install. You can find the list of versions -[here](https://fabricmc.net/use/). For example, you can then set +Two build arguments are required, namely `MC_VERSION` and `FABRIC_VERSION`. +The latter is the version of Fabric you wish to install. You can find the list +of versions [here](https://fabricmc.net/use/). For example, you can then set `FABRIC_VERSION=0.6.1.51` in the `.env` file. # Environment variables The two possible environment variables are `XMS` and `XMX`. These specify the -initial RAM & maximum RAM usage respectively. Only `XMS` is required; `XMX` is -just set to the same value as `XMS` if not specified. You must specify them as +initial RAM & maximum RAM usage respectively. Only `XMX` is required; `XMS` is +just set to the same value as `XMX` if not specified. You must specify them as a number, e.g. `XMS=4`. This number represents a quantity of gigabytes. # Mount points There a three useful mount points defined: -* `/mc/config`: this is where all server config files reside. -* `/mc/config/mods`: this is where all mods should be placed. -* `/mc/worlds`: this is where the world files are stored. +* `/app/config`: this is where all server config files reside, as well as the + mods. +* `/app/worlds`: this is where the world files are stored. You can mount these directories somewhere in the host file system by specifying the mount paths in the `.env` file. These can be both absolute or relative @@ -54,12 +34,22 @@ end of the `Dockerfile` to the following: ``` ENTRYPOINT java \ --Xms"${XMS}G" \ --Xmx"${XMX:-$XMS}G" \ +-Xms"${XMS:-$XMX}G" \ +-Xmx"${XMX}G" \ -jar fabric-server-launch.jar \ ---universe /mc/worlds \ +--universe /app/worlds \ --nogui ``` This will only use the flags absolutely necessary, while still allowing you to tweak the memory variables. + +# Broken symlink +You might've noticed a broken symlink called `server.jar` in your config +directory. This is an (admittedly ugly) fix for the issue where Fabric expects +the vanilla server jar to be in the current working directory. Considering a +server also has to run within its config directory, this would mean that the +vanilla jar should be in the config directory. As I wanted to keep any +version-specific data out of the config/worlds directories, I have opted to use +a symlink to the server jar in question instead. This symlink can be safely +deleted, and will just get re-created when needed. diff --git a/minecraft/fabric/docker-compose.yml b/minecraft/fabric/docker-compose.yml index bc2b81e..a0baa73 100644 --- a/minecraft/fabric/docker-compose.yml +++ b/minecraft/fabric/docker-compose.yml @@ -1,29 +1,14 @@ -# Copyright (C) 2020 Jef Roosens - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - version: '3.5' services: - fabric: + app: build: context: . args: - - 'FABRIC_VERSION=${FABRIC_VERSION}' - image: 'mc-fabric-server:${FABRIC_VERSION}' + - 'MC_VERSION' + - 'FABRIC_VERSION' + image: 'chewingbever/mc-fabric:${MC_VERSION}-${FABRIC_VERSION}' - restart: 'unless-stopped' + restart: 'always' stdin_open: true tty: true @@ -33,6 +18,10 @@ services: ports: - '$PORT:25565' volumes: - - '$CONFIG_DIR:/mc/config' - - '$MODS_DIR:/mc/config/mods' - - '$WORLDS_DIR:/mc/worlds' + - '$CONFIG_DIR:/app/config' + - '$WORLDS_DIR:/app/worlds' + +# These volumes only get created if you use them in the env file +volumes: + config: + worlds: diff --git a/minecraft/fabric/entrypoint.sh b/minecraft/fabric/entrypoint.sh new file mode 100755 index 0000000..bfe55f5 --- /dev/null +++ b/minecraft/fabric/entrypoint.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# Accept the EULA +echo "eula=true" > /app/config/eula.txt + +# Log the last-used version, so we know which version to use when running it again (e.g. loading the backup) +echo "${MC_VERSION}, Fabric v${FABRIC_VERSION}" >> /app/config/versions.txt + +XMS="${XMS:-$XMX}" + +# Create symlink for server jar +ln -sf ../server.jar server.jar + +# Launch the actual server +exec java \ + -Xms"${XMS}G" \ + -Xmx"${XMX:-$XMS}G" \ + -XX:+UseG1GC \ + -XX:+ParallelRefProcEnabled \ + -XX:MaxGCPauseMillis=200 \ + -XX:+UnlockExperimentalVMOptions \ + -XX:+DisableExplicitGC \ + -XX:+AlwaysPreTouch \ + -XX:G1NewSizePercent="$([ $XMS -gt 12 ] && echo 40 || echo 30)" \ + -XX:G1MaxNewSizePercent="$([ $XMS -gt 12 ] && echo 50 || echo 40)" \ + -XX:G1HeapRegionSize="$([ $XMS -gt 12 ] && echo 16 || echo 8)"M \ + -XX:G1ReservePercent="$([ $XMS -gt 12 ] && echo 15 || echo 20)" \ + -XX:G1HeapWastePercent=5 \ + -XX:G1MixedGCCountTarget=4 \ + -XX:InitiatingHeapOccupancyPercent="$([ $XMS -gt 12 ] && echo 20 || echo 15)" \ + -XX:G1MixedGCLiveThresholdPercent=90 \ + -XX:G1RSetUpdatingPauseTimePercent=5 \ + -XX:SurvivorRatio=32 \ + -XX:+PerfDisableSharedMem \ + -XX:MaxTenuringThreshold=1 \ + -Dusing.aikars.flags=https://mcflags.emc.gs \ + -Daikars.new.flags=true \ + -jar /app/fabric-server-launch.jar \ + --universe /app/worlds \ + --nogui diff --git a/minecraft/forge/README.md b/minecraft/forge/README.md index 01f563a..7677729 100644 --- a/minecraft/forge/README.md +++ b/minecraft/forge/README.md @@ -1,23 +1,3 @@ - - - # Build arguments Two build arguments are required, namely `MC_VERSION` and `FORGE_VERSION`. You can find your required versions [here](https://files.minecraftforge.net/). @@ -30,16 +10,16 @@ FORGE_VERSION=35.1.4 # Environment variables The two possible environment variables are `XMS` and `XMX`. These specify the -initial RAM & maximum RAM usage respectively. Only `XMS` is required; `XMX` is -just set to the same value as `XMS` if not specified. You must specify them as +initial RAM & maximum RAM usage respectively. Only `XMX` is required; `XMS` is +just set to the same value as `XMX` if not specified. You must specify them as a number, e.g. `XMS=4`. This number represents a quantity of gigabytes. # Mount points There a three useful mount points defined: -* `/mc/config`: this is where all server config files reside. -* `/mc/config/mods`: this is where all mods should be placed. -* `/mc/worlds`: this is where the world files are stored. +* `/app/config`: this is where all server config files reside, as well as the + mods. +* `/app/worlds`: this is where the world files are stored. You can mount these directories somewhere in the host file system by specifying the mount paths in the `.env` file. These can be both absolute or relative @@ -58,10 +38,10 @@ end of the `Dockerfile` to the following: ``` ENTRYPOINT java \ --Xms"${XMS}G" \ --Xmx"${XMX:-$XMS}G" \ +-Xms"${XMS:-$XMX}G" \ +-Xmx"${XMX}G" \ -jar "$FORGE_JAR" \ ---universe /mc/worlds \ +--universe /app/worlds \ --nogui ``` diff --git a/minecraft/papermc/README.md b/minecraft/papermc/README.md index bfcbed7..ffa5e79 100644 --- a/minecraft/papermc/README.md +++ b/minecraft/papermc/README.md @@ -43,11 +43,11 @@ end of the `Dockerfile` to the following: ``` ENTRYPOINT java \ --Xms"${XMS}G" \ --Xmx"${XMX:-$XMS}G" \ --jar /app/server.jar \ ---universe /app/worlds \ ---nogui + -Xms"${XMS:-$XMX}G" \ + -Xmx"${XMX}G" \ + -jar /app/server.jar \ + --universe /app/worlds \ + --nogui ``` This will only use the flags absolutely necessary, while still allowing you to diff --git a/minecraft/papermc/entrypoint.sh b/minecraft/papermc/entrypoint.sh index 1876d54..e64d31e 100755 --- a/minecraft/papermc/entrypoint.sh +++ b/minecraft/papermc/entrypoint.sh @@ -9,7 +9,7 @@ echo "${MC_VERSION}, PaperMC v${PAPERMC_VERSION}" >> /app/config/versions.txt XMS="${XMS:-$XMX}" # Launch the actual server -java \ +exec java \ -Xms"${XMS}G" \ -Xmx"${XMX:-$XMS}G" \ -XX:+UseG1GC \