Commit f2c3cb0
committed
refactor: implement Builder Pattern for DockerComposeContext
- Introduce DockerComposeContextBuilder for flexible, scalable configuration
- Replace specialized constructors (new_sqlite, new_mysql) with unified builder() entry point
- Default to SQLite database configuration (zero-config common case)
- Explicit database override via with_mysql() method
- Consistent optional feature pattern: all use with_* methods
- Move Prometheus configuration to builder chain
- Update all test code and production code to use new builder API
BREAKING CHANGES:
- Removed: DockerComposeContext::new_sqlite(ports)
- Removed: DockerComposeContext::new_mysql(root_password, database, user, password, port, ports)
- Removed: context.with_prometheus(config) post-construction method
- New API: DockerComposeContext::builder(ports).build()
- MySQL: builder(ports).with_mysql(...).build()
- Prometheus: builder(ports).with_prometheus(config).build()
Rationale:
Previous constructor-based API was "chaotic" with:
- Two specialized constructors forcing early database choice
- One mutable method (with_prometheus) inconsistent with immutable constructors
- Poor scalability: future features (Grafana, Redis) would explode constructor count
- Confusing API: when to use constructors vs methods?
Builder pattern provides:
- Single entry point scales infinitely
- SQLite default handles common case with zero config
- Explicit database choice via with_mysql()
- All optional features via consistent with_* pattern
- Clean immutable result after build()
- Self-documenting API (builder chain reads like English)
- Future-proof: easy to add with_grafana(), with_redis(), etc.
This is a complete refactoring with no backward compatibility, justified by:
- Project in early development phase
- Not used in production by end users yet
- Clean migration without technical debt from deprecated APIs
- Better developer experience for future contributors1 parent 010e6fc commit f2c3cb0
File tree
5 files changed
+174
-142
lines changed- src
- application/steps/rendering
- infrastructure/templating/docker_compose/template
- renderer
- wrappers/docker_compose
5 files changed
+174
-142
lines changedLines changed: 20 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
156 | 156 | | |
157 | 157 | | |
158 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
159 | 168 | | |
160 | 169 | | |
161 | 170 | | |
| |||
176 | 185 | | |
177 | 186 | | |
178 | 187 | | |
179 | | - | |
| 188 | + | |
180 | 189 | | |
181 | 190 | | |
182 | 191 | | |
183 | 192 | | |
184 | 193 | | |
185 | | - | |
186 | 194 | | |
187 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
188 | 204 | | |
189 | 205 | | |
190 | 206 | | |
191 | 207 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | 208 | | |
199 | 209 | | |
200 | 210 | | |
| |||
Lines changed: 14 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
230 | 231 | | |
231 | 232 | | |
232 | 233 | | |
| |||
307 | 308 | | |
308 | 309 | | |
309 | 310 | | |
310 | | - | |
| 311 | + | |
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
| |||
353 | 354 | | |
354 | 355 | | |
355 | 356 | | |
356 | | - | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
357 | 360 | | |
358 | 361 | | |
359 | 362 | | |
| |||
421 | 424 | | |
422 | 425 | | |
423 | 426 | | |
424 | | - | |
| 427 | + | |
425 | 428 | | |
426 | 429 | | |
427 | 430 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
| 215 | + | |
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| |||
0 commit comments