Skip to content

Commit a7f74f7

Browse files
author
DeanLuus22021994
committed
refactor(infrastructure): complete implementation audit and fixes
- Add missing methods to ContainerService base class (add_port, set_health_check, add_environment, add_volume) - Create concrete implementations for RedisService and PostgresService - Fix ServiceFactory to use correct imports and implementations - Update all module imports to use new directory structure - Add health_check, command, and profiles instance variables - Ensure compose config includes all necessary fields - Remove app-dev profile restriction for DevContainer compatibility HIGH PRIORITY openai#3 & openai#4 progress: - Verified all documented classes exist and work - Fixed docker-compose profile configuration - All infrastructure Python files now properly implemented
1 parent 816fa06 commit a7f74f7

File tree

8 files changed

+160
-54
lines changed

8 files changed

+160
-54
lines changed

.devcontainer/infrastructure/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
from typing import Optional
1010
import yaml
1111

12-
from .config import EnvironmentConfig, DockerComposeConfig
13-
from .factories import ServiceFactory, DaprComponentFactory
14-
from .dockerfile_builder import DevelopmentDockerfileBuilder, ProductionDockerfileBuilder
12+
from .core.config import EnvironmentConfig, DockerComposeConfig
13+
from .factories.service import ServiceFactory, DaprComponentFactory
14+
from .builders.dockerfile import DevelopmentDockerfileBuilder, ProductionDockerfileBuilder
1515

1616

1717
class InfrastructureCLI:

.devcontainer/infrastructure/core/base.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def __init__(
5454
self._volumes = volumes or []
5555
self._networks: List[str] = []
5656
self._depends_on: List[str] = []
57+
self._health_check: Optional[Any] = None
58+
self._command: Optional[List[str]] = None
59+
self._profiles: List[str] = []
5760

5861
@property
5962
def name(self) -> str:
@@ -75,6 +78,27 @@ def add_dependency(self, service: str) -> "ContainerService":
7578
self._depends_on.append(service)
7679
return self
7780

81+
def add_port(self, port: Port) -> "ContainerService":
82+
"""Add port to service (fluent interface)."""
83+
self._ports.append(port)
84+
return self
85+
86+
def set_health_check(self, health_check: Any) -> "ContainerService":
87+
"""Set health check for service."""
88+
self._health_check = health_check
89+
return self
90+
91+
def add_environment(self, key: str, value: str) -> "ContainerService":
92+
"""Add environment variable."""
93+
self._environment[key] = value
94+
return self
95+
96+
def add_volume(self, host_path: str, container_path: str, readonly: bool = False) -> "ContainerService":
97+
"""Add volume mount."""
98+
mode = ":ro" if readonly else ""
99+
self._volumes.append(f"{host_path}:{container_path}{mode}")
100+
return self
101+
78102
@abstractmethod
79103
def get_health_check(self) -> Optional[Dict[str, Any]]:
80104
"""Get service health check configuration.
@@ -121,6 +145,14 @@ def to_compose_config(self) -> Dict[str, Any]:
121145
health_check = self.get_health_check()
122146
if health_check:
123147
config["healthcheck"] = health_check
148+
elif self._health_check:
149+
config["healthcheck"] = self._health_check.to_compose_config()
150+
151+
if self._command:
152+
config["command"] = self._command
153+
154+
if self._profiles:
155+
config["profiles"] = self._profiles
124156

125157
return config
126158

.devcontainer/infrastructure/factories/service.py

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
from pathlib import Path
88
import 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

2626
class 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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Concrete implementations of container services.
2+
3+
Provides specific implementations for Redis, PostgreSQL, and other services.
4+
"""
5+
6+
from .redis import RedisService
7+
from .postgres import PostgresService
8+
9+
__all__ = ["RedisService", "PostgresService"]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""PostgreSQL service implementation."""
2+
3+
from typing import Dict, Any, Optional, List
4+
from ..core.base import DatabaseService, Port
5+
6+
7+
class PostgresService(DatabaseService):
8+
"""PostgreSQL database service."""
9+
10+
def get_health_check(self) -> Optional[Dict[str, Any]]:
11+
"""Get PostgreSQL health check configuration."""
12+
# Health check is set via set_health_check() in factory
13+
return None
14+
15+
def get_default_environment(self) -> Dict[str, str]:
16+
"""Get default PostgreSQL environment variables."""
17+
return {
18+
"POSTGRES_USER": self._username,
19+
"POSTGRES_PASSWORD": self._password,
20+
"POSTGRES_DB": self._database,
21+
}
22+
23+
def _build_connection_string(self) -> str:
24+
"""Build PostgreSQL connection string."""
25+
return (
26+
f"host=postgres user={self._username} "
27+
f"password={self._password} "
28+
f"dbname={self._database} port=5432"
29+
)
30+
31+
def _get_init_path(self) -> str:
32+
"""Get initialization scripts path in container."""
33+
return "/docker-entrypoint-initdb.d"
34+
35+
def _get_data_path(self) -> str:
36+
"""Get data persistence path in container."""
37+
return "/var/lib/postgresql/data"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Redis service implementation."""
2+
3+
from typing import Dict, Any, Optional, List
4+
from ..core.base import MessageBrokerService, Port
5+
6+
7+
class RedisService(MessageBrokerService):
8+
"""Redis message broker and state store service."""
9+
10+
def __init__(
11+
self,
12+
name: str = "redis",
13+
image: str = "redis:7-bookworm",
14+
ports: Optional[List[Port]] = None,
15+
persistence: bool = True,
16+
):
17+
"""Initialize Redis service.
18+
19+
Args:
20+
name: Service name
21+
image: Docker image
22+
ports: Port mappings
23+
persistence: Enable data persistence
24+
"""
25+
super().__init__(name, image, ports, persistence)
26+
27+
def get_health_check(self) -> Optional[Dict[str, Any]]:
28+
"""Get Redis health check configuration."""
29+
# Health check is set via set_health_check() in factory
30+
return None
31+
32+
def get_default_environment(self) -> Dict[str, str]:
33+
"""Get default Redis environment variables."""
34+
return {}
35+
36+
def get_persistence_config(self) -> Optional[Dict[str, Any]]:
37+
"""Get Redis persistence configuration."""
38+
if not self._persistence:
39+
return None
40+
41+
return {
42+
"volumes": [f"{self._name}-data:/data"],
43+
}

.devcontainer/infrastructure/testing/fixtures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import tempfile
1010
import shutil
1111

12-
from .config import EnvironmentConfig, ServiceConfig, DockerComposeConfig
13-
from .factories import ServiceFactory, DaprComponentFactory
14-
from .health_checks import RedisHealthCheck, PostgresHealthCheck
15-
from .dockerfile_builder import DevelopmentDockerfileBuilder, ProductionDockerfileBuilder
12+
from ..core.config import EnvironmentConfig, ServiceConfig, DockerComposeConfig
13+
from ..factories.service import ServiceFactory, DaprComponentFactory
14+
from ..health.checks import RedisHealthCheck, PostgresHealthCheck
15+
from ..builders.dockerfile import DevelopmentDockerfileBuilder, ProductionDockerfileBuilder
1616

1717

1818
@pytest.fixture

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ services:
1111
context: .
1212
dockerfile: Dockerfile.dev
1313
container_name: openai-agents-dev
14-
profiles:
15-
- dev
1614
volumes:
1715
- .:/workspace:cached
1816
- /var/run/docker.sock:/var/run/docker.sock

0 commit comments

Comments
 (0)