refactor: [#296] Phase 2: Create DockerComposeTopology Aggregate (P2.1, P2.2)#297
Merged
Conversation
…tworks P2.1: Service enum and DockerComposeTopology aggregate - Add Service enum with 5 variants (Tracker, MySQL, Prometheus, Grafana, Caddy) - Add DockerComposeTopology aggregate with required_networks() derivation - Add ServiceTopology struct linking services to their networks - All types are in domain layer (domain/topology/) P2.2: Network derivation in context and template update - Add NetworkDefinition type for template context serialization - Add required_networks field to DockerComposeContext - Add derive_required_networks() in builder that collects from all services - Replace conditional network blocks in docker-compose.yml.tera with required_networks loop for the global networks: section This establishes the single source of truth pattern - networks are derived from service configurations rather than duplicated in template conditionals. Links: #296, Epic #287
The security documentation about three-network segmentation now lives in src/domain/topology/network.rs where the network logic is defined. The template now has a simple reference to the Rust module.
…mpose.yml - Add description() method to Network enum with short purpose strings: - Database: "Database isolation: Tracker ↔ MySQL" - Metrics: "Metrics scraping: Tracker ↔ Prometheus" - Visualization: "Dashboard queries: Prometheus ↔ Grafana" - Proxy: "TLS termination: Caddy ↔ backend services" - Add description field to NetworkDefinition context type - Update docker-compose.yml.tera to render descriptions as YAML comments - Add 4 unit tests for network description functionality - Update draft issue with implementation details This provides sysadmins with self-documenting configuration files when they inspect deployed docker-compose.yml on production servers.
- Create draft issue for Phase 3: Port Topology Domain Model - Update EPIC to include Phase 3 as extension to original 5-PR strategy - Document that PORT-01 through PORT-11 rules from original plan were not included in initial scope but follow same pattern as networks - Phase 3 will move port exposure logic from templates to domain layer - Includes cross-service port conflict validation (different scope than TrackerConfig internal socket validation)
Member
Author
|
ACK d51857b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2: Create DockerComposeTopology Aggregate
Issue: #296
Epic: #287 (Docker Compose Topology Domain Model Refactoring)
Summary
This PR implements Phase 2 of the Docker Compose Topology refactoring, introducing the
DockerComposeTopologyaggregate and establishing the single source of truth pattern for network derivation.Changes
P2.1: Service Enum and Aggregate
Serviceenum (src/domain/topology/service.rs): Type-safe service identification with 5 variants:Tracker- Core BitTorrent trackerMySQL- Database servicePrometheus- Metrics collectionGrafana- VisualizationCaddy- TLS proxyDockerComposeTopologyaggregate (src/domain/topology/aggregate.rs):ServiceTopologyentriesrequired_networks()from service configurationsServiceTopologystruct: Links services to their network assignmentsP2.2: Network Derivation in Context and Template
NetworkDefinitiontype (context/network_definition.rs): Template-friendly network representationContext updates (
context/mod.rs,context/builder.rs):required_networksfield toDockerComposeContextderive_required_networks()method in builderTemplate update (
docker-compose.yml.tera):required_networksloop{%- if mysql %}\n database_network:\n driver: bridge\n{%- endif %}{%- for net in required_networks %}\n {{ net.name }}:\n driver: {{ net.driver }}\n{%- endfor %}Test Coverage
DockerComposeTopologyaggregateServiceenumNetworkDefinitionrequired_networksderivation in contextBehavioral Equivalence
The generated
docker-compose.ymloutput is functionally identical before and after this change. The only difference is implementation: networks are now derived from service configurations rather than duplicated in template conditionals.Files Changed
src/domain/topology/service.rssrc/domain/topology/aggregate.rssrc/domain/topology/mod.rssrc/domain/mod.rscontext/network_definition.rscontext/mod.rscontext/builder.rsdocker-compose.yml.teraProgress Update
After this PR: