From 4449e1367538f884784d378edeb4b90caf0d61d5 Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 16 Jan 2018 17:59:28 -0600 Subject: [PATCH 1/7] Added creation and symlinking of scenarios directory, creation and symlinking of an entrypoints directory for custom entrypoints, and two examples of using entrypoints with scenarios --- 0.16/Dockerfile | 2 ++ 0.16/docker-entrypoint.sh | 10 +++++++- 0.16/scenario.sh | 49 +++++++++++++++++++++++++++++++++++++++ 0.16/scenario2map.sh | 36 ++++++++++++++++++++++++++++ README.md | 32 +++++++++++++++++++++++++ 5 files changed, 128 insertions(+), 1 deletion(-) create mode 100755 0.16/scenario.sh create mode 100755 0.16/scenario2map.sh diff --git a/0.16/Dockerfile b/0.16/Dockerfile index 2e27913..374a7c3 100644 --- a/0.16/Dockerfile +++ b/0.16/Dockerfile @@ -23,6 +23,8 @@ RUN mkdir -p /opt /factorio && \ rm /tmp/factorio_headless_x64_$VERSION.tar.xz && \ ln -s /factorio/saves /opt/factorio/saves && \ ln -s /factorio/mods /opt/factorio/mods && \ + ln -s /factorio/scenarios /opt/factorio/scenarios && \ + ln -s /factorio/entrypoints /opt/factorio/entrypoints && \ apk del .build-deps && \ addgroup -g $PGID -S $GROUP && \ adduser -u $PUID -G $USER -s /bin/sh -SDH $GROUP && \ diff --git a/0.16/docker-entrypoint.sh b/0.16/docker-entrypoint.sh index b475b0a..b4439d3 100755 --- a/0.16/docker-entrypoint.sh +++ b/0.16/docker-entrypoint.sh @@ -6,10 +6,18 @@ id SAVES=/factorio/saves CONFIG=/factorio/config +MODS=/factorio/mods +SCENARIOS=/factorio/scenarios +ENTRYPOINTS=/factorio/entrypoints mkdir -p $SAVES -mkdir -p /factorio/mods mkdir -p $CONFIG +mkdir -p $MODS +mkdir -p $SCENARIOS +mkdir -p $ENTRYPOINTS + +#symbolic link the default entrypoint to the entrypoints directory so it can be inspected and copied to new entrypoints +ln -s /docker-entrypoint.sh $ENTRYPOINTS/docker-entrypoint.sh #chown -R factorio /factorio diff --git a/0.16/scenario.sh b/0.16/scenario.sh new file mode 100755 index 0000000..a900fd1 --- /dev/null +++ b/0.16/scenario.sh @@ -0,0 +1,49 @@ +#!/bin/sh -x +if [ -z "$1" ] + then + echo "No argument supplied" +fi +SCENARIO=$1 + +set -e + +id + +SAVES=/factorio/saves +CONFIG=/factorio/config +MODS=/factorio/mods +SCENARIOS=/factorio/scenarios + +mkdir -p $SAVES +mkdir -p $CONFIG +mkdir -p $MODS +mkdir -p $SCENARIOS + +#chown -R factorio /factorio + +if [ ! -f $CONFIG/rconpw ]; then + echo $(pwgen 15 1) > $CONFIG/rconpw +fi + +if [ ! -f $CONFIG/server-settings.json ]; then + cp /opt/factorio/data/server-settings.example.json $CONFIG/server-settings.json +fi + +if [ ! -f $CONFIG/map-gen-settings.json ]; then + cp /opt/factorio/data/map-gen-settings.example.json $CONFIG/map-gen-settings.json +fi + +if [ ! -f $CONFIG/map-settings.json ]; then + cp /opt/factorio/data/map-settings.example.json $CONFIG/map-settings.json +fi + + +exec /opt/factorio/bin/x64/factorio \ + --port $PORT \ + --start-server-load-scenario $SCENARIO \ + --server-settings $CONFIG/server-settings.json \ + --server-whitelist $CONFIG/server-whitelist.json \ + --server-banlist $CONFIG/server-banlist.json \ + --rcon-port $RCON_PORT \ + --rcon-password "$(cat $CONFIG/rconpw)" \ + --server-id /factorio/config/server-id.json diff --git a/0.16/scenario2map.sh b/0.16/scenario2map.sh new file mode 100755 index 0000000..c83207b --- /dev/null +++ b/0.16/scenario2map.sh @@ -0,0 +1,36 @@ +#!/bin/sh -x +if [ -z "$1" ] + then + echo "No argument supplied" +fi + +set -e + +id + +SAVES=/factorio/saves +CONFIG=/factorio/config +MODS=/factorio/mods +SCENARIOS=/factorio/scenarios + +mkdir -p $SAVES +mkdir -p $CONFIG +mkdir -p $MODS +mkdir -p $SCENARIOS + +#chown -R factorio /factorio + +if [ ! -f $CONFIG/server-settings.json ]; then + cp /opt/factorio/data/server-settings.example.json $CONFIG/server-settings.json +fi + +if [ ! -f $CONFIG/map-gen-settings.json ]; then + cp /opt/factorio/data/map-gen-settings.example.json $CONFIG/map-gen-settings.json +fi + +if [ ! -f $CONFIG/map-settings.json ]; then + cp /opt/factorio/data/map-settings.example.json $CONFIG/map-settings.json +fi + +exec /opt/factorio/bin/x64/factorio \ + --scenario2map $1 diff --git a/README.md b/README.md index b5149bc..8bbd184 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,38 @@ To generate a new map stop the server, delete all of the saves and restart the s Copy mods into the mods folder and restart the server. +## Scenarios + +If you want to launch a scenario from a clean start (not from a saved map) you'll need to start the docker image from an alternate entrypoint. To do this, use the example entrypoint file stored in the /factorio/entrypoints directory in the volume, and launch the image with the following syntax. Note that this is the normal syntax with the addition of the --entrypoint setting AND the additional argument at the end, which is the name of the Scenario in the Scenarios folder. + +``` +docker run -d \ + -p 34197:34197/udp \ + -p 27015:27015/tcp \ + -v /opt/factorio:/factorio \ + --name factorio \ + --restart=always \ + --entrypoint "/factorio/entrypoints/scenario.sh" \ + dtandersen/factorio \ + MyScenarioName +``` + +## Converting Scenarios to Regular Maps + +If you would like to export your scenario to a saved map, you can use the example entrypoint similar to the Scenario usag above. Factorio will run once, converting the Scenario to a saved Map in your saves directory. A restart of the docker image using the standard options will then load that map, just as if the scenario were just started by the Scenarios example noted above. + +``` +docker run -d \ + -p 34197:34197/udp \ + -p 27015:27015/tcp \ + -v /opt/factorio:/factorio \ + --name factorio \ + --restart=always \ + --entrypoint "/factorio/entrypoints/scenario2map.sh" \ + dtandersen/factorio + MyScenarioName +``` + ## RCON Set the RCON password in the `rconpw` file. A random password is generated if `rconpw` doesn't exist. From ffef5899e91247e203cec3e17aaf761a0655370e Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 16 Jan 2018 18:03:13 -0600 Subject: [PATCH 2/7] Updated Dockerfile to copy in example entrypoints --- 0.16/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/0.16/Dockerfile b/0.16/Dockerfile index 374a7c3..beec13e 100644 --- a/0.16/Dockerfile +++ b/0.16/Dockerfile @@ -35,6 +35,8 @@ VOLUME /factorio EXPOSE $PORT/udp $RCON_PORT/tcp COPY ./docker-entrypoint.sh / +COPY ./scenario2map.sh /factorio/entrypoints +COPY ./scenariosh /factorio/entrypoints USER $USER From 14fb9ecf35ca9b486669b73dc92deb33600dbe61 Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 16 Jan 2018 18:24:35 -0600 Subject: [PATCH 3/7] Typo in Dockerfile --- 0.16/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/0.16/Dockerfile b/0.16/Dockerfile index beec13e..95793bc 100644 --- a/0.16/Dockerfile +++ b/0.16/Dockerfile @@ -36,7 +36,7 @@ EXPOSE $PORT/udp $RCON_PORT/tcp COPY ./docker-entrypoint.sh / COPY ./scenario2map.sh /factorio/entrypoints -COPY ./scenariosh /factorio/entrypoints +COPY ./scenario.sh /factorio/entrypoints USER $USER From 27c14261091574c766cd3adbe63a2704960d967c Mon Sep 17 00:00:00 2001 From: Bill Date: Fri, 2 Mar 2018 15:40:08 -0600 Subject: [PATCH 4/7] Merged in dtandersen/factorio changes --- 0.16/scenario2map.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/0.16/scenario2map.sh b/0.16/scenario2map.sh index c83207b..524299d 100755 --- a/0.16/scenario2map.sh +++ b/0.16/scenario2map.sh @@ -3,6 +3,7 @@ if [ -z "$1" ] then echo "No argument supplied" fi +SCENARIO=$1 set -e @@ -33,4 +34,4 @@ if [ ! -f $CONFIG/map-settings.json ]; then fi exec /opt/factorio/bin/x64/factorio \ - --scenario2map $1 + --scenario2map $SCENARIO From eb22dac84015cf2c6eb888091cb47cbc0c23d050 Mon Sep 17 00:00:00 2001 From: Bill <260078+bplein@users.noreply.github.com> Date: Sat, 10 Mar 2018 17:08:09 -0600 Subject: [PATCH 5/7] force symlinks --- 0.16/Dockerfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/0.16/Dockerfile b/0.16/Dockerfile index 77937aa..b386a91 100644 --- a/0.16/Dockerfile +++ b/0.16/Dockerfile @@ -7,6 +7,8 @@ ARG GROUP=factorio ARG PUID=845 ARG PGID=845 +VOLUME /factorio + ENV PORT=34197 \ RCON_PORT=27015 \ VERSION=0.16.28 \ @@ -21,16 +23,16 @@ RUN mkdir -p /opt /factorio && \ tar xf /tmp/factorio_headless_x64_$VERSION.tar.xz --directory /opt && \ chmod ugo=rwx /opt/factorio && \ rm /tmp/factorio_headless_x64_$VERSION.tar.xz && \ - ln -s /factorio/saves /opt/factorio/saves && \ - ln -s /factorio/mods /opt/factorio/mods && \ - ln -s /factorio/scenarios /opt/factorio/scenarios && \ - ln -s /factorio/entrypoints /opt/factorio/entrypoints && \ + ln -s -F -f /factorio/saves /opt/factorio/saves && \ + ln -s -F -f /factorio/mods /opt/factorio/mods && \ + ln -s -F -f /factorio/scenarios /opt/factorio/scenarios && \ + ln -s -F -f /factorio/entrypoints /opt/factorio/entrypoints && \ apk del .build-deps && \ addgroup -g $PGID -S $GROUP && \ adduser -u $PUID -G $GROUP -s /bin/sh -SDH $USER && \ chown -R $USER:$GROUP /opt/factorio /factorio -VOLUME /factorio + EXPOSE $PORT/udp $RCON_PORT/tcp From 6a9a596cd8e2d474479f9bbe88a267ef5b4e27e3 Mon Sep 17 00:00:00 2001 From: Bill <260078+bplein@users.noreply.github.com> Date: Sat, 10 Mar 2018 17:11:47 -0600 Subject: [PATCH 6/7] fix syntax on symlink --- 0.16/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/0.16/Dockerfile b/0.16/Dockerfile index b386a91..f44d591 100644 --- a/0.16/Dockerfile +++ b/0.16/Dockerfile @@ -23,10 +23,10 @@ RUN mkdir -p /opt /factorio && \ tar xf /tmp/factorio_headless_x64_$VERSION.tar.xz --directory /opt && \ chmod ugo=rwx /opt/factorio && \ rm /tmp/factorio_headless_x64_$VERSION.tar.xz && \ - ln -s -F -f /factorio/saves /opt/factorio/saves && \ - ln -s -F -f /factorio/mods /opt/factorio/mods && \ - ln -s -F -f /factorio/scenarios /opt/factorio/scenarios && \ - ln -s -F -f /factorio/entrypoints /opt/factorio/entrypoints && \ + ln -s -f /factorio/saves /opt/factorio/saves && \ + ln -s -f /factorio/mods /opt/factorio/mods && \ + ln -s -f /factorio/scenarios /opt/factorio/scenarios && \ + ln -s -f /factorio/entrypoints /opt/factorio/entrypoints && \ apk del .build-deps && \ addgroup -g $PGID -S $GROUP && \ adduser -u $PUID -G $GROUP -s /bin/sh -SDH $USER && \ From dc3c040d7c120e2495387c32d8a290b73a1f0cd0 Mon Sep 17 00:00:00 2001 From: Bill <260078+bplein@users.noreply.github.com> Date: Sat, 10 Mar 2018 17:17:16 -0600 Subject: [PATCH 7/7] another symlink bug --- 0.16/docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/0.16/docker-entrypoint.sh b/0.16/docker-entrypoint.sh index b4439d3..5773d93 100755 --- a/0.16/docker-entrypoint.sh +++ b/0.16/docker-entrypoint.sh @@ -17,7 +17,7 @@ mkdir -p $SCENARIOS mkdir -p $ENTRYPOINTS #symbolic link the default entrypoint to the entrypoints directory so it can be inspected and copied to new entrypoints -ln -s /docker-entrypoint.sh $ENTRYPOINTS/docker-entrypoint.sh +ln -s -f /docker-entrypoint.sh $ENTRYPOINTS/docker-entrypoint.sh #chown -R factorio /factorio