diff --git a/minecraft-server/Dockerfile b/minecraft-server/Dockerfile index 564ecc8e..f7576ec5 100644 --- a/minecraft-server/Dockerfile +++ b/minecraft-server/Dockerfile @@ -21,10 +21,7 @@ HEALTHCHECK CMD mcstatus localhost ping RUN addgroup -g 1000 minecraft \ && adduser -Ss /bin/false -u 1000 -G minecraft -h /home/minecraft minecraft \ - && mkdir /data \ - && mkdir /config \ - && mkdir /mods \ - && mkdir /plugins \ + && mkdir -m 777 /data /mods /config /plugins \ && chown minecraft:minecraft /data /config /mods /plugins /home/minecraft EXPOSE 25565 25575 @@ -34,16 +31,17 @@ ADD https://github.com/itzg/rcon-cli/releases/download/1.3/rcon-cli_linux_amd64 COPY mcadmin.jq /usr/share RUN chmod +x /usr/local/bin/* -VOLUME ["/data","/mods","/config","/plugins","/home/minecraft"] +VOLUME ["/data","/mods","/config","/plugins"] COPY server.properties /tmp/server.properties WORKDIR /data ENTRYPOINT [ "/start" ] -ENV UID=1000 GID=1000 \ - JVM_XX_OPTS="-XX:+UseG1GC" MEMORY="1G" \ +ENV JVM_XX_OPTS="-XX:+UseG1GC" MEMORY="1G" \ TYPE=VANILLA VERSION=LATEST FORGEVERSION=RECOMMENDED SPONGEBRANCH=STABLE SPONGEVERSION= LEVEL=world \ PVP=true DIFFICULTY=easy ENABLE_RCON=true RCON_PORT=25575 RCON_PASSWORD=minecraft \ LEVEL_TYPE=DEFAULT GENERATOR_SETTINGS= WORLD= MODPACK= SERVER_PORT=25565 ONLINE_MODE=TRUE CONSOLE=true COPY start* / + +USER minecraft \ No newline at end of file diff --git a/minecraft-server/README.md b/minecraft-server/README.md index 9b07b4e0..44373dc7 100644 --- a/minecraft-server/README.md +++ b/minecraft-server/README.md @@ -91,17 +91,6 @@ to map a directory on your host machine to the container's `/data` directory, su When attached in this way you can stop the server, edit the configuration under your attached `/path/on/host` and start the server again with `docker start CONTAINERID` to pick up the new configuration. -**NOTE**: By default, the files in the attached directory will be owned by the host user with UID of 1000 and host group with GID of 1000. -You can use an different UID and GID by passing the options: - - -e UID=1000 -e GID=1000 - -replacing 1000 with a UID and GID that is present on the host. -Here is one way to find the UID and GID: - - id some_host_user - getent group some_host_group - ## Versions To use a different Minecraft version, pass the `VERSION` environment variable, which can have the value @@ -750,10 +739,6 @@ ways to adjust the memory settings: The values of all three are passed directly to the JVM and support format/units as `[g|G|m|M|k|K]`. -### /data ownership - -In order to adapt to differences in `UID` and `GID` settings the entry script will attempt to correct ownership and writability of the `/data` directory. This logic can be disabled by setting `-e SKIP_OWNERSHIP_FIX=TRUE`. - ### JVM Options General JVM options can be passed to the Minecraft Server invocation by passing a `JVM_OPTS` diff --git a/minecraft-server/start b/minecraft-server/start index cd7aa384..2a45fb67 100755 --- a/minecraft-server/start +++ b/minecraft-server/start @@ -1,23 +1,95 @@ -#!/bin/sh +#!/bin/bash -set -e -# Since Alpine doesn't have a usermod command we have to directly manipulate the passwd/group files :( -sed -i "/^minecraft/s/:1000:1000:/:${UID}:${GID}:/" /etc/passwd -sed -i "/^minecraft/s/:1000:/:${GID}:/" /etc/group +shopt -s nullglob -if [ "$SKIP_OWNERSHIP_FIX" != "TRUE" ]; then - fix_ownership() { - dir=$1 - if ! su-exec minecraft test -w $dir; then - echo "Correcting writability of $dir ..." - chown -R minecraft:minecraft $dir - chmod -R u+w $dir +#umask 002 +export HOME=/data + +if [ ! -e /data/eula.txt ]; then + if [ "$EULA" != "" ]; then + echo "# Generated via Docker on $(date)" > eula.txt + echo "eula=$EULA" >> eula.txt + if [ $? != 0 ]; then + echo "ERROR: unable to write eula to /data. Please make sure attached directory is writable by uid=${UID}" + exit 2 fi - } - - fix_ownership /data - fix_ownership /home/minecraft + else + echo "" + echo "Please accept the Minecraft EULA at" + echo " https://account.mojang.com/documents/minecraft_eula" + echo "by adding the following immediately after 'docker run':" + echo " -e EULA=TRUE" + echo "" + exit 1 + fi fi -echo "Switching to user 'minecraft'" -su-exec minecraft /start-configuration $@ +if ! touch /data/.verify_access; then + echo "ERROR: /data doesn't seem to be writable. Please make sure attached directory is writable by uid=${UID} " + exit 2 +fi + +if [[ $PROXY ]]; then + export http_proxy="$PROXY" + export https_proxy="$PROXY" + echo "INFO: Giving proxy time to startup..." + sleep 5 +fi + +export SERVER_PROPERTIES=/data/server.properties +export FTB_DIR=/data/FeedTheBeast +export VERSIONS_JSON=https://launchermeta.mojang.com/mc/game/version_manifest.json + +echo "Checking version information." +case "X$VERSION" in + X|XLATEST|Xlatest) + export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'` + ;; + XSNAPSHOT|Xsnapshot) + export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.snapshot'` + ;; + X[1-9]*) + export VANILLA_VERSION=$VERSION + ;; + *) + export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'` + ;; +esac + +cd /data + +export ORIGINAL_TYPE=${TYPE} + +echo "Checking type information." +case "$TYPE" in + *BUKKIT|*bukkit|SPIGOT|spigot) + exec /start-deployBukkitSpigot $@ + ;; + + PAPER|paper) + exec /start-deployPaper $@ + ;; + + FORGE|forge) + exec /start-deployForge $@ + ;; + + FTB|ftb) + exec /start-deployFTB $@ + ;; + + VANILLA|vanilla) + exec /start-deployVanilla $@ + ;; + + SPONGEVANILLA|spongevanilla) + exec /start-deploySpongeVanilla $@ + ;; + + *) + echo "Invalid type: '$TYPE'" + echo "Must be: VANILLA, FORGE, BUKKIT, SPIGOT, PAPER, FTB, SPONGEVANILLA" + exit 1 + ;; + +esac diff --git a/minecraft-server/start-configuration b/minecraft-server/start-configuration deleted file mode 100755 index 2a45fb67..00000000 --- a/minecraft-server/start-configuration +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash - -shopt -s nullglob - -#umask 002 -export HOME=/data - -if [ ! -e /data/eula.txt ]; then - if [ "$EULA" != "" ]; then - echo "# Generated via Docker on $(date)" > eula.txt - echo "eula=$EULA" >> eula.txt - if [ $? != 0 ]; then - echo "ERROR: unable to write eula to /data. Please make sure attached directory is writable by uid=${UID}" - exit 2 - fi - else - echo "" - echo "Please accept the Minecraft EULA at" - echo " https://account.mojang.com/documents/minecraft_eula" - echo "by adding the following immediately after 'docker run':" - echo " -e EULA=TRUE" - echo "" - exit 1 - fi -fi - -if ! touch /data/.verify_access; then - echo "ERROR: /data doesn't seem to be writable. Please make sure attached directory is writable by uid=${UID} " - exit 2 -fi - -if [[ $PROXY ]]; then - export http_proxy="$PROXY" - export https_proxy="$PROXY" - echo "INFO: Giving proxy time to startup..." - sleep 5 -fi - -export SERVER_PROPERTIES=/data/server.properties -export FTB_DIR=/data/FeedTheBeast -export VERSIONS_JSON=https://launchermeta.mojang.com/mc/game/version_manifest.json - -echo "Checking version information." -case "X$VERSION" in - X|XLATEST|Xlatest) - export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'` - ;; - XSNAPSHOT|Xsnapshot) - export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.snapshot'` - ;; - X[1-9]*) - export VANILLA_VERSION=$VERSION - ;; - *) - export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'` - ;; -esac - -cd /data - -export ORIGINAL_TYPE=${TYPE} - -echo "Checking type information." -case "$TYPE" in - *BUKKIT|*bukkit|SPIGOT|spigot) - exec /start-deployBukkitSpigot $@ - ;; - - PAPER|paper) - exec /start-deployPaper $@ - ;; - - FORGE|forge) - exec /start-deployForge $@ - ;; - - FTB|ftb) - exec /start-deployFTB $@ - ;; - - VANILLA|vanilla) - exec /start-deployVanilla $@ - ;; - - SPONGEVANILLA|spongevanilla) - exec /start-deploySpongeVanilla $@ - ;; - - *) - echo "Invalid type: '$TYPE'" - echo "Must be: VANILLA, FORGE, BUKKIT, SPIGOT, PAPER, FTB, SPONGEVANILLA" - exit 1 - ;; - -esac diff --git a/minecraft-server/start-deployBukkitSpigot b/minecraft-server/start-deployBukkitSpigot index fd84e22a..1ca612ee 100755 --- a/minecraft-server/start-deployBukkitSpigot +++ b/minecraft-server/start-deployBukkitSpigot @@ -28,8 +28,15 @@ function downloadSpigot { ;; esac + local downloadVersion + if [[ ${VERSION} == LATEST ]]; then + downloadVersion=${VANILLA_VERSION} + else + downloadVersion=${VERSION} + fi + if [[ -z $downloadUrl ]]; then - downloadUrl="https://cdn.getbukkit.org/${getbukkitFlavor}/${getbukkitFlavor}-${VERSION}.jar" + downloadUrl="https://cdn.getbukkit.org/${getbukkitFlavor}/${getbukkitFlavor}-${downloadVersion}.jar" fi echo "Downloading $match ..."