Skip to content

jlucktay/factorio-server-kit

Repository files navigation

Welcome to the Factorio Server Kit 👋

License: The Unlicense Twitter: jlucktay Wakatime tracker

Running your own Factorio server on Google Cloud

Much like the game itself, this project aims to automate as much as possible, when it comes to running your own Factorio server.

The scripts are based around the use of preemptible VMs which keeps running costs low.

Installation

Initial setup

  1. Make sure the following tools are installed, available in your $PATH, and (where necessary) authorised:
    1. Google Cloud SDK - quickstarts
      1. Installation
      2. Authorisation
    2. jq
      1. Installation
    3. Terraform
      1. Installation
  2. Get started on the GCP Free Tier and create a new Google Cloud project
    • Note: you are responsible for the running costs incurred by this project beyond the limits of the Free Tier. Every effort has been made to optimise and minimise the costs of resource usage, and as of this writing running a server for ~50 hours a month cost less than £5 in total, but this is an isolated example from a sample size of 1.
  3. Set the CLOUDSDK_CORE_PROJECT environment variable to the Google Cloud project ID
    1. For example: export CLOUDSDK_CORE_PROJECT=my-factorio-server-kit
  4. Run up the Terraform stack to provision infrastructure in GCP (implemented? -> ❌/✅)
    1. Cloud Pub/Sub topic cleanup-instances
    2. Cloud Scheduler job cleanup-instances to publish to topic ✅
    3. Cloud Function cleanup-instances to clean up terminated instances, triggered by topic ✅
    4. Cloud Storage buckets
      1. <project>-backup-saves
      2. <project>-saves-<location>
      3. <project>-storage
    5. Cloud DNS (optional)
      1. Managed zone ❌
      2. Record set ❌
  5. Run the Cloud Build pipelines in order
    1. Packer builder Docker image
    2. Factorio server VM image

As desired

  1. Fire off the roll-vm.sh Bash script described below

Usage

The project is primarily driven by Bash scripts, supported by Cloud Build pipelines and Terraform infrastructure-as-code.

Cloud Build pipelines

Terraform IaC

Bash scripts

  • roll-vm.sh - the main point of execution; will run up a GCE VM hosting Docker containers for the Factorio server itself, as well as additional containers with Grafana and Prometheus that tie into Graftorio
    • the location/region that the VM will deploy to follows a default based on the locations.json file, and can be overridden with a --<location> flag; see roll-vm.sh --help for more information
    • the machine type of the VM can be specified with the --machine-type=... flag
  • delete-vm.sh - deletes any VMs currently running in the project, optionally filtering by name

Library

Each of the above scripts taps into a common library of functionality under the lib directory.

Other notes

Map (re)generation settings

The two settings files map-settings.json and map-gen-settings.json can be created from a map exchange string in the game as outlined here.

Upstream issues outstanding

Related projects

goppuku

goppuku is a small Go binary/service I built to have a server shut itself down if the player count stays at zero for fifteen consecutive minutes.

The latest release of goppuku is installed in the Factorio server image by Packer's provisioner script.

Author

👤 James Lucktaylor

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update documentation and tests as appropriate.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2020 James Lucktaylor.

This project is licensed with the Unlicense.


This README was generated with ❤️ by readme-md-generator