FROM ubuntu:22.04 ENV DEBIAN_FRONTEND=noninteractive # 1. Install Java 21 (required for 1.21.x), curl, jq, and dependencies RUN apt-get update && apt-get install -y openjdk-21-jre-headless curl jq iptables python3 python3-pip && pip3 install flask && rm -rf /var/lib/apt/lists/* # 2. Download and install Tailscale RUN curl -fsSL https://tailscale.com/install.sh | sh # 3. Setup Minecraft directory WORKDIR /minecraft # 4. Dynamically fetch the latest stable Paper 1.21.11 build at image build time RUN BUILD=$(curl -fsSL "https://api.papermc.io/v2/projects/paper/versions/1.21.11" | jq '.builds[-1]') && curl -fsSL -o paper.jar "https://api.papermc.io/v2/projects/paper/versions/1.21.11/builds/${BUILD}/downloads/paper-1.21.11-${BUILD}.jar" # 5. Accept EULA and pre-configure server.properties for performance + offline mode RUN echo "eula=true" > eula.txt && printf '%s\n' "online-mode=false" "view-distance=6" "simulation-distance=4" "network-compression-threshold=256" "max-tick-time=60000" "entity-broadcast-range-percentage=80" "sync-chunk-writes=false" > server.properties # 6. Pre-create bukkit.yml and spigot.yml tuning RUN mkdir -p /minecraft && printf '%s\n' "spawn-limits:" " monsters: 50" " animals: 8" " water-animals: 3" " water-ambient: 10" "chunk-gc:" " period-in-ticks: 600" > bukkit.yml && printf '%s\n' "world-settings:" " default:" " mob-spawn-range: 4" " entity-activation-range:" " animals: 16" " monsters: 24" " raiders: 48" " misc: 8" " merge-radius:" " item: 3.5" " exp: 4.0" " tick-inactive-villagers: false" " nerf-spawner-mobs: true" > spigot.yml # 7. Copy the web app COPY app.py /minecraft/app.py # 8. Expose Minecraft and web ports EXPOSE 25565 7860 # 9. Start Tailscale, boot Minecraft, and run Flask CMD tailscaled --tun=userspace-networking --socks5-server=localhost:1055 & sleep 2 && tailscale up --authkey=${TAILSCALE_AUTHKEY} && python3 /minecraft/app.py & java -Xmx4G -Xms4G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=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 paper.jar nogui