diff --git a/paper/Dockerfile b/paper/Dockerfile index d897d2c..ed1b430 100644 --- a/paper/Dockerfile +++ b/paper/Dockerfile @@ -1,11 +1,15 @@ FROM alpine:latest +ENV UID=1000 +ENV GID=1000 + ARG JAVA=openjdk17 -RUN apk add --upgrade $JAVA curl jq +RUN apk add --upgrade sudo shadow $JAVA curl jq ADD ./bin /usr/local/bin -RUN adduser -D minecraft +RUN groupadd -g $GID minecraft +RUN useradd -u $UID -g $GID minecraft RUN mkdir /minecraft && chown -R minecraft /minecraft @@ -13,11 +17,10 @@ VOLUME ["/minecraft"] WORKDIR /minecraft -USER minecraft - EXPOSE 25565 ARG MC_VERSION ENV MC_VERSION=${MC_VERSION:-1.19.4} -CMD sh -c "download_mc $MC_VERSION && java -Xmx2G -Xms2G -jar paper.jar" +ENTRYPOINT ["setup"] +CMD ["java", "-Xmx2G", "-Xms2G", "-jar", "paper.jar"] diff --git a/paper/bin/download_mc b/paper/bin/configure_and_start similarity index 82% rename from paper/bin/download_mc rename to paper/bin/configure_and_start index 4290a55..8782b46 100755 --- a/paper/bin/download_mc +++ b/paper/bin/configure_and_start @@ -1,13 +1,8 @@ #!/bin/sh -if test "$EULA" != "true"; then - echo "You need to accept the Mojang EULA (using -e EULA=true) to run the server" - exit 1 -fi - meta_dir="docker_meta" -if test ! -f "$meta_dir/setup_done"; then +if test ! -f "$meta_dir/config_done"; then # TODO: Use config/paper-global.yml with new config keys for 1.19+ Paper config_path="paper.yml" @@ -35,10 +30,11 @@ EOF mkdir -p "$meta_dir" && touch "$meta_dir/setup_done" else - echo "Setup is done" + echo "Configuration is done" fi -version=$1 +echo $MC_VERSION +version=$MC_VERSION echo "Downloading version $version" apiURL=https://api.papermc.io/v2/projects/paper @@ -53,3 +49,6 @@ echo "Downloading to $PWD" wget -O paper.jar $url echo "eula=true" > eula.txt + +echo "> $@" +exec "$@" diff --git a/paper/bin/setup b/paper/bin/setup new file mode 100755 index 0000000..867c73b --- /dev/null +++ b/paper/bin/setup @@ -0,0 +1,12 @@ +#!/bin/sh + +if test "$EULA" != "true"; then + echo "You need to accept the Mojang EULA (using -e EULA=true) to run the server" + exit 1 +fi + +usermod -u $UID minecraft +groupmod -g $GID minecraft +chown -R minecraft:minecraft /minecraft + +exec sudo -E -u minecraft configure_and_start "$@" diff --git a/velocity/Dockerfile b/velocity/Dockerfile index d121727..458fe66 100644 --- a/velocity/Dockerfile +++ b/velocity/Dockerfile @@ -1,10 +1,14 @@ FROM alpine:latest -RUN apk add --upgrade openjdk17 curl jq +ENV UID=1000 +ENV GID=1000 + +RUN apk add --upgrade sudo shadow openjdk17 curl jq ADD ./bin /usr/local/bin -RUN adduser -D velocity +RUN groupadd -g $GID velocity +RUN useradd -u $UID -g $GID velocity RUN mkdir /velocity && chown -R velocity /velocity @@ -12,8 +16,7 @@ VOLUME ["/velocity"] WORKDIR /velocity -USER velocity - EXPOSE 25577 -CMD sh -c "download_velocity && java -Xmx500M -Xms500M -jar velocity.jar" +ENTRYPOINT ["setup"] +CMD ["java", "-Xmx500M", "-Xms500M", "-jar", "velocity.jar"] diff --git a/velocity/bin/download_velocity b/velocity/bin/configure_and_start similarity index 97% rename from velocity/bin/download_velocity rename to velocity/bin/configure_and_start index bf8200c..17de863 100755 --- a/velocity/bin/download_velocity +++ b/velocity/bin/configure_and_start @@ -28,3 +28,6 @@ echo "Full URL is: $url" echo "Downloading to $PWD" wget -O velocity.jar $url + +echo "> $@" +exec "$@" diff --git a/velocity/bin/setup b/velocity/bin/setup new file mode 100755 index 0000000..ab40d66 --- /dev/null +++ b/velocity/bin/setup @@ -0,0 +1,7 @@ +#!/bin/sh + +usermod -u $UID velocity +groupmod -g $GID velocity +chown -R velocity:velocity /velocity + +exec sudo -E -u velocity configure_and_start "$@"