Refactor service startup logic #17
Open
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.
This PR addresses significant code duplication within run.py by refactoring the Docker container orchestration.
Previously, each service (ollama, web-ui, state-service, etc.) had its own dedicated setup_* function. These functions were nearly identical, all performing the same sequence of "check -> remove -> pull -> run". This update abstracts this shared logic into a single, reusable function.
Changes Implemented
Introduced setup_service(): A new, generic function that takes a ServiceConfig object and handles the complete setup lifecycle for any container (logging, removing old containers, pulling new images, and running the container).
Created get*_config() Factory Functions: Added new private "factory" functions (e.g., _get_ollama_config(), _get_policy_models_config()) that are responsible for defining the specific configuration (ports, volumes, environment) for each service.
Simplified start_containers(): This function has been refactored to be much cleaner. It now simply:
Gathers all ServiceConfig objects from the factory functions.
Iterates and passes each config to the setup_service() function.
Waits for the containers to become healthy as before.
Benefits of this Change
DRY (Don't Repeat Yourself): Eliminates a large amount of redundant code, making the script cleaner and more concise.
Maintainability: Adding or modifying a service is now much easier. You only need to add/edit a small factory function instead of duplicating 30+ lines of orchestration logic.
Readability: The start_containers function now clearly expresses its intent (looping through service configs and starting them) without being cluttered by implementation details.