···11+# compose-sync
22+33+A tool to automatically sync and deploy Docker Compose stacks from a git repository, with multi-host support.
44+55+## Overview
66+77+compose-sync pulls changes from a git repository containing Docker Compose files and only deploys stacks that:
88+1. Have changed since the last pull
99+2. Are assigned to the current host
1010+1111+## Repository Structure
1212+1313+Your git repository should have the following structure:
1414+1515+```
1616+stacks/
1717+ traefik/compose.yml
1818+ uptime-kuma/compose.yml
1919+ home-assistant/compose.yml
2020+ ...
2121+2222+inventory.yml
2323+```
2424+2525+The `inventory.yml` file at the root contains all hosts and their assigned stacks. For example:
2626+2727+```yaml
2828+hosts:
2929+ vps-1:
3030+ - traefik
3131+ - uptime-kuma
3232+ nas-1:
3333+ - home-assistant
3434+ - nextcloud
3535+```
3636+3737+This format is compatible with Ansible inventory structures and provides a centralized view of all host assignments.
3838+3939+## Installation
4040+4141+```bash
4242+go install github.com/aottr/compose-sync@latest
4343+```
4444+4545+#### Alternatively build from source
4646+4747+1. Clone this repository
4848+2. Build the application:
4949+ ```bash
5050+ go build -o compose-sync
5151+ ```
5252+5353+## Configuration
5454+5555+1. Copy `config.yml.example` to `config.yml`
5656+2. Edit `config.yml` and set `repo_path` to the local path of your git repository
5757+5858+## Usage
5959+6060+### Basic Usage
6161+6262+```bash
6363+./compose-sync
6464+```
6565+6666+This will:
6767+- Detect the current hostname
6868+- Pull the latest changes from git
6969+- Find changed stacks
7070+- Deploy only changed stacks assigned to this host
7171+7272+### Dry Run
7373+7474+To see what would be deployed without actually deploying:
7575+7676+```bash
7777+./compose-sync -dry-run
7878+```
7979+8080+### Custom Config Path
8181+8282+```bash
8383+./compose-sync -config /path/to/config.yml
8484+```
8585+8686+## How It Works
8787+8888+1. **Host Detection**: The tool uses the system hostname to identify the current host
8989+2. **Stack Assignment**: Reads `inventory.yml` to determine which stacks should be deployed on this host
9090+3. **Change Detection**: Compares git commits before and after pulling to find changed stacks
9191+4. **Selective Deployment**: Only deploys stacks that both changed AND are assigned to this host
9292+9393+## Requirements
9494+9595+- Go 1.21 or later
9696+- Git
9797+- Docker and Docker Compose
9898+- A git repository with the structure described above
9999+100100+## License
101101+102102+MIT
103103+
+4
config.yml.example
···11+# Configuration file for compose-sync
22+repo_url: "git@github.com:user/compose-repo.git" # Optional: URL for cloning (not used if repo_path already exists)
33+repo_path: "/path/to/local/repo" # Required: Local path to the git repository
44+