From b8ad6e06abb68c392921a1e7949d63724c6933e9 Mon Sep 17 00:00:00 2001 From: Florian Kinder Date: Sun, 31 Aug 2025 22:21:22 +0900 Subject: [PATCH 1/2] Fix ARM64 emulation support in all entrypoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add shared setup-exec.sh script to handle ARM64 emulation logic - Update scenario.sh and scenario2map.sh to use box64 emulation on ARM64 - Refactor docker-entrypoint.sh and docker-entrypoint-rootless.sh to use shared script - Ensures all factorio binary calls work correctly on ARM64 platforms Fixes #585 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- docker/files/docker-entrypoint-rootless.sh | 6 ++---- docker/files/docker-entrypoint.sh | 8 +++----- docker/files/scenario.sh | 7 ++++++- docker/files/scenario2map.sh | 7 ++++++- docker/files/setup-exec.sh | 16 ++++++++++++++++ 5 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 docker/files/setup-exec.sh diff --git a/docker/files/docker-entrypoint-rootless.sh b/docker/files/docker-entrypoint-rootless.sh index 129dc4fbf..a1aa8d9b7 100755 --- a/docker/files/docker-entrypoint-rootless.sh +++ b/docker/files/docker-entrypoint-rootless.sh @@ -53,10 +53,8 @@ fi # In rootless mode, we don't need to handle user switching or chown # The container runs as the specified user from the start EXEC="" -if [[ -f /bin/box64 ]]; then - # Use emulator for ARM hosts - EXEC="/bin/box64" -fi +# Setup ARM64 emulation support +source "${INSTALLED_DIRECTORY}/setup-exec.sh" # Update config path sed -i '/write-data=/c\write-data=\/factorio/' /opt/factorio/config/config.ini diff --git a/docker/files/docker-entrypoint.sh b/docker/files/docker-entrypoint.sh index 05277d522..84ef3cee9 100755 --- a/docker/files/docker-entrypoint.sh +++ b/docker/files/docker-entrypoint.sh @@ -56,11 +56,9 @@ if [[ $(id -u) == 0 ]]; then # Drop to the factorio user EXEC="runuser -u factorio -g factorio --" fi -if [[ -f /bin/box64 ]]; then - # Use an emulator to run on ARM hosts - # this only gets installed when the target docker platform is linux/arm64 - EXEC="$EXEC /bin/box64" -fi + +# Setup ARM64 emulation support +source "${INSTALLED_DIRECTORY}/setup-exec.sh" sed -i '/write-data=/c\write-data=\/factorio/' /opt/factorio/config/config.ini diff --git a/docker/files/scenario.sh b/docker/files/scenario.sh index f108ca634..4bd2eaabe 100755 --- a/docker/files/scenario.sh +++ b/docker/files/scenario.sh @@ -1,5 +1,6 @@ #!/bin/bash set -eoux pipefail +INSTALLED_DIRECTORY=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")") if [[ -z ${1:-} ]]; then echo "No argument supplied" @@ -31,7 +32,11 @@ 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 \ +# Setup ARM64 emulation support +EXEC="" +source "${INSTALLED_DIRECTORY}/setup-exec.sh" + +exec $EXEC /opt/factorio/bin/x64/factorio \ --port "$PORT" \ --start-server-load-scenario "$SERVER_SCENARIO" \ --preset "$PRESET" \ diff --git a/docker/files/scenario2map.sh b/docker/files/scenario2map.sh index 94c4dd23d..c0a10757a 100755 --- a/docker/files/scenario2map.sh +++ b/docker/files/scenario2map.sh @@ -1,5 +1,6 @@ #!/bin/bash set -eoux pipefail +INSTALLED_DIRECTORY=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")") if [[ -z ${1:-} ]]; then echo "No argument supplied" @@ -23,5 +24,9 @@ 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 \ +# Setup ARM64 emulation support +EXEC="" +source "${INSTALLED_DIRECTORY}/setup-exec.sh" + +exec $EXEC /opt/factorio/bin/x64/factorio \ --scenario2map "$SERVER_SCENARIO" diff --git a/docker/files/setup-exec.sh b/docker/files/setup-exec.sh new file mode 100644 index 000000000..5ab85338b --- /dev/null +++ b/docker/files/setup-exec.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Setup EXEC variable for running Factorio with ARM64 emulation support +# This script handles ARM64 emulation and can be combined with user switching as needed + +# If EXEC is not already set, initialize it +if [[ -z "${EXEC:-}" ]]; then + EXEC="" +fi + +if [[ -f /bin/box64 ]]; then + # Use an emulator to run on ARM hosts + # this only gets installed when the target docker platform is linux/arm64 + EXEC="$EXEC /bin/box64" +fi + +export EXEC \ No newline at end of file From 17ec12cb7f5a395f83028f48a27583b30e2d758e Mon Sep 17 00:00:00 2001 From: Florian Kinder Date: Sun, 31 Aug 2025 22:31:45 +0900 Subject: [PATCH 2/2] Fix shellcheck warnings in entrypoint scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add shellcheck disable=SC1091 for dynamic source paths - Quote INSTALLED_DIRECTORY variables to prevent word splitting - Resolves all reported shellcheck issues in PR review 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- docker/files/docker-entrypoint-rootless.sh | 1 + docker/files/docker-entrypoint.sh | 5 +++-- docker/files/scenario.sh | 1 + docker/files/scenario2map.sh | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docker/files/docker-entrypoint-rootless.sh b/docker/files/docker-entrypoint-rootless.sh index a1aa8d9b7..2b91698a7 100755 --- a/docker/files/docker-entrypoint-rootless.sh +++ b/docker/files/docker-entrypoint-rootless.sh @@ -54,6 +54,7 @@ fi # The container runs as the specified user from the start EXEC="" # Setup ARM64 emulation support +# shellcheck disable=SC1091 source "${INSTALLED_DIRECTORY}/setup-exec.sh" # Update config path diff --git a/docker/files/docker-entrypoint.sh b/docker/files/docker-entrypoint.sh index 84ef3cee9..fd9537bca 100755 --- a/docker/files/docker-entrypoint.sh +++ b/docker/files/docker-entrypoint.sh @@ -41,10 +41,10 @@ if [[ $NRTMPSAVES -gt 0 ]]; then fi if [[ ${UPDATE_MODS_ON_START:-} == "true" ]]; then - ${INSTALLED_DIRECTORY}/docker-update-mods.sh + "${INSTALLED_DIRECTORY}"/docker-update-mods.sh fi -${INSTALLED_DIRECTORY}/docker-dlc.sh +"${INSTALLED_DIRECTORY}"/docker-dlc.sh EXEC="" if [[ $(id -u) == 0 ]]; then @@ -58,6 +58,7 @@ if [[ $(id -u) == 0 ]]; then fi # Setup ARM64 emulation support +# shellcheck disable=SC1091 source "${INSTALLED_DIRECTORY}/setup-exec.sh" sed -i '/write-data=/c\write-data=\/factorio/' /opt/factorio/config/config.ini diff --git a/docker/files/scenario.sh b/docker/files/scenario.sh index 4bd2eaabe..a98d9d9ca 100755 --- a/docker/files/scenario.sh +++ b/docker/files/scenario.sh @@ -34,6 +34,7 @@ fi # Setup ARM64 emulation support EXEC="" +# shellcheck disable=SC1091 source "${INSTALLED_DIRECTORY}/setup-exec.sh" exec $EXEC /opt/factorio/bin/x64/factorio \ diff --git a/docker/files/scenario2map.sh b/docker/files/scenario2map.sh index c0a10757a..7f40d3a25 100755 --- a/docker/files/scenario2map.sh +++ b/docker/files/scenario2map.sh @@ -26,6 +26,7 @@ fi # Setup ARM64 emulation support EXEC="" +# shellcheck disable=SC1091 source "${INSTALLED_DIRECTORY}/setup-exec.sh" exec $EXEC /opt/factorio/bin/x64/factorio \