···1+# compose-sync
2+3+A tool to automatically sync and deploy Docker Compose stacks from a git repository, with multi-host support.
4+5+## Overview
6+7+compose-sync pulls changes from a git repository containing Docker Compose files and only deploys stacks that:
8+1. Have changed since the last pull
9+2. Are assigned to the current host
10+11+## Repository Structure
12+13+Your git repository should have the following structure:
14+15+```
16+stacks/
17+ traefik/compose.yml
18+ uptime-kuma/compose.yml
19+ home-assistant/compose.yml
20+ ...
21+22+inventory.yml
23+```
24+25+The `inventory.yml` file at the root contains all hosts and their assigned stacks. For example:
26+27+```yaml
28+hosts:
29+ vps-1:
30+ - traefik
31+ - uptime-kuma
32+ nas-1:
33+ - home-assistant
34+ - nextcloud
35+```
36+37+This format is compatible with Ansible inventory structures and provides a centralized view of all host assignments.
38+39+## Installation
40+41+```bash
42+go install github.com/aottr/compose-sync@latest
43+```
44+45+#### Alternatively build from source
46+47+1. Clone this repository
48+2. Build the application:
49+ ```bash
50+ go build -o compose-sync
51+ ```
52+53+## Configuration
54+55+1. Copy `config.yml.example` to `config.yml`
56+2. Edit `config.yml` and set `repo_path` to the local path of your git repository
57+58+## Usage
59+60+### Basic Usage
61+62+```bash
63+./compose-sync
64+```
65+66+This will:
67+- Detect the current hostname
68+- Pull the latest changes from git
69+- Find changed stacks
70+- Deploy only changed stacks assigned to this host
71+72+### Dry Run
73+74+To see what would be deployed without actually deploying:
75+76+```bash
77+./compose-sync -dry-run
78+```
79+80+### Custom Config Path
81+82+```bash
83+./compose-sync -config /path/to/config.yml
84+```
85+86+## How It Works
87+88+1. **Host Detection**: The tool uses the system hostname to identify the current host
89+2. **Stack Assignment**: Reads `inventory.yml` to determine which stacks should be deployed on this host
90+3. **Change Detection**: Compares git commits before and after pulling to find changed stacks
91+4. **Selective Deployment**: Only deploys stacks that both changed AND are assigned to this host
92+93+## Requirements
94+95+- Go 1.21 or later
96+- Git
97+- Docker and Docker Compose
98+- A git repository with the structure described above
99+100+## License
101+102+MIT
103+
+4
config.yml.example
···0000
···1+# Configuration file for compose-sync
2+repo_url: "git@github.com:user/compose-repo.git" # Optional: URL for cloning (not used if repo_path already exists)
3+repo_path: "/path/to/local/repo" # Required: Local path to the git repository
4+