From 4449e1367538f884784d378edeb4b90caf0d61d5 Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 16 Jan 2018 17:59:28 -0600 Subject: [PATCH] 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.