Commit a540a12
committed
95d5e13 refactor: [#236] fix clippy too_many_arguments error with TrackerPorts struct (Jose Celano)
150f382 test: [#236] verify dynamic ports are rendered in docker-compose.yml (Jose Celano)
b902262 feat: [#236] make Docker Compose ports dynamic using Tera variables (Jose Celano)
5909c0b feat: [#236] extend DockerComposeContext with tracker port fields (Jose Celano)
Pull request description:
## Description
This PR implements dynamic tracker ports in Docker Compose templates, replacing hardcoded port values with Tera template variables extracted from the tracker configuration.
Closes #236
## Changes
### Core Implementation
- **Extended `DockerComposeContext`** with tracker port fields (udp_tracker_ports, http_tracker_ports, http_api_port)
- **Created `TrackerPorts` struct** to group port parameters and resolve clippy `too_many_arguments` warning
- **Implemented `extract_tracker_ports()`** helper to extract ports from `TrackerConfig` domain model
- **Updated `docker-compose.yml.tera`** template with Tera loops for dynamic port rendering
### Files Modified
- `src/infrastructure/templating/docker_compose/template/wrappers/docker_compose/context.rs` - Added TrackerPorts struct and port fields
- `src/application/steps/rendering/docker_compose_templates.rs` - Implemented port extraction logic
- `templates/docker-compose/docker-compose.yml.tera` - Replaced hardcoded ports with dynamic Tera variables
- Updated 27+ test call sites across context.rs, template.rs, docker_compose.rs, project_generator.rs
## Testing
### Automated Tests ✅
- **1473 unit tests** pass (11.95s)
- **8 E2E integration tests** pass
- **371 doc tests** pass (22.20s)
- All linters pass (markdown, YAML, TOML, clippy, rustfmt, shellcheck, cspell)
- Pre-commit validation: 6/6 steps pass (4m 58s)
### Manual E2E Test ✅
Successfully completed full deployment workflow with custom port configuration.
**Test Configuration:**
- 3 UDP Tracker Ports: 8080, 8081, 8082 (instead of default 6868, 6969)
- 2 HTTP Tracker Ports: 9090, 9091 (instead of default 7070)
- 1 HTTP API Port: 3030 (instead of default 1212)
**Test Results:**
1. ✅ Environment created successfully
2. ✅ Infrastructure provisioned with LXD
3. ✅ Instance configured with Ansible
4. ✅ docker-compose.yml generated with correct dynamic ports:
```yaml
ports:
# UDP Tracker Ports (dynamically configured)
- 8080:8080/udp
- 8081:8081/udp
- 8082:8082/udp
# HTTP Tracker Ports (dynamically configured)
- 9090:9090
- 9091:9091
# HTTP API Port (dynamically configured)
- 3030:3030
```
5. ✅ Tracker started successfully
6. ✅ Container verified running with correct port mappings:
```
0.0.0.0:8080-8082->8080-8082/udp
0.0.0.0:9090-9091->9090-9091/tcp
0.0.0.0:3030->3030/tcp
```
7. ✅ Services verified accessible from outside VM (IP: 10.140.190.152):
- HTTP API: `curl http://10.140.190.152:3030/api/health_check` → `{"status":"Ok"}`
- HTTP Tracker 1: `curl http://10.140.190.152:9090/announce` → Responding
- HTTP Tracker 2: `curl http://10.140.190.152:9091/announce` → Responding
8. ✅ Environment destroyed cleanly
**Key Achievements:**
- ✅ Multiple UDP trackers (3 ports) working simultaneously
- ✅ Multiple HTTP trackers (2 ports) working simultaneously
- ✅ Custom API port responding correctly
- ✅ All services accessible on configured custom ports
## Implementation Details
**Before (Hardcoded):**
```yaml
ports:
- "6868:6868/udp"
- "6969:6969/udp"
- "7070:7070"
- "1212:1212"
```
**After (Dynamic):**
```yaml
ports:
{% for port in udp_tracker_ports %}
- "{{ port }}:{{ port }}/udp"
{% endfor %}
{% for port in http_tracker_ports %}
- "{{ port }}:{{ port }}"
{% endfor %}
- "{{ http_api_port }}:{{ http_api_port }}"
```
## Architecture
The implementation follows the existing pattern established by `AnsibleVariablesContext`:
1. Port extraction in `RenderDockerComposeTemplatesStep`
2. Domain model (`TrackerConfig`) as source of truth
3. Infrastructure layer handles serialization
4. Tera template rendering with dynamic loops
## Commits
- docs: [#236] add issue specification for dynamic tracker ports
- feat: [#236] extend DockerComposeContext with tracker port fields
- feat: [#236] make Docker Compose ports dynamic using Tera variables
- test: [#236] verify dynamic ports are rendered in docker-compose.yml
- refactor: [#236] fix clippy too_many_arguments error with TrackerPorts struct
## Checklist
- [x] Code follows DDD layer placement guidelines
- [x] All automated tests pass
- [x] Pre-commit validation passes
- [x] Conventional commit format used
- [x] Issue number referenced in commits
- [x] Manual E2E test completed
- [x] Feature verified working in real deployment
ACKs for top commit:
josecelano:
ACK 95d5e13
Tree-SHA512: bf83696b8be104f2929b82245028c6bc12a0ba4b00f2bda21898bb1571a8dcf7ce088bcdc1d47eccfa2e066c6df0f2266b72640a20ef2a6b864d4107f3c85bed
File tree
7 files changed
+219
-20
lines changed- src
- application/steps/rendering
- infrastructure/templating/docker_compose/template
- renderer
- wrappers/docker_compose
- templates/docker-compose
7 files changed
+219
-20
lines changedLines changed: 61 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| |||
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
73 | 99 | | |
74 | 100 | | |
75 | 101 | | |
| |||
113 | 139 | | |
114 | 140 | | |
115 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
116 | 153 | | |
117 | 154 | | |
118 | 155 | | |
119 | 156 | | |
120 | 157 | | |
121 | | - | |
| 158 | + | |
122 | 159 | | |
123 | 160 | | |
124 | 161 | | |
| |||
145 | 182 | | |
146 | 183 | | |
147 | 184 | | |
| 185 | + | |
148 | 186 | | |
149 | 187 | | |
150 | 188 | | |
| |||
248 | 286 | | |
249 | 287 | | |
250 | 288 | | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
251 | 309 | | |
252 | 310 | | |
Lines changed: 15 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
192 | 194 | | |
193 | 195 | | |
194 | 196 | | |
| |||
212 | 214 | | |
213 | 215 | | |
214 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
215 | 222 | | |
216 | 223 | | |
217 | 224 | | |
218 | 225 | | |
219 | 226 | | |
220 | 227 | | |
| 228 | + | |
221 | 229 | | |
222 | 230 | | |
223 | 231 | | |
| |||
294 | 302 | | |
295 | 303 | | |
296 | 304 | | |
297 | | - | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
298 | 311 | | |
299 | 312 | | |
300 | 313 | | |
| |||
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| 188 | + | |
188 | 189 | | |
189 | 190 | | |
190 | 191 | | |
| |||
205 | 206 | | |
206 | 207 | | |
207 | 208 | | |
208 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
209 | 216 | | |
210 | 217 | | |
211 | 218 | | |
| |||
0 commit comments