Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Expose config file locations as env vars #422

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,21 @@ The `server-settings.json` file may then contain the variable references like th

These are the environment variables which can be specified at container run time.

| Variable Name | Description | Default | Available in |
| - | - | - | - |
| GENERATE_NEW_SAVE | Generate a new save if one does not exist before starting the server | false | 0.17+ |
| LOAD_LATEST_SAVE | Load latest when true. Otherwise load SAVE_NAME | true | 0.17+ |
| PORT | UDP port the server listens on | 34197 | 0.15+ |
| RCON_PORT | TCP port the rcon server listens on | 27015 | 0.15+ |
| SAVE_NAME | Name to use for the save file | _autosave1 | 0.17+ |
| TOKEN | factorio.com token | | 0.17+ |
| UPDATE_MODS_ON_START | If mods should be updated before starting the server | | 0.17+ |
| USERNAME | factorio.com username | | 0.17+ | |
| Variable Name | Description | Default | Available in |
| -------------------- | -------------------------------------------------------------------- | ------------------------------------ | ------------ |
| GENERATE_NEW_SAVE | Generate a new save if one does not exist before starting the server | `false` | 0.17+ |
| LOAD_LATEST_SAVE | Load latest when true. Otherwise load SAVE_NAME | `true` | 0.17+ |
| PORT | UDP port the server listens on | `34197` | 0.15+ |
| RCON_PORT | TCP port the rcon server listens on | `27015` | 0.15+ |
| SAVE_NAME | Name to use for the save file | `_autosave1` | 0.17+ |
| TOKEN | factorio.com token | | 0.17+ |
| UPDATE_MODS_ON_START | If mods should be updated before starting the server | | 0.17+ |
| USERNAME | factorio.com username | | 0.17+ |
| ADMINLIST_FILE | Path to server adminlist file | `<config-dir>/server-adminlist.json` | |
| BANLIST_FILE | Path to server banlist file | `<config-dir>/server-banlist.json` | |
| SERVER_ID_FILE | Path to server ID file | `<config-dir>/server-id.json` | |
| SERVER_SETTINGS_FILE | Path to server settings file | `<config-dir>/server-settings.json` | |
| WHITELIST_FILE | Path to server whitelist file | `<config-dir>/server-whitelist.json` | |

**Note:** All environment variables are compared as strings

Expand Down
28 changes: 20 additions & 8 deletions docker/files/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@ mkdir -p "$MODS"
mkdir -p "$SCENARIOS"
mkdir -p "$SCRIPTOUTPUT"

# Initialize Factorio server configuration files location variables...
SERVER_ADMINLIST_FILE="${SERVER_ADMINLIST_FILE:-$CONFIG/server-adminlist.json}"
SERVER_BANLIST_FILE="${SERVER_BANLIST_FILE:-$CONFIG/server-banlist.json}"
SERVER_ID_FILE="${SERVER_ID_FILE:-$CONFIG/server-id.json}"
SERVER_SETTINGS_FILE="${SERVER_SETTINGS_FILE:-$CONFIG/server-settings.json}"
SERVER_WHITELIST_FILE="${SERVER_WHITELIST_FILE:-$CONFIG/server-whitelist.json}"
mkdir -p "$(dirname "$SERVER_ADMINLIST_FILE")"
mkdir -p "$(dirname "$SERVER_BANLIST_FILE")"
mkdir -p "$(dirname "$SERVER_ID_FILE")"
mkdir -p "$(dirname "$SERVER_SETTINGS_FILE")"
mkdir -p "$(dirname "$SERVER_WHITELIST_FILE")"

if [[ ! -f $CONFIG/rconpw ]]; then
# Generate a new RCON password if none exists
pwgen 15 1 >"$CONFIG/rconpw"
fi

if [[ ! -f $CONFIG/server-settings.json ]]; then
if [[ ! -f $SERVER_SETTINGS_FILE ]]; then
# Copy default settings if server-settings.json doesn't exist
cp /opt/factorio/data/server-settings.example.json "$CONFIG/server-settings.json"
cp /opt/factorio/data/server-settings.example.json "$SERVER_SETTINGS_FILE"
fi

if [[ ! -f $CONFIG/map-gen-settings.json ]]; then
Expand Down Expand Up @@ -78,14 +90,14 @@ fi

FLAGS=(\
--port "$PORT" \
--server-settings "$CONFIG/server-settings.json" \
--server-banlist "$CONFIG/server-banlist.json" \
--rcon-password "$(cat "$CONFIG/rconpw")" \
--rcon-port "$RCON_PORT" \
--server-whitelist "$CONFIG/server-whitelist.json" \
--server-adminlist "$SERVER_ADMINLIST_FILE" \
--server-banlist "$SERVER_BANLIST_FILE" \
--server-id "$SERVER_ID_FILE" \
--server-settings "$SERVER_SETTINGS_FILE" \
--server-whitelist "$SERVER_WHITELIST_FILE" \
--use-server-whitelist \
--server-adminlist "$CONFIG/server-adminlist.json" \
--rcon-password "$(cat "$CONFIG/rconpw")" \
--server-id /factorio/config/server-id.json \
)

if [[ $LOAD_LATEST_SAVE == true ]]; then
Expand Down