From b5c1dff7b48e67842f319f4baca7c5d378ae1c12 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 17 May 2019 05:32:55 -0500 Subject: [PATCH] Allow puid/pgid to be set as environment vars on stable (#256) * allow puid/pgid to be set on stable * update docker-entrypoint to include puid, gpid * add quotes to env puid/pgid env vars * add quotes for factorio-vol --- 0.16/Dockerfile | 8 ++++---- 0.16/files/docker-entrypoint.sh | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/0.16/Dockerfile b/0.16/Dockerfile index 7039822..5746f0a 100644 --- a/0.16/Dockerfile +++ b/0.16/Dockerfile @@ -15,10 +15,12 @@ ENV PORT=34197 \ CONFIG=/factorio/config \ MODS=/factorio/mods \ SCENARIOS=/factorio/scenarios \ - SCRIPTOUTPUT=/factorio/script-output + SCRIPTOUTPUT=/factorio/script-output \ + PUID="$PUID" \ + PGID="$PGID" RUN mkdir -p /opt /factorio && \ - apk add --update --no-cache pwgen && \ + apk add --update --no-cache pwgen su-exec shadow && \ apk add --update --no-cache --virtual .build-deps curl && \ curl -sSL https://www.factorio.com/get-download/$VERSION/headless/linux64 \ -o /tmp/factorio_headless_x64_$VERSION.tar.xz && \ @@ -41,6 +43,4 @@ EXPOSE $PORT/udp $RCON_PORT/tcp COPY files/ / -USER $USER - ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/0.16/files/docker-entrypoint.sh b/0.16/files/docker-entrypoint.sh index 4e83260..0d27808 100755 --- a/0.16/files/docker-entrypoint.sh +++ b/0.16/files/docker-entrypoint.sh @@ -3,6 +3,8 @@ set -euo pipefail id +FACTORIO_VOL=/factorio +mkdir -p "$FACTORIO_VOL" mkdir -p "$SAVES" mkdir -p "$CONFIG" mkdir -p "$MODS" @@ -29,14 +31,26 @@ if find -L "$SAVES" -iname \*.tmp.zip -mindepth 1 -print | grep -q .; then rm -f "$SAVES"/*.tmp.zip fi +if [ "$(id -u)" = '0' ]; then + # Update the User and Group ID based on the PUID/PGID variables + usermod -o -u "$PUID" factorio + groupmod -o -g "$PGID" factorio + # Take ownership of factorio data if running as root + chown -R factorio:factorio "$FACTORIO_VOL" + # Drop to the factorio user + SU_EXEC="su-exec factorio" +else + SU_EXEC="" +fi + if ! find -L "$SAVES" -iname \*.zip -mindepth 1 -print | grep -q .; then - /opt/factorio/bin/x64/factorio \ + $SU_EXEC /opt/factorio/bin/x64/factorio \ --create "$SAVES/_autosave1.zip" \ --map-gen-settings "$CONFIG/map-gen-settings.json" \ --map-settings "$CONFIG/map-settings.json" fi -exec /opt/factorio/bin/x64/factorio \ +$SU_EXEC /opt/factorio/bin/x64/factorio \ --port "$PORT" \ --start-server-load-latest \ --server-settings "$CONFIG/server-settings.json" \