|
1 | | -This repository contains all the configuration needed to run the live Torrust Tracker demo. |
2 | | - |
3 | | -The main goal is to provide a simple and easy-to-use setup for the Torrust Tracker, which can be deployed on a single server. |
4 | | - |
5 | | -The current major initiative is to migrate the tracker to a new infrastructure on Hetzner. This involves: |
6 | | -- Running the tracker binary directly on the host for performance. |
7 | | -- Using Docker for supporting services like Nginx, Prometheus, Grafana and MySQL. |
8 | | -- Migrating the database from SQLite to MySQL. |
9 | | - |
10 | | -When providing assistance, please act as an experienced open-source developer and system administrator. |
11 | | - |
12 | | -Follow these conventions: |
13 | | -- Use Conventional Commits for commit messages. Include the issue number in this format `#1` in the commit message if applicable, e.g., `feat: [#1] add new feature`. |
14 | | - - The issue number should be the branch prefix, e.g., `feat: [#1] add new feature` for branch `1-add-new-feature`. |
15 | | -- We use the proposed GitHub branch naming convention: |
16 | | - - Starts with a number indicating the issue number. |
17 | | - - Followed by a hyphen and a short description of the feature or fix. |
18 | | - - Uses hyphens to separate words, e.g., `1-add-new-feature`. |
19 | | -- Ensure that shell scripts are POSIX-compliant. |
20 | | -- Provide clear and concise documentation for any new features or changes. |
| 1 | +# Torrust Tracker Demo - Contributor Guide |
| 2 | + |
| 3 | +## 🎯 Project Overview |
| 4 | + |
| 5 | +**Torrust Tracker Demo** is the complete production deployment configuration for running a live [Torrust Tracker](https://github.com/torrust/torrust-tracker) instance. This repository provides: |
| 6 | + |
| 7 | +- **Production deployment** configurations for Hetzner cloud infrastructure |
| 8 | +- **Local testing environment** using KVM/libvirt virtualization |
| 9 | +- **Infrastructure as Code** approach using OpenTofu/Terraform and cloud-init |
| 10 | +- **Monitoring setup** with Grafana dashboards and Prometheus metrics |
| 11 | +- **Automated deployment** scripts and Docker Compose configurations |
| 12 | + |
| 13 | +### Current Major Initiative |
| 14 | + |
| 15 | +We are migrating the tracker to a new infrastructure on Hetzner, involving: |
| 16 | + |
| 17 | +- Running the tracker binary directly on the host for performance |
| 18 | +- Using Docker for supporting services (Nginx, Prometheus, Grafana, MySQL) |
| 19 | +- Migrating the database from SQLite to MySQL |
| 20 | +- Implementing Infrastructure as Code for reproducible deployments |
| 21 | + |
| 22 | +## 📁 Repository Structure |
| 23 | + |
| 24 | +```text |
| 25 | +torrust-tracker-demo/ |
| 26 | +├── .github/ |
| 27 | +│ ├── workflows/ # GitHub Actions CI/CD pipelines |
| 28 | +│ └── copilot-instructions.md # This contributor guide |
| 29 | +├── docs/ |
| 30 | +│ ├── infrastructure/ # Local testing documentation |
| 31 | +│ │ ├── quick-start.md # Fast setup guide |
| 32 | +│ │ ├── local-testing-setup.md # Detailed setup |
| 33 | +│ │ └── libvirt-setup.md # Troubleshooting guide |
| 34 | +│ ├── setup.md # Production deployment docs |
| 35 | +│ ├── deployment.md # Deployment procedures |
| 36 | +│ ├── firewall.md # Security configuration |
| 37 | +│ └── *.md # Additional operational docs |
| 38 | +├── infrastructure/ # Infrastructure as Code |
| 39 | +│ ├── terraform/ # OpenTofu/Terraform configurations |
| 40 | +│ │ ├── main.tf # VM and infrastructure definition |
| 41 | +│ │ └── local.tfvars # Local configuration (git-ignored) |
| 42 | +│ ├── cloud-init/ # VM provisioning templates |
| 43 | +│ │ ├── user-data.yaml.tpl # Main system configuration |
| 44 | +│ │ ├── user-data-minimal.yaml.tpl # Debug configuration |
| 45 | +│ │ ├── meta-data.yaml # VM metadata |
| 46 | +│ │ └── network-config.yaml # Network setup |
| 47 | +│ └── scripts/ # Infrastructure automation scripts |
| 48 | +├── share/ |
| 49 | +│ ├── bin/ # Deployment and utility scripts |
| 50 | +│ └── container/default/config/ # Docker service configurations |
| 51 | +├── tests/infrastructure/ # Infrastructure validation tests |
| 52 | +├── compose.yaml # Docker Compose for services |
| 53 | +├── Makefile # Main automation interface |
| 54 | +└── *.md # Project documentation |
| 55 | +``` |
| 56 | + |
| 57 | +### Key Components |
| 58 | + |
| 59 | +#### 🏗️ Infrastructure (`infrastructure/`) |
| 60 | + |
| 61 | +- **OpenTofu/Terraform**: Declarative infrastructure configuration |
| 62 | +- **Cloud-init**: Automated VM provisioning and setup |
| 63 | +- **Scripts**: Automation helpers for libvirt, monitoring, etc. |
| 64 | + |
| 65 | +#### 🐳 Docker Services (`compose.yaml`, `share/container/`) |
| 66 | + |
| 67 | +- **Nginx**: Reverse proxy and SSL termination |
| 68 | +- **Grafana**: Metrics visualization and dashboards |
| 69 | +- **Prometheus**: Metrics collection and storage |
| 70 | +- **Certbot**: Automated SSL certificate management |
| 71 | + |
| 72 | +#### 🧪 Testing (`tests/infrastructure/`) |
| 73 | + |
| 74 | +- **Validation scripts**: Ensure infrastructure works correctly |
| 75 | +- **Integration tests**: End-to-end deployment verification |
| 76 | +- **CI/CD pipelines**: Automated testing in GitHub Actions |
| 77 | + |
| 78 | +#### 📚 Documentation (`docs/`) |
| 79 | + |
| 80 | +- **Production**: Setup, deployment, and operational guides |
| 81 | +- **Local testing**: Development and testing instructions |
| 82 | +- **Troubleshooting**: Common issues and solutions |
| 83 | + |
| 84 | +## 🛠️ Development Workflow |
| 85 | + |
| 86 | +### Quick Start for Contributors |
| 87 | + |
| 88 | +```bash |
| 89 | +# 1. Clone and setup |
| 90 | +git clone https://github.com/torrust/torrust-tracker-demo.git |
| 91 | +cd torrust-tracker-demo |
| 92 | + |
| 93 | +# 2. Install dependencies (Ubuntu/Debian) |
| 94 | +make install-deps |
| 95 | + |
| 96 | +# 3. Setup SSH key for VMs |
| 97 | +make setup-ssh-key |
| 98 | + |
| 99 | +# 4. Test infrastructure locally |
| 100 | +make apply # Deploy test VM |
| 101 | +make ssh # Connect to VM |
| 102 | +make destroy # Cleanup |
| 103 | + |
| 104 | +# 5. Run tests |
| 105 | +make test # Full infrastructure test |
| 106 | +make test-syntax # Syntax validation only |
| 107 | +``` |
| 108 | + |
| 109 | +### Main Commands |
| 110 | + |
| 111 | +| Command | Purpose | |
| 112 | +| ------------------------- | --------------------------------- | |
| 113 | +| `make help` | Show all available commands | |
| 114 | +| `make install-deps` | Install OpenTofu, libvirt, KVM | |
| 115 | +| `make test` | Run complete infrastructure tests | |
| 116 | +| `make apply` | Deploy VM with full configuration | |
| 117 | +| `make apply-minimal` | Deploy VM with minimal config | |
| 118 | +| `make ssh` | Connect to deployed VM | |
| 119 | +| `make destroy` | Remove deployed VM | |
| 120 | +| `make monitor-cloud-init` | Watch VM provisioning progress | |
| 121 | + |
| 122 | +## 📋 Conventions and Standards |
| 123 | + |
| 124 | +### Git Workflow |
| 125 | + |
| 126 | +#### Branch Naming |
| 127 | + |
| 128 | +- **Format**: `{issue-number}-{short-description}` |
| 129 | +- **Examples**: `42-add-mysql-support`, `15-fix-ssl-renewal` |
| 130 | +- Always start with the GitHub issue number |
| 131 | + |
| 132 | +#### Commit Messages |
| 133 | + |
| 134 | +- **Format**: Conventional Commits with issue references |
| 135 | +- **Structure**: `{type}: [#{issue}] {description}` |
| 136 | +- **Examples**: |
| 137 | + ``` |
| 138 | + feat: [#42] add MySQL database support |
| 139 | + fix: [#15] resolve SSL certificate renewal issue |
| 140 | + docs: [#8] update deployment guide |
| 141 | + ci: [#23] add infrastructure validation tests |
| 142 | + ``` |
| 143 | + |
| 144 | +#### Commit Types |
| 145 | + |
| 146 | +- `feat`: New features |
| 147 | +- `fix`: Bug fixes |
| 148 | +- `docs`: Documentation changes |
| 149 | +- `ci`: CI/CD pipeline changes |
| 150 | +- `refactor`: Code refactoring |
| 151 | +- `test`: Test additions/changes |
| 152 | +- `chore`: Maintenance tasks |
| 153 | + |
| 154 | +### Code Quality Standards |
| 155 | + |
| 156 | +#### Shell Scripts |
| 157 | + |
| 158 | +- **POSIX Compliance**: All shell scripts must be POSIX-compliant |
| 159 | +- **Linting**: Use [ShellCheck](https://github.com/koalaman/shellcheck) |
| 160 | +- **Error Handling**: Use `set -euo pipefail` for strict error handling |
| 161 | +- **Documentation**: Include help functions and clear comments |
| 162 | + |
| 163 | +#### YAML Files |
| 164 | + |
| 165 | +- **Linting**: Use [yamllint](https://yamllint.readthedocs.io/en/stable/) |
| 166 | +- **Configuration**: Follow `.yamllint-ci.yml` rules |
| 167 | +- **Formatting**: 2-space indentation, 120-character line limit |
| 168 | +- **Comments**: Use `# ` (space after hash) for comments |
| 169 | + |
| 170 | +#### Markdown Documentation |
| 171 | + |
| 172 | +- **Linting**: Follow [markdownlint](https://github.com/DavidAnson/markdownlint) conventions |
| 173 | +- **Structure**: Use consistent heading hierarchy |
| 174 | +- **Links**: Prefer relative links for internal documentation |
| 175 | +- **Code blocks**: Always specify language for syntax highlighting |
| 176 | + |
| 177 | +#### Infrastructure as Code |
| 178 | + |
| 179 | +- **Validation**: All Terraform/OpenTofu must pass `tofu validate` |
| 180 | +- **Planning**: Test with `tofu plan` before applying |
| 181 | +- **Variables**: Use `local.tfvars` for sensitive/local config (git-ignored) |
| 182 | +- **Templates**: Use `.tpl` extension for templated files |
| 183 | + |
| 184 | +### Testing Requirements |
| 185 | + |
| 186 | +#### Infrastructure Tests |
| 187 | + |
| 188 | +- **Syntax validation**: All configurations must pass linting |
| 189 | +- **Local deployment**: Must successfully deploy and provision VMs |
| 190 | +- **Service validation**: All services must start and be accessible |
| 191 | +- **Network testing**: Ports and firewall rules must be correct |
| 192 | + |
| 193 | +#### CI/CD Requirements |
| 194 | + |
| 195 | +- **GitHub Actions**: All PRs must pass CI validation |
| 196 | +- **No secrets**: Never commit SSH keys, passwords, or tokens |
| 197 | +- **Documentation**: Update docs for any infrastructure changes |
| 198 | + |
| 199 | +### Security Guidelines |
| 200 | + |
| 201 | +#### Secrets Management |
| 202 | + |
| 203 | +- **SSH Keys**: Use template variables, store in `local.tfvars` |
| 204 | +- **Git Ignore**: All sensitive files must be in `.gitignore` |
| 205 | +- **Environment Variables**: Use environment variables for CI/CD secrets |
| 206 | +- **Review**: All security-related changes require review |
| 207 | + |
| 208 | +#### Infrastructure Security |
| 209 | + |
| 210 | +- **UFW Firewall**: Only open required ports |
| 211 | +- **SSH Access**: Key-based authentication only |
| 212 | +- **Updates**: Enable automatic security updates |
| 213 | +- **Monitoring**: Log security events and access |
| 214 | + |
| 215 | +## 🚀 Getting Started |
| 216 | + |
| 217 | +### For New Contributors |
| 218 | + |
| 219 | +1. **Read the documentation**: |
| 220 | + |
| 221 | + - [Quick Start Guide](../docs/infrastructure/quick-start.md) |
| 222 | + - [Complete Setup Guide](../docs/infrastructure/local-testing-setup.md) |
| 223 | + |
| 224 | +2. **Set up your environment**: |
| 225 | + |
| 226 | + ```bash |
| 227 | + make install-deps # Install dependencies |
| 228 | + make setup-ssh-key # Configure SSH access |
| 229 | + make test-prereq # Verify setup |
| 230 | + ``` |
| 231 | + |
| 232 | +3. **Test a simple change**: |
| 233 | + |
| 234 | + ```bash |
| 235 | + make apply # Deploy test VM |
| 236 | + make ssh # Verify access |
| 237 | + make destroy # Clean up |
| 238 | + ``` |
| 239 | + |
| 240 | +4. **Review existing issues**: Check [GitHub Issues](https://github.com/torrust/torrust-tracker-demo/issues) for good first contributions |
| 241 | + |
| 242 | +### For Infrastructure Changes |
| 243 | + |
| 244 | +1. **Local testing first**: Always test infrastructure changes locally |
| 245 | +2. **Validate syntax**: Run `make test-syntax` before committing |
| 246 | +3. **Document changes**: Update relevant documentation |
| 247 | +4. **Test end-to-end**: Ensure the full deployment pipeline works |
| 248 | + |
| 249 | +### For AI Assistants |
| 250 | + |
| 251 | +When providing assistance: |
| 252 | + |
| 253 | +- Act as an experienced open-source developer and system administrator |
| 254 | +- Follow all conventions listed above |
| 255 | +- Prioritize security and best practices |
| 256 | +- Test infrastructure changes locally before suggesting them |
| 257 | +- Provide clear explanations and documentation |
| 258 | +- Consider the migration to Hetzner infrastructure in suggestions |
| 259 | + |
| 260 | +## 📖 Additional Resources |
| 261 | + |
| 262 | +- **Torrust Tracker**: <https://github.com/torrust/torrust-tracker> |
| 263 | +- **OpenTofu Documentation**: <https://opentofu.org/docs/> |
| 264 | +- **Cloud-init Documentation**: <https://cloud-init.io/> |
| 265 | +- **libvirt Documentation**: <https://libvirt.org/> |
| 266 | +- **Repomix Tool**: <https://repomix.com/> (for generating project summaries) |
0 commit comments