77from pathlib import Path
88import yaml
99
10- from .base import (
10+ from .. core . base import (
1111 ContainerService ,
1212 DatabaseService ,
1313 MessageBrokerService ,
1414 Port ,
1515)
16- from .health_checks import (
16+ from .. health . checks import (
1717 HealthCheck ,
1818 HttpHealthCheck ,
1919 RedisHealthCheck ,
2020 PostgresHealthCheck ,
2121 DaprHealthCheck ,
2222)
23- from .config import ServiceConfig , EnvironmentConfig
23+ from .. core . config import ServiceConfig , EnvironmentConfig
2424
2525
2626class ServiceFactory :
@@ -30,30 +30,36 @@ class ServiceFactory:
3030 """
3131
3232 @staticmethod
33- def create_redis_service (config : EnvironmentConfig ) -> MessageBrokerService :
33+ def create_redis_service (config : EnvironmentConfig ) -> "RedisService" :
3434 """Create Redis service instance."""
35- service = MessageBrokerService (
35+ from ..implementations import RedisService
36+
37+ service = RedisService (
3638 name = "redis" ,
3739 image = "redis:7-bookworm" ,
38- container_name = "openai-agents-redis" ,
40+ ports = [ Port ( container = 6379 , host = 6379 )] ,
3941 )
4042
41- service .add_port (Port (6379 , 6379 ))
4243 service .set_health_check (RedisHealthCheck (interval = "5s" , timeout = "3s" ))
43- service .add_network ("openai- agents-network" )
44+ service .add_network ("agents-network" )
4445
4546 return service
4647
4748 @staticmethod
48- def create_postgres_service (config : EnvironmentConfig ) -> DatabaseService :
49+ def create_postgres_service (config : EnvironmentConfig ) -> "PostgresService" :
4950 """Create PostgreSQL service instance."""
50- service = DatabaseService (
51+ from ..implementations import PostgresService
52+
53+ service = PostgresService (
5154 name = "postgres" ,
5255 image = "postgres:16-bookworm" ,
53- container_name = "openai-agents-postgres" ,
56+ database = config .postgres_db ,
57+ username = config .postgres_user ,
58+ password = config .postgres_password ,
59+ ports = [Port (container = 5432 , host = 5432 )],
60+ init_scripts = "./postgres-init" ,
5461 )
5562
56- service .add_port (Port (5432 , 5432 ))
5763 service .set_health_check (
5864 PostgresHealthCheck (
5965 user = config .postgres_user ,
@@ -62,22 +68,7 @@ def create_postgres_service(config: EnvironmentConfig) -> DatabaseService:
6268 timeout = "3s" ,
6369 )
6470 )
65- service .add_network ("openai-agents-network" )
66-
67- # Environment variables
68- service .add_environment ("POSTGRES_USER" , config .postgres_user )
69- service .add_environment ("POSTGRES_PASSWORD" , config .postgres_password )
70- service .add_environment ("POSTGRES_DB" , config .postgres_db )
71-
72- # Volume for data persistence
73- service .add_volume ("postgres-data" , "/var/lib/postgresql/data" )
74-
75- # Initialization scripts
76- service .add_volume (
77- "./postgres-init:/docker-entrypoint-initdb.d" ,
78- "/docker-entrypoint-initdb.d" ,
79- readonly = True ,
80- )
71+ service .add_network ("agents-network" )
8172
8273 return service
8374
@@ -87,40 +78,37 @@ def create_dapr_sidecar_service(config: EnvironmentConfig) -> ContainerService:
8778 service = ContainerService (
8879 name = "dapr-sidecar" ,
8980 image = "daprio/daprd:1.16.0" ,
90- container_name = "openai-agents-dapr-sidecar" ,
9181 )
9282
9383 # Dapr ports
94- service .add_port (Port (3500 , 3500 )) # HTTP
95- service .add_port (Port (50001 , 50001 )) # gRPC
84+ service .add_port (Port (container = 3500 , host = 3500 )) # HTTP
85+ service .add_port (Port (container = 50001 , host = 50001 )) # gRPC
9686
9787 # Health check
9888 service .set_health_check (
9989 DaprHealthCheck (interval = "10s" , timeout = "5s" , retries = 10 )
10090 )
10191
102- service .add_network ("openai- agents-network" )
92+ service .add_network ("agents-network" )
10393
10494 # Dependencies
10595 service .add_dependency ("redis" )
10696 service .add_dependency ("postgres" )
107- service .add_dependency ("dapr-placement" )
10897
10998 # Command
11099 service ._command = [
111100 "./daprd" ,
112- "--app-id" , "openai-agents" ,
113- "--app-port" , "8000" ,
114- "--dapr-http-port" , str (config .dapr_http_port ),
115- "--dapr-grpc-port" , str (config .dapr_grpc_port ),
116- "--resources-path" , "/dapr/components" ,
117- "--config" , "/dapr/components/configuration.yaml" ,
101+ "-app-id" , "openai-agents" ,
102+ "-dapr-http-port" , str (config .dapr_http_port ),
103+ "-dapr-grpc-port" , str (config .dapr_grpc_port ),
104+ "-components-path" , "/components" ,
105+ "-log-level" , "info" ,
118106 ]
119107
120108 # Volume for Dapr components
121109 service .add_volume (
122- "./.devcontainer/dapr-components:/dapr/components " ,
123- "/dapr/ components" ,
110+ "./.devcontainer/dapr-components" ,
111+ "/components" ,
124112 readonly = True ,
125113 )
126114
@@ -132,17 +120,16 @@ def create_dapr_placement_service() -> ContainerService:
132120 service = ContainerService (
133121 name = "dapr-placement" ,
134122 image = "daprio/dapr:1.16.0" ,
135- container_name = "openai-agents-dapr-placement" ,
136123 )
137124
138- service .add_port (Port (50005 , 50005 ))
139- service .add_network ("openai- agents-network" )
125+ service .add_port (Port (container = 50006 , host = 50006 ))
126+ service .add_network ("agents-network" )
140127
141128 # Run only with actors profile
142129 service ._profiles = ["actors" ]
143130
144131 # Command for placement service
145- service ._command = ["./placement" ]
132+ service ._command = ["./placement" , "-port" , "50006" ]
146133
147134 return service
148135
0 commit comments