Merge branch 'mc-revamp'

pull/3/head
Jef Roosens 2021-01-26 14:07:06 +01:00
commit 0128dce6f6
15 changed files with 272 additions and 372 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
# Build arguments # Build arguments
MC_VERSION=
FABRIC_VERSION= FABRIC_VERSION=
# Environment variables # Environment variables
XMS=4 # If XMS is left blank, it uses the same value as XMX
XMS=
XMX=4 XMX=4
# Mount points # Mount points
CONFIG_DIR= # The mods should be placed inside the CONFIG_DIR under `mods`
MODS_DIR= CONFIG_DIR=config
WORLDS_DIR= WORLDS_DIR=worlds
# Other # Other
PORT=25565 PORT=25565

View File

@ -1,69 +1,40 @@
# Copyright (C) 2020 Jef Roosens FROM openjdk:8-jre-slim
# 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 <https://www.gnu.org/licenses/>.
FROM openjdk:8-slim
# Build arguments # Build arguments
ARG MC_VERSION
ARG FABRIC_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 # Create worlds and config directory
WORKDIR /mc WORKDIR /app
RUN mkdir worlds config RUN mkdir worlds config
# Download installer jar # Download installer jar
ADD "https://maven.fabricmc.net/net/fabricmc/fabric-installer/$FABRIC_VERSION/fabric-installer-$FABRIC_VERSION.jar" installer.jar ADD "https://maven.fabricmc.net/net/fabricmc/fabric-installer/$FABRIC_VERSION/fabric-installer-$FABRIC_VERSION.jar" installer.jar
# Install fabric & remove installer # Install fabric & remove installer
RUN java -jar installer.jar server -downloadMinecraft && \ RUN java -jar installer.jar server -downloadMinecraft -mcversion "$MC_VERSION" && \
rm installer.jar rm installer.jar
# Store the cache in an anonymous volume, which means it won't get stored in the other volumes # 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 # 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 runs in /app/config
ENTRYPOINT mv -n /mc/*.jar /mc/config && \ COPY entrypoint.sh /entrypoint.sh
echo "eula=true" > /mc/config/eula.txt && \ WORKDIR /app/config
java \ ENTRYPOINT /entrypoint.sh
-Xms"${XMS}G" \
-Xmx"${XMX:-$XMS}G" \ HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
-XX:+UseG1GC \ CMD mcstatus localhost:25565 ping
-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

View File

@ -1,41 +1,21 @@
<!---
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 <https://www.gnu.org/licenses/>.
-->
# Build arguments # Build arguments
Only one build argument is required, namely `FABRIC_VERSION`. This is the Two build arguments are required, namely `MC_VERSION` and `FABRIC_VERSION`.
version of Fabric you wish to install. You can find the list of versions The latter is the version of Fabric you wish to install. You can find the list
[here](https://fabricmc.net/use/). For example, you can then set of versions [here](https://fabricmc.net/use/). For example, you can then set
`FABRIC_VERSION=0.6.1.51` in the `.env` file. `FABRIC_VERSION=0.6.1.51` in the `.env` file.
# Environment variables # Environment variables
The two possible environment variables are `XMS` and `XMX`. These specify the The two possible environment variables are `XMS` and `XMX`. These specify the
initial RAM & maximum RAM usage respectively. Only `XMS` is required; `XMX` is initial RAM & maximum RAM usage respectively. Only `XMX` is required; `XMS` is
just set to the same value as `XMS` if not specified. You must specify them as 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. a number, e.g. `XMS=4`. This number represents a quantity of gigabytes.
# Mount points # Mount points
There a three useful mount points defined: There a three useful mount points defined:
* `/mc/config`: this is where all server config files reside. * `/app/config`: this is where all server config files reside, as well as the
* `/mc/config/mods`: this is where all mods should be placed. mods.
* `/mc/worlds`: this is where the world files are stored. * `/app/worlds`: this is where the world files are stored.
You can mount these directories somewhere in the host file system by specifying 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 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 \ ENTRYPOINT java \
-Xms"${XMS}G" \ -Xms"${XMS:-$XMX}G" \
-Xmx"${XMX:-$XMS}G" \ -Xmx"${XMX}G" \
-jar fabric-server-launch.jar \ -jar fabric-server-launch.jar \
--universe /mc/worlds \ --universe /app/worlds \
--nogui --nogui
``` ```
This will only use the flags absolutely necessary, while still allowing you to This will only use the flags absolutely necessary, while still allowing you to
tweak the memory variables. 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.

View File

@ -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 <https://www.gnu.org/licenses/>.
version: '3.5' version: '3.5'
services: services:
fabric: app:
build: build:
context: . context: .
args: args:
- 'FABRIC_VERSION=${FABRIC_VERSION}' - 'MC_VERSION'
image: 'mc-fabric-server:${FABRIC_VERSION}' - 'FABRIC_VERSION'
image: 'chewingbever/mc-fabric:${MC_VERSION}-${FABRIC_VERSION}'
restart: 'unless-stopped' restart: 'always'
stdin_open: true stdin_open: true
tty: true tty: true
@ -33,6 +18,10 @@ services:
ports: ports:
- '$PORT:25565' - '$PORT:25565'
volumes: volumes:
- '$CONFIG_DIR:/mc/config' - '$CONFIG_DIR:/app/config'
- '$MODS_DIR:/mc/config/mods' - '$WORLDS_DIR:/app/worlds'
- '$WORLDS_DIR:/mc/worlds'
# These volumes only get created if you use them in the env file
volumes:
config:
worlds:

View File

@ -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

View File

@ -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 <https://www.gnu.org/licenses/>.
# Build arguments # Build arguments
MC_VERSION= MC_VERSION=
FORGE_VERSION= FORGE_VERSION=
# Environment variables # Environment variables
XMS=4 # If XMS is left blank, it uses the same value as XMX
XMS=
XMX=4 XMX=4
# Mount points # Mount points
# The mods should be placed inside the CONFIG_DIR under `mods`
CONFIG_DIR= CONFIG_DIR=
MODS_DIR=
WORLDS_DIR= WORLDS_DIR=
# Other # Other

View File

@ -1,27 +1,18 @@
# Copyright (C) 2020 Jef Roosens FROM openjdk:8-jre-slim
# 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 <https://www.gnu.org/licenses/>.
FROM openjdk:8-slim
# Build arguments # Build arguments
ARG MC_VERSION ARG MC_VERSION
ARG FORGE_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 # Create worlds and config directory
WORKDIR /mc WORKDIR /app
RUN mkdir worlds config RUN mkdir worlds config
# Download installer jar # Download installer jar
@ -29,10 +20,7 @@ ADD "https://files.minecraftforge.net/maven/net/minecraftforge/forge/${MC_VERSIO
# Install forge & remove installer # Install forge & remove installer
RUN java -jar installer.jar server --installServer && \ RUN java -jar installer.jar server --installServer && \
rm installer.jar installer.jar.log 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"
# Store the cache in an anonymous volume, which means it won't get stored in the other volumes # Store the cache in an anonymous volume, which means it won't get stored in the other volumes
VOLUME /mc/config/cache VOLUME /mc/config/cache
@ -40,34 +28,16 @@ VOLUME /mc/config/cache
WORKDIR /mc/config WORKDIR /mc/config
# Default value to keep users from eating up all ram accidentally # 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 runs in /app/config
ENTRYPOINT mv -n /mc/*.jar /mc/*.json /mc/libraries /mc/config && \ COPY entrypoint.sh /entrypoint.sh
echo "eula=true" > /mc/config/eula.txt && \ WORKDIR /app/config
java \ ENTRYPOINT /entrypoint.sh
-Xms"${XMS}G" \
-Xmx"${XMX:-$XMS}G" \ HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
-XX:+UseG1GC \ CMD mcstatus localhost:25565 ping
-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

View File

@ -1,23 +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 <https://www.gnu.org/licenses/>.
-->
# Build arguments # Build arguments
Two build arguments are required, namely `MC_VERSION` and `FORGE_VERSION`. You Two build arguments are required, namely `MC_VERSION` and `FORGE_VERSION`. You
can find your required versions [here](https://files.minecraftforge.net/). can find your required versions [here](https://files.minecraftforge.net/).
@ -30,16 +10,16 @@ FORGE_VERSION=35.1.4
# Environment variables # Environment variables
The two possible environment variables are `XMS` and `XMX`. These specify the The two possible environment variables are `XMS` and `XMX`. These specify the
initial RAM & maximum RAM usage respectively. Only `XMS` is required; `XMX` is initial RAM & maximum RAM usage respectively. Only `XMX` is required; `XMS` is
just set to the same value as `XMS` if not specified. You must specify them as 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. a number, e.g. `XMS=4`. This number represents a quantity of gigabytes.
# Mount points # Mount points
There a three useful mount points defined: There a three useful mount points defined:
* `/mc/config`: this is where all server config files reside. * `/app/config`: this is where all server config files reside, as well as the
* `/mc/config/mods`: this is where all mods should be placed. mods.
* `/mc/worlds`: this is where the world files are stored. * `/app/worlds`: this is where the world files are stored.
You can mount these directories somewhere in the host file system by specifying 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 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 \ ENTRYPOINT java \
-Xms"${XMS}G" \ -Xms"${XMS:-$XMX}G" \
-Xmx"${XMX:-$XMS}G" \ -Xmx"${XMX}G" \
-jar "$FORGE_JAR" \ -jar "$FORGE_JAR" \
--universe /mc/worlds \ --universe /app/worlds \
--nogui --nogui
``` ```

View File

@ -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 <https://www.gnu.org/licenses/>.
version: '3.5' version: '3.5'
services: services:
forge: app:
build: build:
context: . context: .
args: args:
- 'MC_VERSION=${MC_VERSION}' - 'MC_VERSION'
- 'FORGE_VERSION=${FORGE_VERSION}' - 'FORGE_VERSION'
image: 'mc-forge-server:${MC_VERSION}-${FORGE_VERSION}' image: 'chewingbever/mc-forge:${MC_VERSION}-${FORGE_VERSION}'
restart: 'unless-stopped' restart: 'always'
stdin_open: true stdin_open: true
tty: true tty: true
@ -34,6 +18,10 @@ services:
ports: ports:
- '$PORT:25565' - '$PORT:25565'
volumes: volumes:
- '$CONFIG_DIR:/mc/config' - '$CONFIG_DIR:/app/config'
- '$MODS_DIR:/mc/config/mods' - '$WORLDS_DIR:/app/worlds'
- '$WORLDS_DIR:/mc/worlds'
# These volumes only get created if you use them in the env file
volumes:
config:
worlds:

View File

@ -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

View File

@ -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 <https://www.gnu.org/licenses/>.
# Build arguments # Build arguments
MC_VERSION= MC_VERSION=
PAPERMC_VERSION= PAPERMC_VERSION=
# Environment variables # Environment variables
XMS=4 # If XMS is left blank, it uses the same value as XMX
XMS=
XMX=4 XMX=4
# Mount points # Mount points
CONFIG_DIR= CONFIG_DIR=config
WORLDS_DIR= WORLDS_DIR=worlds
# Other # Other
PORT=25565 PORT=25565

View File

@ -1,66 +1,39 @@
# Copyright (C) 2020 Jef Roosens FROM openjdk:11-jre-slim
# 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 <https://www.gnu.org/licenses/>.
FROM openjdk:8-slim
# Build arguments # Build arguments
ARG MC_VERSION ARG MC_VERSION
ARG PAPERMC_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 # Create worlds and config directory
WORKDIR /mc WORKDIR /app
RUN mkdir worlds config RUN mkdir worlds config
# Download server file # Download server file
ADD "https://papermc.io/api/v1/paper/$MC_VERSION/$PAPERMC_VERSION/download" server.jar 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 # 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 # 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}"
# We copy over the server jar(s) as well to make the backup more reproducible to deploy # Document exposed ports
ENTRYPOINT mv -n /mc/*.jar /mc/config && \ EXPOSE 25565
echo "eula=true" > /mc/config/eula.txt && \
java \ # Entrypoint runs in /app/config
-Xms"${XMS}G" \ COPY entrypoint.sh /entrypoint.sh
-Xmx"${XMX:-$XMS}G" \ WORKDIR /app/config
-XX:+UseG1GC \ ENTRYPOINT /entrypoint.sh
-XX:+ParallelRefProcEnabled \
-XX:MaxGCPauseMillis=200 \ HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
-XX:+UnlockExperimentalVMOptions \ CMD mcstatus localhost:25565 ping
-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 /mc/server.jar \
--universe /mc/worlds \
--nogui

View File

@ -1,23 +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 <https://www.gnu.org/licenses/>.
-->
# Build arguments # Build arguments
Two build arguments are required, namely `MC_VERSION` and `PAPERMC_VERSION`. Two build arguments are required, namely `MC_VERSION` and `PAPERMC_VERSION`.
You can find your required versions [here](https://papermc.io/downloads). The 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 # Environment variables
The two possible environment variables are `XMS` and `XMX`. These specify the The two possible environment variables are `XMS` and `XMX`. These specify the
initial RAM & maximum RAM usage respectively. Only `XMS` is required; `XMX` is initial RAM & maximum RAM usage respectively. Only `XMX` is required; `XMS` is
just set to the same value as `XMS` if not specified. You must specify them as 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. a number, e.g. `XMS=4`. This number represents a quantity of gigabytes.
# Mount points # Mount points
There a two useful mount points defined: There a two useful mount points defined:
* `/mc/config`: this is where all server config files reside. * `/app/config`: this is where all server config files reside.
* `/mc/worlds`: this is where the world files are stored. * `/app/worlds`: this is where the world files are stored.
You can mount these directories somewhere in the host file system by specifying 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 the mount paths in the `.env` file. These can be both absolute or relative
@ -63,11 +43,11 @@ end of the `Dockerfile` to the following:
``` ```
ENTRYPOINT java \ ENTRYPOINT java \
-Xms"${XMS}G" \ -Xms"${XMS:-$XMX}G" \
-Xmx"${XMX:-$XMS}G" \ -Xmx"${XMX}G" \
-jar /mc/server.jar \ -jar /app/server.jar \
--universe /mc/worlds \ --universe /app/worlds \
--nogui --nogui
``` ```
This will only use the flags absolutely necessary, while still allowing you to This will only use the flags absolutely necessary, while still allowing you to

View File

@ -1,39 +1,28 @@
# 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 <https://www.gnu.org/licenses/>.
version: '3.5' version: '3.5'
services: services:
papermc: app:
build: build:
context: . context: .
dockerfile: Dockerfile
args: args:
- 'MC_VERSION=${MC_VERSION}' - 'MC_VERSION'
- 'PAPERMC_VERSION=${PAPERMC_VERSION}' - 'PAPERMC_VERSION'
image: 'mc-papermc-server:${MC_VERSION}-${PAPERMC_VERSION}' image: 'chewingbever/mc-papermc:${MC_VERSION}-${PAPERMC_VERSION}'
restart: 'always'
restart: unless-stopped # Needed to interact with server console
stdin_open: true stdin_open: true
tty: true tty: true
environment: environment:
- XMS - 'XMS'
- XMX - 'XMX'
ports: ports:
- '$PORT:25565' - '$PORT:25565'
volumes: volumes:
- '$CONFIG_DIR:/minecraft/config' - '$CONFIG_DIR:/app/config'
- '$WORLDS_DIR:/minecraft/worlds' - '$WORLDS_DIR:/app/worlds'
# These volumes only get created if you use them in the env file
volumes:
config:
worlds:

View File

@ -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
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/server.jar \
--universe /app/worlds \
--nogui