Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Tests

on:
pull_request:
push:
branches:
- master

jobs:
regression:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Run regression tests
run: python3 -m unittest discover -s tests -v
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Factorio [![Docker Version](https://img.shields.io/docker/v/factoriotools/factorio?sort=semver)](https://hub.docker.com/r/factoriotools/factorio/) [![Docker Pulls](https://img.shields.io/docker/pulls/factoriotools/factorio.svg?maxAge=600)](https://hub.docker.com/r/factoriotools/factorio/) [![Docker Stars](https://img.shields.io/docker/stars/factoriotools/factorio.svg?maxAge=600)](https://hub.docker.com/r/factoriotools/factorio/)

> [!NOTE]
> Support for ARM is experimental. Expect crashes and lag if you try to run this on a raspberry pi.
> ARM64 images for Factorio 2.1 and newer run the native `linux-arm64` headless build. Older versions have no native build and run the x64 build under box64 emulation, which is experimental: expect crashes and lag if you try to run those on a raspberry pi.

[中文](./README_zh_CN.md)

Expand Down
15 changes: 11 additions & 4 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ def push_singlearch(tags):
exit(1)


def build_and_push(sha256, version, tags, push, multiarch, dockerfile="Dockerfile", builder_suffix=""):
def build_and_push(sha256, version, tags, push, multiarch, dockerfile="Dockerfile", builder_suffix="",
sha256_arm64=None):
build_dir = tempfile.mktemp()
shutil.copytree("docker", build_dir)
build_args = ["-f", dockerfile, "--build-arg", f"VERSION={version}", "--build-arg", f"SHA256={sha256}", "."]
build_args = ["-f", dockerfile, "--build-arg", f"VERSION={version}", "--build-arg", f"SHA256={sha256}"]
if sha256_arm64:
# Native ARM64 archive available: the arm64 image runs it instead of the x64 build under box64
build_args.extend(["--build-arg", f"SHA256_ARM64={sha256_arm64}"])
build_args.append(".")
for tag in tags:
build_args.extend(["-t", f"factoriotools/factorio:{tag}"])

Expand Down Expand Up @@ -131,7 +136,8 @@ def main():
for version, buildinfo in versions_to_build:
sha256 = buildinfo["sha256"]
tags = buildinfo["tags"]
build_and_push(sha256, version, tags, args.push_tags, args.multiarch)
build_and_push(sha256, version, tags, args.push_tags, args.multiarch,
sha256_arm64=buildinfo.get("sha256_arm64"))

# Build rootless images
if build_rootless:
Expand All @@ -150,7 +156,8 @@ def main():
original_tags = buildinfo["tags"]
rootless_tags = generate_rootless_tags(original_tags)
build_and_push(sha256, version, rootless_tags, args.push_tags, args.multiarch,
dockerfile="Dockerfile.rootless", builder_suffix="-rootless")
dockerfile="Dockerfile.rootless", builder_suffix="-rootless",
sha256_arm64=buildinfo.get("sha256_arm64"))


if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions buildinfo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"2.1.24": {
"sha256": "c49b66cff90aceff87b30f2973af0df7f51712cb2ee3153e0169d9bed46a964f",
"sha256_arm64": "141bd7aaa199fcf7e223dcaca8877aec1d6deaa9c4ac03b7a8c60ef37b6afb98",
"tags": [
"latest",
"stable",
Expand Down
19 changes: 14 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# build rcon client
FROM debian:stable-slim AS rcon-builder
RUN apt-get -q update \
&& DEBIAN_FRONTEND=noninteractive apt-get -qy install build-essential
&& DEBIAN_FRONTEND=noninteractive apt-get -qy install build-essential --no-install-recommends

WORKDIR /src
COPY rcon/ /src
Expand All @@ -16,6 +16,8 @@ ARG GROUP=factorio
ARG PUID=845
ARG PGID=845
ARG BOX64_VERSION=v0.2.4
# sha256 of the native linux-arm64 archive (2.1+); empty means x64 build under box64
ARG SHA256_ARM64

# optionally utilize a built-in map-gen-preset (see data/base/prototypes/map-gen-presets
# if this is used, the preset will be used over any .json files supplied
Expand Down Expand Up @@ -44,7 +46,7 @@ SHELL ["/bin/bash", "-eo", "pipefail", "-c"]

RUN apt-get -q update \
&& DEBIAN_FRONTEND=noninteractive apt-get -qy install ca-certificates curl jq pwgen xz-utils procps gettext-base file --no-install-recommends \
&& if [[ "$(uname -m)" == "aarch64" ]]; then \
&& if [[ "$(uname -m)" == "aarch64" && -z "${SHA256_ARM64}" ]]; then \
echo "installing ARM compatability layer" \
&& DEBIAN_FRONTEND=noninteractive apt-get -qy install unzip --no-install-recommends \
&& curl -LO https://github.com/ptitSeb/box64/releases/download/${BOX64_VERSION}/box64-GENERIC_ARM-RelWithDebInfo.zip \
Expand Down Expand Up @@ -75,14 +77,21 @@ RUN set -ox pipefail \
echo "build-arg SHA256 is required" \
&& exit 1; \
fi \
&& archive="/tmp/factorio_headless_x64_$VERSION.tar.xz" \
&& if [[ "$(uname -m)" == "aarch64" && -n "${SHA256_ARM64}" ]]; then \
platform="linux-arm64" && sha256="${SHA256_ARM64}"; \
else \
platform="linux64" && sha256="${SHA256}"; \
fi \
&& archive="/tmp/factorio_headless_${platform}_$VERSION.tar.xz" \
&& mkdir -p /opt /factorio \
&& curl -sSL "https://www.factorio.com/get-download/$VERSION/headless/linux64" -o "$archive" --retry $CURL_RETRIES \
&& echo "$SHA256 $archive" | sha256sum -c \
&& curl -sSL "https://www.factorio.com/get-download/$VERSION/headless/$platform" -o "$archive" --retry $CURL_RETRIES \
&& echo "$sha256 $archive" | sha256sum -c \
|| (sha256sum "$archive" && file "$archive" && exit 1) \
&& tar xf "$archive" --directory /opt \
&& chmod ugo=rwx /opt/factorio \
&& rm "$archive" \
# the native arm64 archive ships bin/arm64; keep the bin/x64 path the scripts use
&& if [[ -d /opt/factorio/bin/arm64 && ! -e /opt/factorio/bin/x64 ]]; then ln -s arm64 /opt/factorio/bin/x64; fi \
&& ln -s "$SCENARIOS" /opt/factorio/scenarios \
&& ln -s "$SAVES" /opt/factorio/saves \
&& mkdir -p /opt/factorio/config/ \
Expand Down
17 changes: 13 additions & 4 deletions docker/Dockerfile.rootless
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ FROM debian:stable-slim
LABEL maintainer="https://github.com/factoriotools/factorio-docker"

ARG BOX64_VERSION=v0.2.4
# sha256 of the native linux-arm64 archive (2.1+); empty means x64 build under box64
ARG SHA256_ARM64

# optionally utilize a built-in map-gen-preset (see data/base/prototypes/map-gen-presets
ARG PRESET
Expand All @@ -33,7 +35,7 @@ SHELL ["/bin/bash", "-eo", "pipefail", "-c"]

RUN apt-get -q update \
&& DEBIAN_FRONTEND=noninteractive apt-get -qy install ca-certificates curl jq pwgen xz-utils procps gettext-base --no-install-recommends \
&& if [[ "$(uname -m)" == "aarch64" ]]; then \
&& if [[ "$(uname -m)" == "aarch64" && -z "${SHA256_ARM64}" ]]; then \
echo "installing ARM compatability layer" \
&& DEBIAN_FRONTEND=noninteractive apt-get -qy install unzip --no-install-recommends \
&& curl -LO https://github.com/ptitSeb/box64/releases/download/${BOX64_VERSION}/box64-GENERIC_ARM-RelWithDebInfo.zip \
Expand Down Expand Up @@ -61,14 +63,21 @@ RUN set -ox pipefail \
echo "build-arg SHA256 is required" \
&& exit 1; \
fi \
&& archive="/tmp/factorio_headless_x64_$VERSION.tar.xz" \
&& if [[ "$(uname -m)" == "aarch64" && -n "${SHA256_ARM64}" ]]; then \
platform="linux-arm64" && sha256="${SHA256_ARM64}"; \
else \
platform="linux64" && sha256="${SHA256}"; \
fi \
&& archive="/tmp/factorio_headless_${platform}_$VERSION.tar.xz" \
&& mkdir -p /opt /factorio \
&& curl -sSL "https://www.factorio.com/get-download/$VERSION/headless/linux64" -o "$archive" --retry $CURL_RETRIES \
&& echo "$SHA256 $archive" | sha256sum -c \
&& curl -sSL "https://www.factorio.com/get-download/$VERSION/headless/$platform" -o "$archive" --retry $CURL_RETRIES \
&& echo "$sha256 $archive" | sha256sum -c \
|| (sha256sum "$archive" && file "$archive" && exit 1) \
&& tar xf "$archive" --directory /opt \
&& chmod ugo=rwx /opt/factorio \
&& rm "$archive" \
# the native arm64 archive ships bin/arm64; keep the bin/x64 path the scripts use
&& if [[ -d /opt/factorio/bin/arm64 && ! -e /opt/factorio/bin/x64 ]]; then ln -s arm64 /opt/factorio/bin/x64; fi \
&& ln -s "$SCENARIOS" /opt/factorio/scenarios \
&& ln -s "$SAVES" /opt/factorio/saves \
&& mkdir -p /opt/factorio/config/
Expand Down
1 change: 1 addition & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
# https://github.com/factoriotools/factorio-docker/blob/master/buildinfo.json
- VERSION=2.1.24
- SHA256=c49b66cff90aceff87b30f2973af0df7f51712cb2ee3153e0169d9bed46a964f
- SHA256_ARM64=141bd7aaa199fcf7e223dcaca8877aec1d6deaa9c4ac03b7a8c60ef37b6afb98
ports:
- "34197:34197/udp"
- "27015:27015/tcp"
Expand Down
124 changes: 124 additions & 0 deletions tests/test_native_arm64.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"""Regression tests: python3 -m unittest discover -s tests -v."""

import importlib.util
import json
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
from unittest.mock import patch

ROOT = Path(__file__).resolve().parents[1]


class UpdateTests(unittest.TestCase):
def run_update(self, stable, experimental, arm_versions, current=None):
with tempfile.TemporaryDirectory() as directory:
work = Path(directory)
bin_dir = work / "bin"
bin_dir.mkdir()
(work / "docker").mkdir()
(work / "README.md").write_text(
"<!-- start autogeneration tags -->\nold\n<!-- end autogeneration tags -->\n"
)
(work / "buildinfo.json").write_text(json.dumps(current or {
"2.0.76": {"sha256": "old", "tags": ["stable", "latest"]}
}))
releases = {"stable": {"headless": stable}, "experimental": {"headless": experimental}}
sums = []
for version in sorted({stable, experimental}):
# Both historical and new upstream archive names remain supported.
name = "factorio_headless_x64" if version.startswith("2.0.") else "factorio-headless_linux"
sums.append(f"{'b' * 64} {name}_{version}.tar.xz")
if version in arm_versions:
sums.append(f"{'a' * 64} factorio-headless_linux-arm64_{version}.tar.xz")
(work / "releases.json").write_text(json.dumps(releases))
(work / "sums.txt").write_text("\n".join(sums) + "\n")
commands = {
"curl": '#!/bin/sh\ncase "$1" in *latest-releases) cat releases.json;; *sha256sums/) cat sums.txt;; *) exit 99;; esac\n',
"git": '#!/bin/sh\nprintf "%s\\n" "$*" >> git-calls\n',
"yq": '#!/bin/sh\nprintf "%s\\n" "${sov:-}${sha:-}${sha_arm64:-}" >> compose-args\n',
}
for name, contents in commands.items():
command = bin_dir / name
command.write_text(contents)
command.chmod(0o755)
env = {**os.environ, "PATH": f"{bin_dir}:{os.environ['PATH']}"}
result = subprocess.run(["bash", str(ROOT / "update.sh")], cwd=work,
env=env, text=True, capture_output=True)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertEqual(result.stderr, "", result.stderr)
data = json.loads((work / "buildinfo.json").read_text())
compose = (work / "compose-args").read_text() if (work / "compose-args").exists() else ""
published = (work / "git-calls").exists()
return data, compose, published

def test_release_transitions(self):
cases = [
("2.0.77", "2.1.24", {"2.1.24"}),
("2.1.23", "2.1.24", {"2.1.23", "2.1.24"}),
("2.1.24", "2.1.24", {"2.1.24"}),
("2.0.77", "2.0.77", set()),
]
for stable, experimental, arm in cases:
with self.subTest(stable=stable, experimental=experimental):
data, compose, published = self.run_update(stable, experimental, arm)
self.assertEqual(set(data), {stable, experimental})
self.assertIn("stable", data[stable]["tags"])
self.assertIn("latest", data[experimental]["tags"])
for version, info in data.items():
self.assertEqual(info["sha256"], "b" * 64)
self.assertEqual(info.get("sha256_arm64"), "a" * 64 if version in arm else None)
self.assertIn("SHA256_ARM64=" + ("a" * 64 if stable in arm else "") + "\n", compose)
self.assertTrue(published)

def test_unchanged_versions_do_not_publish(self):
current = {"2.1.24": {"sha256": "b" * 64, "sha256_arm64": "a" * 64,
"tags": ["stable", "latest"]}}
data, compose, published = self.run_update("2.1.24", "2.1.24", {"2.1.24"}, current)
self.assertEqual(data, current)
self.assertEqual(compose, "")
self.assertFalse(published)


class BuildTests(unittest.TestCase):
def setUp(self):
spec = importlib.util.spec_from_file_location("factorio_build", ROOT / "build.py")
self.build = importlib.util.module_from_spec(spec)
spec.loader.exec_module(self.build)

def test_build_arguments(self):
for multiarch in (False, True):
for dockerfile in ("Dockerfile", "Dockerfile.rootless"):
for arm_sha in (None, "a" * 64):
with self.subTest(multiarch=multiarch, dockerfile=dockerfile, arm_sha=arm_sha):
with patch.object(self.build.shutil, "copytree"), \
patch.object(self.build, "build_singlearch") as single, \
patch.object(self.build, "build_and_push_multiarch") as multi:
self.build.build_and_push("b" * 64, "2.1.24", ["test"], False,
multiarch, dockerfile=dockerfile,
sha256_arm64=arm_sha)
args = (multi if multiarch else single).call_args.args[1]
self.assertEqual(args[:2], ["-f", dockerfile])
self.assertIn("SHA256=" + "b" * 64, args)
self.assertEqual("SHA256_ARM64=" + "a" * 64 in args, bool(arm_sha))

def test_main_passes_checksum_to_both_variants(self):
data = {
"2.0.77": {"sha256": "b" * 64, "tags": ["stable"]},
"2.1.24": {"sha256": "c" * 64, "sha256_arm64": "a" * 64, "tags": ["latest"]},
}
with patch.object(self.build.json, "load", return_value=data), \
patch.object(self.build, "build_and_push") as build, \
patch("sys.argv", ["build.py", "--both"]):
self.build.main()
self.assertEqual(build.call_count, 4)
for call in build.call_args_list:
self.assertEqual(call.kwargs.get("sha256_arm64"), data[call.args[1]].get("sha256_arm64"))
self.assertEqual(sum(call.kwargs.get("dockerfile") == "Dockerfile.rootless"
for call in build.call_args_list), 2)


if __name__ == "__main__":
unittest.main()
Loading
Loading