|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +### Key Components |
| 12 | + |
| 13 | +1. **Docker Image Build System** |
| 14 | + - `build.py` - Python script that builds Docker images from `buildinfo.json` |
| 15 | + - `docker/Dockerfile` - Main Dockerfile that creates the Factorio server image |
| 16 | + - `buildinfo.json` - Contains version info, SHA256 checksums, and tags for all supported versions |
| 17 | + - Supports multi-architecture builds (linux/amd64, linux/arm64) using Docker buildx |
| 18 | + |
| 19 | +2. **Automated Updates** |
| 20 | + - `update.sh` - Checks for new Factorio releases and updates `buildinfo.json` |
| 21 | + - Updates README.md with new version tags |
| 22 | + - Commits changes and tags releases automatically |
| 23 | + - Run by GitHub Actions to keep images up-to-date |
| 24 | + |
| 25 | +3. **Container Scripts** |
| 26 | + - `docker/files/docker-entrypoint.sh` - Main entrypoint that configures and starts the server |
| 27 | + - `docker/files/docker-update-mods.sh` - Updates mods on server start |
| 28 | + - `docker/files/docker-dlc.sh` - Manages DLC (Space Age) activation |
| 29 | + - `docker/files/scenario.sh` - Alternative entrypoint for launching scenarios |
| 30 | + - `docker/files/players-online.sh` - Checks if players are online (for watchtower integration) |
| 31 | + |
| 32 | +4. **RCON Client** |
| 33 | + - `docker/rcon/` - C source for RCON client, built during Docker image creation |
| 34 | + - Allows sending commands to the running server |
| 35 | + |
| 36 | +## Common Development Commands |
| 37 | + |
| 38 | +### Building Images |
| 39 | + |
| 40 | +```bash |
| 41 | +# Build a single architecture image locally |
| 42 | +python3 build.py |
| 43 | + |
| 44 | +# Build and push multi-architecture images |
| 45 | +python3 build.py --multiarch --push-tags |
| 46 | +``` |
| 47 | + |
| 48 | +### Running the Container |
| 49 | + |
| 50 | +```bash |
| 51 | +# Basic run command |
| 52 | +docker run -d \ |
| 53 | + -p 34197:34197/udp \ |
| 54 | + -p 27015:27015/tcp \ |
| 55 | + -v /opt/factorio:/factorio \ |
| 56 | + --name factorio \ |
| 57 | + factoriotools/factorio |
| 58 | + |
| 59 | +# Using docker-compose |
| 60 | +docker-compose up -d |
| 61 | +``` |
| 62 | + |
| 63 | +### Linting |
| 64 | + |
| 65 | +```bash |
| 66 | +# Lint Dockerfiles |
| 67 | +./lint.sh |
| 68 | +``` |
| 69 | + |
| 70 | +### Testing Updates |
| 71 | + |
| 72 | +```bash |
| 73 | +# Check for new Factorio versions and update buildinfo.json |
| 74 | +./update.sh |
| 75 | +``` |
| 76 | + |
| 77 | +## Key Configuration |
| 78 | + |
| 79 | +### Environment Variables |
| 80 | +- `LOAD_LATEST_SAVE` - Load the most recent save (default: true) |
| 81 | +- `GENERATE_NEW_SAVE` - Generate a new save if none exists (default: false) |
| 82 | +- `SAVE_NAME` - Name of the save file to load/create |
| 83 | +- `UPDATE_MODS_ON_START` - Update mods before starting (requires USERNAME/TOKEN) |
| 84 | +- `DLC_SPACE_AGE` - Enable/disable Space Age DLC (default: true) |
| 85 | +- `PORT` - UDP port for game server (default: 34197) |
| 86 | +- `RCON_PORT` - TCP port for RCON (default: 27015) |
| 87 | + |
| 88 | +### Volume Structure |
| 89 | +All data is stored in a single volume mounted at `/factorio`: |
| 90 | +``` |
| 91 | +/factorio/ |
| 92 | +├── config/ # Server configuration files |
| 93 | +├── mods/ # Game modifications |
| 94 | +├── saves/ # Save games |
| 95 | +├── scenarios/ # Scenario files |
| 96 | +└── script-output/ # Script output directory |
| 97 | +``` |
| 98 | + |
| 99 | +## Version Management |
| 100 | + |
| 101 | +The project maintains compatibility with multiple Factorio versions: |
| 102 | +- Latest experimental version gets the `latest` tag |
| 103 | +- Latest stable version gets the `stable` tag |
| 104 | +- Each version also gets specific tags (e.g., `2.0.55`, `2.0`, `2`) |
| 105 | +- Legacy versions back to 0.12 are supported |
| 106 | + |
| 107 | +Version updates are automated via GitHub Actions that run `update.sh` periodically. |
| 108 | + |
| 109 | +## Testing Changes |
| 110 | + |
| 111 | +1. Modify `buildinfo.json` to test specific versions |
| 112 | +2. Run `python3 build.py` to build locally |
| 113 | +3. Test the container with your local data volume |
| 114 | +4. For production changes, ensure `update.sh` handles version transitions correctly |
0 commit comments