|
| 1 | +# Torrust Tracker Demo Migration Plan - Digital Ocean to Hetzner |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This plan outlines the migration of the Torrust Tracker demo from Digital Ocean to Hetzner |
| 6 | +infrastructure. The migration prioritizes **ease of updates** over performance by maintaining |
| 7 | +Docker-based deployments, and follows a **complete local development and testing** approach |
| 8 | +before deploying to production. |
| 9 | + |
| 10 | +## Key Decisions |
| 11 | + |
| 12 | +- **Docker-first approach**: Continue using Docker for the tracker to simplify updates |
| 13 | + (just pull new images) |
| 14 | +- **Complete local testing**: Finish all development and testing locally before creating |
| 15 | + any Hetzner VMs |
| 16 | +- **MySQL by default**: Replace SQLite with MySQL for better production characteristics |
| 17 | +- **12-Factor App compliance**: Refactor the entire repository to follow modern deployment |
| 18 | + practices |
| 19 | + |
| 20 | +## Migration Phases |
| 21 | + |
| 22 | +### Phase 1: Database Migration to MySQL |
| 23 | + |
| 24 | +**Objective**: Replace SQLite with MySQL as the default database |
| 25 | + |
| 26 | +#### Tasks |
| 27 | + |
| 28 | +- [ ] Add MySQL service to `docker-compose.yaml` |
| 29 | +- [ ] Update tracker configuration (`tracker.toml`) to use MySQL connection |
| 30 | +- [ ] Create MySQL initialization scripts/schema |
| 31 | +- [ ] Update environment variable templates (`.env.production`) |
| 32 | +- [ ] Update documentation for MySQL setup |
| 33 | + |
| 34 | +#### Validation |
| 35 | + |
| 36 | +- [ ] Deploy locally using `make apply` |
| 37 | +- [ ] Verify MySQL service starts successfully |
| 38 | +- [ ] Make test announce request |
| 39 | +- [ ] Confirm download counter increases in MySQL `torrents` table |
| 40 | +- [ ] Test tracker restart with persistent MySQL data |
| 41 | + |
| 42 | +**Deliverable**: Working local deployment with MySQL backend |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +### Phase 2: 12-Factor App Refactoring |
| 47 | + |
| 48 | +**Objective**: Refactor repository to follow [12-Factor App methodology](https://12factor.net/) |
| 49 | + |
| 50 | +**Reference**: See detailed plan in `infrastructure/docs/refactoring/twelve-factor-refactor/` |
| 51 | + |
| 52 | +#### Key Changes |
| 53 | + |
| 54 | +- [ ] **Configuration via environment**: Move all config to environment variables |
| 55 | +- [ ] **Dependency isolation**: Explicit dependency declaration in Docker |
| 56 | +- [ ] **Stateless processes**: Ensure tracker processes are stateless |
| 57 | +- [ ] **Port binding**: Clean service port configuration |
| 58 | +- [ ] **Logs as streams**: Structured logging to stdout/stderr |
| 59 | +- [ ] **Environment parity**: Dev/staging/prod environment consistency |
| 60 | + |
| 61 | +#### Tasks |
| 62 | + |
| 63 | +- [ ] Implement configuration refactoring (see phase-1-implementation.md) |
| 64 | +- [ ] Update Docker configurations |
| 65 | +- [ ] Refactor environment variable management |
| 66 | +- [ ] Update deployment scripts |
| 67 | +- [ ] Update documentation |
| 68 | + |
| 69 | +**Deliverable**: 12-Factor compliant repository structure |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +### Phase 3: Complete Application Installation Automation |
| 74 | + |
| 75 | +**Objective**: Fully automate tracker deployment including SSL certificates |
| 76 | + |
| 77 | +#### Current State |
| 78 | + |
| 79 | +- ✅ VM provisioning via cloud-init |
| 80 | +- ✅ Basic app setup (copy files, `.env` config, `docker compose up`) |
| 81 | +- ❌ SSL certificate generation |
| 82 | +- ❌ Crontab setup for renewals |
| 83 | +- ❌ Production hardening steps |
| 84 | + |
| 85 | +#### Tasks |
| 86 | + |
| 87 | +- [ ] Automate SSL certificate generation with Certbot |
| 88 | +- [ ] Set up automatic certificate renewal crontabs |
| 89 | +- [ ] Implement production hardening automation |
| 90 | +- [ ] Create comprehensive deployment validation script |
| 91 | +- [ ] Handle edge cases and error recovery |
| 92 | + |
| 93 | +#### Implementation Notes |
| 94 | + |
| 95 | +- Integrate with existing cloud-init setup |
| 96 | +- If Certbot automation requires manual interaction, document as the only manual step |
| 97 | +- Follow production setup guide: https://torrust.com/blog/deploying-torrust-to-production |
| 98 | + |
| 99 | +**Deliverable**: One-command deployment to production-ready state |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +### Phase 4: Hetzner Infrastructure Implementation |
| 104 | + |
| 105 | +**Objective**: Add Hetzner Cloud provider support and validate complete deployment |
| 106 | + |
| 107 | +#### Tasks |
| 108 | + |
| 109 | +- [ ] Research and add Hetzner Cloud OpenTofu provider |
| 110 | +- [ ] Create Hetzner-specific Terraform configurations |
| 111 | +- [ ] Implement Hetzner cloud-init adaptations |
| 112 | +- [ ] Test complete deployment pipeline on Hetzner |
| 113 | +- [ ] Configure provider-level firewall (optional, complementing VM firewall) |
| 114 | +- [ ] Validate tracker accessibility via IP (HTTP) |
| 115 | + |
| 116 | +#### Provider Firewall Consideration |
| 117 | + |
| 118 | +- VM firewall via cloud-init: ✅ Required |
| 119 | +- Provider firewall: 🤔 Optional additional security layer |
| 120 | + |
| 121 | +#### Validation |
| 122 | + |
| 123 | +- [ ] Deploy test VM on Hetzner |
| 124 | +- [ ] Verify all services start correctly |
| 125 | +- [ ] Test tracker functionality (announce, scrape) |
| 126 | +- [ ] Confirm firewall rules work correctly |
| 127 | +- [ ] Performance and connectivity testing |
| 128 | + |
| 129 | +**Deliverable**: Working Hetzner deployment with IP access |
| 130 | + |
| 131 | +--- |
| 132 | + |
| 133 | +### Phase 5: Database Migration (Optional) |
| 134 | + |
| 135 | +**Objective**: Migrate existing tracker data from Digital Ocean SQLite to Hetzner MySQL |
| 136 | + |
| 137 | +#### Tasks |
| 138 | + |
| 139 | +- [ ] Export existing SQLite data from Digital Ocean instance |
| 140 | +- [ ] Create data transformation scripts (SQLite → MySQL) |
| 141 | +- [ ] Import data to new MySQL instance |
| 142 | +- [ ] Validate data integrity and completeness |
| 143 | +- [ ] Test tracker with migrated data |
| 144 | + |
| 145 | +**Note**: This step is optional and can be skipped for a fresh start |
| 146 | + |
| 147 | +--- |
| 148 | + |
| 149 | +### Phase 6: Testing and Validation |
| 150 | + |
| 151 | +**Objective**: Comprehensive testing of the new Hetzner deployment |
| 152 | + |
| 153 | +#### Testing Areas |
| 154 | + |
| 155 | +- [ ] **Functional Testing**: All tracker endpoints work correctly |
| 156 | +- [ ] **Performance Testing**: Announce/scrape response times |
| 157 | +- [ ] **Integration Testing**: Index ↔ Tracker communication |
| 158 | +- [ ] **Monitoring**: Grafana dashboards show correct metrics |
| 159 | +- [ ] **SSL Testing**: HTTPS certificate generation and renewal |
| 160 | +- [ ] **Backup Testing**: Database backup and restore procedures |
| 161 | + |
| 162 | +#### Test Scenarios |
| 163 | + |
| 164 | +- [ ] Fresh torrent announce and scrape |
| 165 | +- [ ] High-load announce testing |
| 166 | +- [ ] Tracker restart with data persistence |
| 167 | +- [ ] Certificate renewal simulation |
| 168 | +- [ ] Firewall rule validation |
| 169 | + |
| 170 | +**Deliverable**: Fully validated production deployment |
| 171 | + |
| 172 | +--- |
| 173 | + |
| 174 | +### Phase 7: Go Live |
| 175 | + |
| 176 | +**Objective**: Switch production traffic to Hetzner infrastructure |
| 177 | + |
| 178 | +#### Pre-Go-Live |
| 179 | + |
| 180 | +- [ ] Consider static IP allocation on Hetzner |
| 181 | +- [ ] Prepare DNS change procedures |
| 182 | +- [ ] Document rollback plan |
| 183 | + |
| 184 | +#### Go-Live Steps |
| 185 | + |
| 186 | +- [ ] Update DNS records to point to new Hetzner IP |
| 187 | +- [ ] Update Digital Ocean index configuration: |
| 188 | + - Change tracker resolution from Docker service name to public domain |
| 189 | + - Index will access tracker via public API instead of internal Docker network |
| 190 | +- [ ] Monitor traffic and error rates |
| 191 | +- [ ] Validate end-to-end functionality |
| 192 | + |
| 193 | +#### Post-Go-Live |
| 194 | + |
| 195 | +- [ ] Monitor system stability for 24-48 hours |
| 196 | +- [ ] Verify certificate auto-renewal works |
| 197 | +- [ ] Confirm backup procedures |
| 198 | +- [ ] Update documentation with new procedures |
| 199 | + |
| 200 | +**Deliverable**: Production traffic on Hetzner infrastructure |
| 201 | + |
| 202 | +--- |
| 203 | + |
| 204 | +## Future Considerations |
| 205 | + |
| 206 | +### Dynamic Configuration (Future Work) |
| 207 | + |
| 208 | +Currently hardcoded in cloud-init: |
| 209 | + |
| 210 | +- Number of tracker instances (e.g., 2 UDP trackers on ports 6868, 6969) |
| 211 | +- Firewall port configurations |
| 212 | +- Service scaling parameters |
| 213 | + |
| 214 | +**Future Enhancement**: Inject dynamic configuration via template variables |
| 215 | + |
| 216 | +### Repository Template Usage |
| 217 | + |
| 218 | +This repository serves as a template for users deploying their own trackers. Current |
| 219 | +hardcoded configurations can be manually adapted, but future work could make this more |
| 220 | +dynamic. |
| 221 | + |
| 222 | +## Risk Mitigation |
| 223 | + |
| 224 | +### Rollback Plan |
| 225 | + |
| 226 | +- Keep Digital Ocean instance running until Hetzner deployment is fully validated |
| 227 | +- Maintain DNS rollback capability |
| 228 | +- Document emergency procedures |
| 229 | + |
| 230 | +### Testing Strategy |
| 231 | + |
| 232 | +- All changes tested locally before Hetzner deployment |
| 233 | +- Staged rollout with validation at each phase |
| 234 | +- Comprehensive testing before DNS switch |
| 235 | + |
| 236 | +## Success Criteria |
| 237 | + |
| 238 | +- [ ] Tracker accessible via HTTPS on Hetzner |
| 239 | +- [ ] MySQL database working with persistent data |
| 240 | +- [ ] Grafana monitoring functional |
| 241 | +- [ ] SSL certificates auto-renewing |
| 242 | +- [ ] Index successfully communicating with tracker |
| 243 | +- [ ] Performance equivalent to or better than Digital Ocean |
| 244 | +- [ ] 12-Factor App compliance achieved |
| 245 | +- [ ] One-command deployment working |
0 commit comments