1
0
mirror of https://github.com/bplein/factorio-docker.git synced 2025-01-06 03:03:49 +02:00

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
This commit is contained in:
Jason 2019-05-17 05:32:55 -05:00 committed by Florian Kinder
parent ee5b023911
commit b5c1dff7b4
2 changed files with 20 additions and 6 deletions

View File

@ -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"]

View File

@ -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" \