From d8b6a3c4d3bb7ecf641902c8f41ebcc04b24ac04 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 15 Dec 2016 01:37:56 +0100 Subject: [PATCH] Initial version --- Dockerfile | 22 ++++++++++++++++ README.md | 17 ++++++++++++ map-gen-settings.json | 20 ++++++++++++++ server-settings.json | 61 +++++++++++++++++++++++++++++++++++++++++++ start.sh | 34 ++++++++++++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 map-gen-settings.json create mode 100644 server-settings.json create mode 100755 start.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4ee535d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM debian + +ENV FACTORIO_SERVER_VERSION 0.14.21 + +ENTRYPOINT ["/opt/defaults/start.sh"] +EXPOSE 34197/udp +CMD ["--help"] + +ADD https://www.factorio.com/get-download/${FACTORIO_SERVER_VERSION}/headless/linux64 /tmp/factorio.tgz +ADD . /opt/defaults + +RUN set -ex \ + && mkdir -p /opt \ + && useradd -d /opt/factorio -M -u 10000 factorio \ + && tar -C /opt -x -z -f /tmp/factorio.tgz \ + && chown -R factorio:factorio /opt/factorio \ + && rm /tmp/factorio.tgz + +USER factorio + +VOLUME /data +WORKDIR /data diff --git a/README.md b/README.md new file mode 100644 index 0000000..49e2d59 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Luzifer / factorio + +This repository contains a Docker setup for a headless [Factorio](https://www.factorio.com/) server. + +## Usage + +You need to have a directory to mount into your container which will afterwards contain your map, saves and also the configuration. In this example I will use `/data/factorio` as storage directory. + +1. At first you maybe want to initialize the configuration files: +`docker run --rm -v /data/factorio:/data quay.io/luzifer/factorio init` +2. Afterwards you can edit the two settings files create in `/data/factorio` and adjust your settings. +3. If you are okay with your `map-gen-settings.json` you can generate a map file: +`docker run --rm -v /data/factorio:/data quay.io/luzifer/factorio create` +4. After the map has been generated (and for every future start) you can start the server: +`docker run --rm -v /data/factorio:/data -e 34197:34197 quay.io/luzifer/factorio start` + +The server will expose the port `34197/udp` for the game. The above command already exposes that port to the host machine. diff --git a/map-gen-settings.json b/map-gen-settings.json new file mode 100644 index 0000000..0ad1391 --- /dev/null +++ b/map-gen-settings.json @@ -0,0 +1,20 @@ +{ + "_comment": "Sizes can be specified as none, very-low, low, normal, high, very-high", + + "terrain_segmentation": "normal", + "water": "normal", + "width": 0, + "height": 0, + "starting_area": "normal", + "peaceful_mode": false, + "autoplace_controls": + { + "coal": {"frequency": "normal", "size": "normal", "richness": "normal"}, + "copper-ore": {"frequency": "normal", "size": "normal", "richness": "normal"}, + "crude-oil": {"frequency": "normal", "size": "normal", "richness": "normal"}, + "enemy-base": {"frequency": "normal", "size": "normal", "richness": "normal"}, + "iron-ore": {"frequency": "normal", "size": "normal", "richness": "normal"}, + "stone": {"frequency": "normal", "size": "normal", "richness": "normal"} + } +} + diff --git a/server-settings.json b/server-settings.json new file mode 100644 index 0000000..24bbbd1 --- /dev/null +++ b/server-settings.json @@ -0,0 +1,61 @@ +{ + "name": "Name of the game as it will appear in the game listing", + "description": "Description of the game that will appear in the listing", + "tags": ["game", "tags"], + + "_comment_max_players": "Maximum number of players allowed, admins can join even a full server. 0 means unlimited.", + "max_players": 0, + + "_comment_visibility": ["public: Game will be published on the official Factorio matching server", + "lan: Game will be broadcast on LAN"], + "visibility": + { + "public": false, + "lan": true + }, + + "_comment_credentials": "Your factorio.com login credentials. Required for games with visibility public", + "username": "", + "password": "", + + "_comment_token": "Authentication token. May be used instead of 'password' above.", + "token": "", + + "game_password": "", + + "_comment_require_user_verification": "When set to true, the server will only allow clients that have a valid Factorio.com account", + "require_user_verification": true, + + "_comment_max_upload_in_kilobytes_per_second" : "optional, default value is 0. 0 means unlimited.", + "max_upload_in_kilobytes_per_second": 0, + + "_comment_minimum_latency_in_ticks": "optional one tick is 16ms in default speed, default value is 0. 0 means no minimum.", + "minimum_latency_in_ticks": 0, + + "_comment_ignore_player_limit_for_returning_players": "Players that played on this map already can join even when the max player limit was reached.", + "ignore_player_limit_for_returning_players": false, + + "_comment_allow_commands": "possible values are, true, false and admins-only", + "allow_commands": "admins-only", + + "_comment_autosave_interval": "Autosave interval in minutes", + "autosave_interval": 10, + + "_comment_autosave_slots": "server autosave slots, it is cycled through when the server autosaves.", + "autosave_slots": 5, + + "_comment_afk_autokick_interval": "How many minutes until someone is kicked when doing nothing, 0 for never.", + "afk_autokick_interval": 0, + + "_comment_auto_pause": "Whether should the server be paused when no players are present.", + "auto_pause": true, + + "only_admins_can_pause_the_game": true, + + "_comment_autosave_only_on_server": "Whether autosaves should be saved only on server or also on all connected clients. Default is true.", + "autosave_only_on_server": true, + + "_comment_admins": "List of case insensitive usernames, that will be promoted immediately", + "admins": [] +} + diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..865413d --- /dev/null +++ b/start.sh @@ -0,0 +1,34 @@ +#!/bin/bash -e + +set -o pipefail + +ACTION=$1 +BINARY="/opt/factorio/bin/x64/factorio" +MAP_FILE="mapfile.zip" + +case ${ACTION} in + "init") + echo "Initializing files in case they do not exist: map-gen-settings.json / server-settings.json" + [ -e map-gen-settings.json ] || cp /opt/defaults/map-gen-settings.json map-gen-settings.json + [ -e server-settings.json ] || cp /opt/defaults/server-settings.json server-settings.json + ;; + "create") + echo "Creating map at ${MAP_FILE} with settings from map-gen-settings.json" + [ -e map-gen-settings.json ] || cp /opt/defaults/map-gen-settings.json map-gen-settings.json + exec ${BINARY} --map-gen-settings map-gen-settings.json --create ${MAP_FILE} + ;; + "start") + echo "Starting game from map file ${MAP_FILE} with settings from server-settings.json" + + if ! [ -e ${MAP_FILE} ]; then + echo "Error: There is no map file at ${MAP_FILE}. Use 'create' or put a map file at that location." + exit 1 + fi + + [ -e server-settings.json ] || cp /opt/defaults/server-settings.json server-settings.json + exec ${BINARY} --server-settings server-settings.json --start-server ${MAP_FILE} + ;; + *) + exec ${BINARY} "$@" + ;; +esac