Added papermc config

master
Jef Roosens 2021-12-27 18:28:57 +01:00
parent 2a58ab9605
commit 65c6f7e316
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
4 changed files with 166 additions and 0 deletions

View File

@ -0,0 +1,43 @@
ARG BASE_IMAGE
# We use ${:-} instead of a default value because the argument is always passed
# to the build, it'll just be blank most likely
FROM ${BASE_IMAGE:-'openjdk:17-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
# Download server file
ADD "https://papermc.io/api/v2/projects/paper/versions/$MC_VERSION/builds/$PAPERMC_VERSION/downloads/paper-$MC_VERSION-$PAPERMC_VERSION.jar" server.jar
# Store the cache in an anonymous volume, which means it won't get stored in the other volumes
VOLUME /app/config/cache
# Default value to keep users from eating up all ram accidentally
ENV XMX=4
ENV MC_VERSION="${MC_VERSION}"
ENV PAPERMC_VERSION="${PAPERMC_VERSION}"
# Document exposed ports
EXPOSE 25565
# 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

36
stacks/paper.yml 100644
View File

@ -0,0 +1,36 @@
version: '3.4'
services:
app:
image: 'chewingbever/mc-paper:1.18.1-103'
build:
context: paper
args:
- 'BASE_IMAGE=openjdk:17-slim'
- 'MC_VERSION=1.18.1'
- 'PAPERMC_VERSION=103'
# These are necessary to make the console work
stdin_open: true
tty: true
deploy:
mode: 'replicated'
replicas: 1
placement:
constraints:
- 'node.labels.class==gitea'
# This makes sure the Minecraft server can never choke my Gitea completely
resources:
limits:
cpus: '4.0'
environment:
- 'XMS=4'
- 'XMX=8'
ports:
- '25565:25565'
volumes:
config:
worlds:

View File

@ -0,0 +1,50 @@
ARG BASE_IMAGE
# We use ${:-} instead of a default value because the argument is always passed
# to the build, it'll just be blank most likely
FROM ${BASE_IMAGE:-'openjdk:17-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 && \
groupadd -g 1000 paper && \
useradd -rMg paper -u 1000 paper
# Create worlds and config directory
WORKDIR /app
RUN mkdir -p worlds config/cache
# Download server file
ADD "https://papermc.io/api/v2/projects/paper/versions/$MC_VERSION/builds/$PAPERMC_VERSION/downloads/paper-$MC_VERSION-$PAPERMC_VERSION.jar" server.jar
# Make sure the server user can access all necessary folders
RUN chown -R paper:paper /app
# Store the cache in an anonymous volume, which means it won't get stored in the other volumes
VOLUME /app/config/cache
# Default value to keep users from eating up all ram accidentally
ENV XMX=4
ENV MC_VERSION="${MC_VERSION}"
ENV PAPERMC_VERSION="${PAPERMC_VERSION}"
# Document exposed ports
EXPOSE 25565
# Switch to non-root user
USER paper:paper
# Entrypoint runs in /app/config
COPY entrypoint.sh /entrypoint.sh
WORKDIR /app/config
ENTRYPOINT /entrypoint.sh
HEALTHCHECK --interval=30s --timeout=5s --start-period=1m --retries=5 \
CMD mcstatus localhost:25565 ping

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