Commit c520c76
committed
af3fc7b feat: [#252] implement dynamic image detection for vulnerability scanning (Jose Celano)
Pull request description:
Closes #252
## Summary
Implements dynamic Docker image detection for the Trivy vulnerability scanning workflow. Instead of a hardcoded image list, the workflow now builds the deployer CLI, creates a minimal environment, and extracts the image list from the `show` command JSON output — ensuring the scan matrix automatically updates whenever an image constant changes.
## Changes
### Domain Model
- Added `DockerImage` value object (`src/shared/docker_image.rs`) with `repository`, `tag`, and `full_reference()` method
- Added `docker_image()` static methods with constants to `TrackerConfig`, `MysqlServiceConfig`, `PrometheusConfig`, and `GrafanaConfig`
- Added `docker_image()` delegation in `DatabaseConfig` (returns `Some` for MySQL, `None` for SQLite)
### Infrastructure / Template
- Added `image: String` field to all four service context structs (`TrackerServiceContext`, `MysqlServiceContext`, `PrometheusServiceContext`, `GrafanaServiceContext`)
- Updated `templates/docker-compose/docker-compose.yml.tera` to use `{{ tracker.image }}`, `{{ mysql.image }}`, `{{ prometheus.image }}`, `{{ grafana.image }}` instead of hardcoded strings
### Show Command
- Added `DockerImagesInfo` DTO (extracted to its own module `show/info/docker_images.rs`)
- Added `docker_images: DockerImagesInfo` field to `EnvironmentInfo` (always populated, not optional)
- Updated show handler to populate `docker_images` from domain config constants
- Updated text view to render a **Docker Images** section
- Updated JSON output — `docker_images` is now present in all states
### GitHub Actions Workflow
- Added `extract-images` job: builds CLI → creates minimal env → runs `show ci-images` → pipes JSON to `jq` to produce image array
- Updated `scan-third-party-images` to use `${{ fromJson(needs.extract-images.outputs.images) }}` matrix (fully dynamic)
- Replaced 5 hardcoded third-party SARIF upload steps with a single bash loop in `upload-sarif-results`
- Added `src/**` to workflow trigger paths so image constant changes trigger re-scans
## Verification
All commands tested locally:
```bash
./target/release/torrust-tracker-deployer --working-dir /tmp/ci-workspace create environment --env-file /tmp/ci-images-env.json
./target/release/torrust-tracker-deployer --working-dir /tmp/ci-workspace show ci-images
# jq output: ["torrust/tracker:develop","mysql:8.4","prom/prometheus:v3.5.0","grafana/grafana:12.3.1","caddy:2.10"]
```
Pre-commit checks: ✅ 425/425 tests pass, all linters pass.
ACKs for top commit:
josecelano:
ACK af3fc7b
Tree-SHA512: 1eb54e311fe3b87673a60e0427561414cbc2e5f710e1df17c7052074a092e17d47e663441e0d3f817477bfaca0bce98cf4cd90317c8917b484cd6e755ec8042a
22 files changed
Lines changed: 559 additions & 60 deletions
File tree
- .github/workflows
- src
- application/command_handlers/show
- info
- domain
- grafana
- mysql
- prometheus
- tracker/config
- core/database
- infrastructure/templating/docker_compose/template/wrappers/docker_compose/context
- presentation/cli/views/commands/show
- view_data
- views
- templates/docker-compose
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
18 | | - | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
63 | | - | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| |||
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
96 | 187 | | |
97 | 188 | | |
| 189 | + | |
98 | 190 | | |
99 | 191 | | |
100 | 192 | | |
| |||
103 | 195 | | |
104 | 196 | | |
105 | 197 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
114 | 201 | | |
115 | 202 | | |
116 | 203 | | |
| |||
154 | 241 | | |
155 | 242 | | |
156 | 243 | | |
157 | | - | |
| 244 | + | |
158 | 245 | | |
159 | 246 | | |
160 | 247 | | |
| |||
168 | 255 | | |
169 | 256 | | |
170 | 257 | | |
171 | | - | |
172 | 258 | | |
173 | 259 | | |
174 | 260 | | |
| |||
192 | 278 | | |
193 | 279 | | |
194 | 280 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
204 | 287 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
210 | 301 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
218 | 306 | | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
| 307 | + | |
226 | 308 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
| 429 | + | |
429 | 430 | | |
430 | 431 | | |
431 | 432 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| |||
121 | 127 | | |
122 | 128 | | |
123 | 129 | | |
124 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
125 | 148 | | |
126 | 149 | | |
127 | 150 | | |
| |||
144 | 167 | | |
145 | 168 | | |
146 | 169 | | |
147 | | - | |
148 | 170 | | |
149 | 171 | | |
150 | 172 | | |
| |||
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
0 commit comments