Compare commits

...

5 Commits

Author SHA1 Message Date
8a1c6ac27b Fix mod version compatibility checking for major version differences
This fixes issue #517 where the auto mod updater was downloading the wrong
mod versions after updating to Space Age (Factorio 2.0). The problem was that
the version checking logic was incorrectly rejecting compatible mod versions.

Changes:
- Fixed check_game_version() to properly handle major version differences
- Game versions can now run mods designed for older major versions (backward compatibility)
- Game versions correctly reject mods requiring newer versions
- Fixed variable references in check_dependency_version()
- Added clarifying comments about the version checking behavior

This also addresses issue #468 by ensuring mods requiring newer Factorio
versions than currently installed are properly skipped.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-06 16:32:39 +09:00
9464758a7b Updated mods updater script to correctly process mod dependencies (#557)
Co-authored-by: Victor <victor@blockbank.ai>
2025-07-03 19:48:23 +09:00
50f04fb096 Fix README tag pollution from update script (#573)
* fix: Improve README tag generation to reduce clutter

- Modified update.sh to only show the latest and stable versions
- Removed duplicate major.minor version tags
- Changed from listing all versions to showing only the most relevant tags
- Fixed jq query to properly detect stable version using index() instead of contains()

This significantly reduces README pollution by showing only:
- The latest experimental version with its tags
- The current stable version with its tags
- One entry per major.minor version for older releases (removed from this commit)

Before: 60+ lines of tags with many duplicates
After: 2 lines showing only latest and stable versions

* fix: Address shellcheck warnings about subshell variable modifications

- Changed from pipeline to process substitution to avoid SC2030/SC2031 warnings
- Variables modified in the while loop are now properly preserved
- This ensures readme_tags modifications are not lost in subshells
2025-07-03 19:45:29 +09:00
15d31c9a2e docs: Add documentation for PRESET environment variable (#572)
- Add PRESET to the environment variables table
- Include detailed explanation of available preset values
- Add example showing how to use PRESET when generating a new map
- Document that PRESET is optional and only used with GENERATE_NEW_SAVE=true

Fixes #571

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-07-03 19:32:40 +09:00
8784845385 Add CLAUDE.md with project guidance for Claude Code
- Project overview and architecture description
- Common development commands for building and testing
- Environment variables and configuration details
- Version management and automated update process
- Volume structure and data organization

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-03 19:22:52 +09:00
4 changed files with 349 additions and 60 deletions

114
CLAUDE.md Normal file
View File

@ -0,0 +1,114 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
This is a Docker image for running a Factorio headless server. It provides automated builds for multiple Factorio versions (stable and experimental) and supports both AMD64 and ARM64 architectures.
## Architecture
### Key Components
1. **Docker Image Build System**
- `build.py` - Python script that builds Docker images from `buildinfo.json`
- `docker/Dockerfile` - Main Dockerfile that creates the Factorio server image
- `buildinfo.json` - Contains version info, SHA256 checksums, and tags for all supported versions
- Supports multi-architecture builds (linux/amd64, linux/arm64) using Docker buildx
2. **Automated Updates**
- `update.sh` - Checks for new Factorio releases and updates `buildinfo.json`
- Updates README.md with new version tags
- Commits changes and tags releases automatically
- Run by GitHub Actions to keep images up-to-date
3. **Container Scripts**
- `docker/files/docker-entrypoint.sh` - Main entrypoint that configures and starts the server
- `docker/files/docker-update-mods.sh` - Updates mods on server start
- `docker/files/docker-dlc.sh` - Manages DLC (Space Age) activation
- `docker/files/scenario.sh` - Alternative entrypoint for launching scenarios
- `docker/files/players-online.sh` - Checks if players are online (for watchtower integration)
4. **RCON Client**
- `docker/rcon/` - C source for RCON client, built during Docker image creation
- Allows sending commands to the running server
## Common Development Commands
### Building Images
```bash
# Build a single architecture image locally
python3 build.py
# Build and push multi-architecture images
python3 build.py --multiarch --push-tags
```
### Running the Container
```bash
# Basic run command
docker run -d \
-p 34197:34197/udp \
-p 27015:27015/tcp \
-v /opt/factorio:/factorio \
--name factorio \
factoriotools/factorio
# Using docker-compose
docker-compose up -d
```
### Linting
```bash
# Lint Dockerfiles
./lint.sh
```
### Testing Updates
```bash
# Check for new Factorio versions and update buildinfo.json
./update.sh
```
## Key Configuration
### Environment Variables
- `LOAD_LATEST_SAVE` - Load the most recent save (default: true)
- `GENERATE_NEW_SAVE` - Generate a new save if none exists (default: false)
- `SAVE_NAME` - Name of the save file to load/create
- `UPDATE_MODS_ON_START` - Update mods before starting (requires USERNAME/TOKEN)
- `DLC_SPACE_AGE` - Enable/disable Space Age DLC (default: true)
- `PORT` - UDP port for game server (default: 34197)
- `RCON_PORT` - TCP port for RCON (default: 27015)
### Volume Structure
All data is stored in a single volume mounted at `/factorio`:
```
/factorio/
├── config/ # Server configuration files
├── mods/ # Game modifications
├── saves/ # Save games
├── scenarios/ # Scenario files
└── script-output/ # Script output directory
```
## Version Management
The project maintains compatibility with multiple Factorio versions:
- Latest experimental version gets the `latest` tag
- Latest stable version gets the `stable` tag
- Each version also gets specific tags (e.g., `2.0.55`, `2.0`, `2`)
- Legacy versions back to 0.12 are supported
Version updates are automated via GitHub Actions that run `update.sh` periodically.
## Testing Changes
1. Modify `buildinfo.json` to test specific versions
2. Run `python3 build.py` to build locally
3. Test the container with your local data volume
4. For production changes, ensure `update.sh` handles version transitions correctly

View File

@ -6,59 +6,9 @@
[中文](./README_zh_CN.md) [中文](./README_zh_CN.md)
<!-- start autogeneration tags --> <!-- start autogeneration tags -->
* `2.0.58`, `latest` * `latest, 2.0.58`
* `2.0.57` * `2, 2.0, 2.0.55, stable, stable-2.0.55`
* `2`, `2.0`, `2.0.55`, `stable`, `stable-2.0.55` <!-- end autogeneration tags -->
* `2.0.54`
* `2.0.53`
* `2.0.52`
* `2.0.51`
* `2.0.50`
* `2.0.49`
* `2.0.48`
* `2.0`, `2.0.47`, `stable-2.0.47`
* `2.0.46`
* `2.0.45`
* `2.0.44`
* `2.0`, `2.0.43`, `stable-2.0.43`
* `2.0`, `2.0.42`, `stable-2.0.42`
* `2.0`, `2.0.41`, `stable-2.0.41`
* `2.0.40`
* `2.0`, `2.0.39`, `stable-2.0.39`
* `2.0.38`
* `2.0.37`
* `2.0.36`
* `2.0.35`
* `2.0.34`
* `2.0.33`
* `2.0`, `2.0.32`, `stable-2.0.32`
* `2.0.31`
* `2.0`, `2.0.30`, `stable-2.0.30`
* `2.0.29`
* `2.0`, `2.0.28`, `stable-2.0.28`
* `2.0.27`
* `2.0.26`
* `2.0.25`
* `2.0.24`
* `2.0`, `2.0.23`, `stable-2.0.23`
* `2.0.22`
* `2.0`, `2.0.21`, `stable-2.0.21`
* `2.0`, `2.0.20`, `stable-2.0.20`
* `2.0.19`
* `2.0.18`
* `2.0.17`
* `2.0.16`
* `2.0`, `2.0.15`, `stable-2.0.15`
* `2.0`, `2.0.14`, `stable-2.0.14`
* `2.0`, `2.0.13`, `stable-2.0.13`
* `1`, `1.1`, `1.1.110`, `stable-1.1.110`
* `1.0`, `1.0.0`
* `0.17`, `0.17.79`
* `0.16`, `0.16.51`
* `0.15`, `0.15.40`
* `0.14`, `0.14.23`
* `0.13`, `0.13.20`
* `0.12`, `0.12.35`<!-- end autogeneration tags -->
## Tag descriptions ## Tag descriptions
@ -203,6 +153,22 @@ sudo docker run -d \
factoriotools/factorio factoriotools/factorio
``` ```
To generate a new map with a specific preset (e.g., death-world):
```shell
sudo docker run -d \
-p 34197:34197/udp \
-p 27015:27015/tcp \
-v /opt/factorio:/factorio \
-e LOAD_LATEST_SAVE=false \
-e GENERATE_NEW_SAVE=true \
-e SAVE_NAME=replaceme \
-e PRESET=death-world \
--name factorio \
--restart=unless-stopped \
factoriotools/factorio
```
### Mods ### Mods
Copy mods into the mods folder and restart the server. Copy mods into the mods folder and restart the server.
@ -321,6 +287,7 @@ These are the environment variables which can be specified at container run time
| BIND | IP address (v4 or v6) the server listens on (IP\[:PORT]) | | 0.15+ | | BIND | IP address (v4 or v6) the server listens on (IP\[:PORT]) | | 0.15+ |
| RCON_PORT | TCP port the rcon server listens on | 27015 | 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+ | | SAVE_NAME | Name to use for the save file | _autosave1 | 0.17+ |
| PRESET | Map generation preset when GENERATE_NEW_SAVE is true | | 0.17+ |
| TOKEN | factorio.com token | | 0.17+ | | TOKEN | factorio.com token | | 0.17+ |
| UPDATE_MODS_ON_START | If mods should be updated before starting the server | | 0.17+ | | UPDATE_MODS_ON_START | If mods should be updated before starting the server | | 0.17+ |
| USERNAME | factorio.com username | | 0.17+ | | USERNAME | factorio.com username | | 0.17+ |
@ -330,6 +297,20 @@ These are the environment variables which can be specified at container run time
**Note:** All environment variables are compared as strings **Note:** All environment variables are compared as strings
#### PRESET Values
The `PRESET` environment variable is used when generating a new map (when `GENERATE_NEW_SAVE=true`). It corresponds to Factorio's built-in map generation presets. Common values include:
- `default` - Normal settings
- `rich-resources` - Resources are more abundant
- `marathon` - Recipes and technologies are more expensive
- `death-world` - Biters are more aggressive and numerous
- `death-world-marathon` - Combines death-world and marathon settings
- `rail-world` - Resources are further apart, encouraging train usage
- `ribbon-world` - Map height is limited for a unique challenge
If PRESET is not specified or left empty, the map will be generated using the settings from `map-gen-settings.json` and `map-settings.json` without a preset.
## Container Details ## Container Details
The philosophy is to [keep it simple](http://wiki.c2.com/?KeepItSimple). The philosophy is to [keep it simple](http://wiki.c2.com/?KeepItSimple).

View File

@ -23,6 +23,141 @@ print_failure()
echo "$1" echo "$1"
} }
# Checks if the current game version satisfies the mod's minimum required version.
# Returns 1 if the game version is compatible with the mod, 0 if not
check_game_version() {
local mod_required_version="$1" # The minimum Factorio version required by the mod
local current_game_version="$2" # The current Factorio version
local mod_major mod_minor game_major game_minor
mod_major=$(echo "$mod_required_version" | cut -d '.' -f1)
mod_minor=$(echo "$mod_required_version" | cut -d '.' -f2)
game_major=$(echo "$current_game_version" | cut -d '.' -f1)
game_minor=$(echo "$current_game_version" | cut -d '.' -f2)
# If game major version is greater than mod's required major version, it's compatible
if [[ "$game_major" -gt "$mod_major" ]]; then
echo 1
return
fi
# If game major version is less than mod's required major version, it's not compatible
if [[ "$game_major" -lt "$mod_major" ]]; then
echo 0
return
fi
# Major versions are equal, check minor versions
# Game minor version must be >= mod's required minor version
if [[ "$game_minor" -ge "$mod_minor" ]]; then
echo 1
else
echo 0
fi
}
# Checks dependency string with provided version.
# Only checks for operator based string, ignoring everything else
# Returns 1 if check is ok, 0 if not
check_dependency_version()
{
local dependency="$1"
local mod_version="$2"
if [[ "$dependency" =~ ^(\?|!|~|\(~\)) ]]; then
echo 1
fi
local condition
condition=$(echo "$dependency" | grep -oE '(>=|<=|>|<|=) [0-9]+(\.[0-9]+)*')
if [[ -z "$condition" ]]; then
echo 1
fi
local operator required_version
operator=$(echo "$condition" | awk '{print $1}')
required_version=$(echo "$condition" | awk '{print $2}')
case "$operator" in
">=")
if [[ "$(printf '%s\n%s\n' "$required_version" "$mod_version" | sort -V | head -n1)" == "$required_version" ]]; then
echo 1
else
echo 0
fi
;;
">")
if [[ "$(printf '%s\n%s\n' "$required_version" "$mod_version" | sort -V | head -n1)" == "$required_version" && "$required_version" != "$mod_version" ]]; then
echo 1
else
echo 0
fi
;;
"<=")
if [[ "$(printf '%s\n%s\n' "$required_version" "$mod_version" | sort -V | tail -n1)" == "$required_version" ]]; then
echo 1
else
echo 0
fi
;;
"<")
if [[ "$(printf '%s\n%s\n' "$required_version" "$mod_version" | sort -V | tail -n1)" == "$required_version" && "$required_version" != "$mod_version" ]]; then
echo 1
else
echo 0
fi
;;
"=")
if [[ "$mod_version" == "$required_version" ]]; then
echo 1
else
echo 0
fi
;;
*)
echo 0
;;
esac
}
get_mod_info()
{
local mod_info_json="$1"
# Process mod releases from newest to oldest, looking for a compatible version
while IFS= read -r mod_release_info; do
local mod_version mod_factorio_version
mod_version=$(echo "$mod_release_info" | jq -r ".version")
mod_factorio_version=$(echo "$mod_release_info" | jq -r ".info_json.factorio_version")
# Check if this mod version is compatible with our Factorio version
# This prevents downloading mods that require a newer Factorio version (fixes #468)
# and ensures backward compatibility (e.g., Factorio 2.0 can use 1.x mods) (fixes #517)
if [[ $(check_game_version "$mod_factorio_version" "$FACTORIO_VERSION") == 0 ]]; then
echo " Skipping mod version $mod_version because of factorio version mismatch" >&2
continue
fi
# If we found 'dependencies' element, we also check versions there
if [[ $(echo "$mod_release_info" | jq -e '.info_json | has("dependencies") and (.dependencies | length > 0)') == true ]]; then
while IFS= read -r dependency; do
# We only check for 'base' dependency
if [[ "$dependency" == base* ]] && [[ $(check_dependency_version "$dependency" "$FACTORIO_VERSION") == 0 ]]; then
echo " Skipping mod version $mod_version, unsatisfied base dependency: $dependency" >&2
continue 2
fi
done < <(echo "$mod_release_info" | jq -r '.info_json.dependencies[]')
fi
echo "$mod_release_info" | jq -j ".file_name, \";\", .download_url, \";\", .sha1"
break
done < <(echo "$mod_info_json" | jq -c ".releases|sort_by(.released_at)|reverse|.[]")
}
update_mod() update_mod()
{ {
MOD_NAME="$1" MOD_NAME="$1"
@ -30,7 +165,7 @@ update_mod()
print_step "Checking for update of mod $MOD_NAME for factorio $FACTORIO_VERSION ..." print_step "Checking for update of mod $MOD_NAME for factorio $FACTORIO_VERSION ..."
MOD_INFO_URL="$MOD_BASE_URL/api/mods/$MOD_NAME_ENCODED" MOD_INFO_URL="$MOD_BASE_URL/api/mods/$MOD_NAME_ENCODED/full"
MOD_INFO_JSON=$(curl --silent "$MOD_INFO_URL") MOD_INFO_JSON=$(curl --silent "$MOD_INFO_URL")
if ! echo "$MOD_INFO_JSON" | jq -e .name >/dev/null; then if ! echo "$MOD_INFO_JSON" | jq -e .name >/dev/null; then
@ -38,7 +173,12 @@ update_mod()
return 0 return 0
fi fi
MOD_INFO=$(echo "$MOD_INFO_JSON" | jq -j --arg version "$FACTORIO_VERSION" ".releases|reverse|map(select(.info_json.factorio_version as \$mod_version | \$version | startswith(\$mod_version)))[0]|.file_name, \";\", .download_url, \";\", .sha1") MOD_INFO=$(get_mod_info "$MOD_INFO_JSON")
if [[ "$MOD_INFO" == "" ]]; then
print_failure " Not compatible with version"
return 0
fi
MOD_FILENAME=$(echo "$MOD_INFO" | cut -f1 -d";") MOD_FILENAME=$(echo "$MOD_INFO" | cut -f1 -d";")
MOD_URL=$(echo "$MOD_INFO" | cut -f2 -d";") MOD_URL=$(echo "$MOD_INFO" | cut -f2 -d";")
@ -90,7 +230,7 @@ update_mod()
if [[ -f $MOD_DIR/mod-list.json ]]; then if [[ -f $MOD_DIR/mod-list.json ]]; then
jq -r ".mods|map(select(.enabled))|.[].name" "$MOD_DIR/mod-list.json" | while read -r mod; do jq -r ".mods|map(select(.enabled))|.[].name" "$MOD_DIR/mod-list.json" | while read -r mod; do
if [[ $mod != base ]]; then if [[ $mod != base ]]; then
update_mod "$mod" update_mod "$mod" || true
fi fi
done done
fi fi

View File

@ -91,10 +91,64 @@ if [[ $experimental_online_version != "$stable_online_version" ]]; then
fi fi
rm -f -- "$tmpfile" rm -f -- "$tmpfile"
readme_tags=$(jq --sort-keys 'keys[]' buildinfo.json | tac | (while read -r line # Generate README tags with logical sorting and de-duplication
do # First, collect all unique tags with their versions
tags="$tags\n* "$(jq --sort-keys ".$line.tags | sort | .[]" buildinfo.json | sed 's/"/`/g' | sed ':a; /$/N; s/\n/, /; ta') declare -A tag_versions
done && printf "%s\n\n" "$tags")) while IFS= read -r version; do
while IFS= read -r tag; do
# If this tag is already seen, compare versions to keep the latest
if [[ -n "${tag_versions[$tag]}" ]]; then
# Compare version strings - keep the higher one
if [[ "$version" > "${tag_versions[$tag]}" ]]; then
tag_versions[$tag]="$version"
fi
else
tag_versions[$tag]="$version"
fi
done < <(jq -r ".\"$version\".tags[]" buildinfo.json)
done < <(jq -r 'keys[]' buildinfo.json | sort -V -r)
# Build the tags list for README
readme_tags=""
# First add the current latest and stable tags
latest_version=$(jq -r 'to_entries | map(select(.value.tags | contains(["latest"]))) | .[0].key' buildinfo.json)
stable_version=$(jq -r 'to_entries | map(select(.value.tags | index("stable"))) | .[0].key' buildinfo.json)
if [[ -n "$latest_version" ]]; then
latest_tags=$(jq -r ".\"$latest_version\".tags | map(select(. == \"latest\" or . == \"$latest_version\")) | join(\", \")" buildinfo.json | sed 's/"/`/g')
readme_tags="${readme_tags}\n* \`${latest_tags}\`"
fi
if [[ -n "$stable_version" ]] && [[ "$stable_version" != "$latest_version" ]]; then
stable_tags=$(jq -r ".\"$stable_version\".tags | sort | join(\", \")" buildinfo.json | sed 's/"/`/g')
readme_tags="${readme_tags}\n* \`${stable_tags}\`"
fi
# Add major.minor tags (e.g., 2.0, 1.1) - only the latest version for each
declare -A major_minor_seen
while IFS= read -r version; do
if [[ "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
major_minor="$major.$minor"
# Skip if this is the latest or stable version (already added above)
if [[ "$version" == "$latest_version" ]] || [[ "$version" == "$stable_version" ]]; then
continue
fi
# Only add if we haven't seen this major.minor yet
if [[ -z "${major_minor_seen[$major_minor]}" ]]; then
major_minor_seen[$major_minor]=1
tags=$(jq -r ".\"$version\".tags | join(\", \")" buildinfo.json | sed 's/"/`/g')
if [[ -n "$tags" ]]; then
readme_tags="${readme_tags}\n* \`${tags}\`"
fi
fi
fi
done < <(jq -r 'keys[]' buildinfo.json | sort -V -r)
readme_tags="${readme_tags}\n"
perl -i -0777 -pe "s/<!-- start autogeneration tags -->.+<!-- end autogeneration tags -->/<!-- start autogeneration tags -->$readme_tags<!-- end autogeneration tags -->/s" README.md perl -i -0777 -pe "s/<!-- start autogeneration tags -->.+<!-- end autogeneration tags -->/<!-- start autogeneration tags -->$readme_tags<!-- end autogeneration tags -->/s" README.md