Skip to content

Conversation

@dumplingleon65-prog
Copy link

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.

…tup logic")

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.
@dumplingleon65-prog dumplingleon65-prog changed the title Refactor service startup logic ( git commit -m "Refactor service startup logic") Refactor service startup logic Nov 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant