base-deployment-controller 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- base_deployment_controller/__init__.py +59 -0
- base_deployment_controller/builder.py +90 -0
- base_deployment_controller/models/__init__.py +33 -0
- base_deployment_controller/models/compose.py +11 -0
- base_deployment_controller/models/container.py +31 -0
- base_deployment_controller/models/deployment.py +57 -0
- base_deployment_controller/models/environment.py +42 -0
- base_deployment_controller/routers/__init__.py +7 -0
- base_deployment_controller/routers/container.py +398 -0
- base_deployment_controller/routers/deployment.py +281 -0
- base_deployment_controller/routers/environment.py +174 -0
- base_deployment_controller/services/__init__.py +5 -0
- base_deployment_controller/services/config.py +560 -0
- base_deployment_controller-0.1.0.dist-info/METADATA +184 -0
- base_deployment_controller-0.1.0.dist-info/RECORD +17 -0
- base_deployment_controller-0.1.0.dist-info/WHEEL +5 -0
- base_deployment_controller-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Base Deployment Controller package entry point."""
|
|
2
|
+
from fastapi import FastAPI
|
|
3
|
+
|
|
4
|
+
from .services.config import ConfigService
|
|
5
|
+
from .routers.environment import EnvRoutes
|
|
6
|
+
from .routers.container import ContainerRoutes
|
|
7
|
+
from .routers.deployment import DeploymentRoutes
|
|
8
|
+
from .builder import AppBuilder
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def create_app(
|
|
12
|
+
compose_file: str = "compose.yaml",
|
|
13
|
+
env_file: str = ".env",
|
|
14
|
+
include_routers: bool = True,
|
|
15
|
+
title: str = "Base Deployment Controller",
|
|
16
|
+
description: str = "REST API to control the basic operations of a deployment",
|
|
17
|
+
version: str = "1.0.0",
|
|
18
|
+
) -> FastAPI:
|
|
19
|
+
"""
|
|
20
|
+
Factory function to create a preconfigured FastAPI application.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
compose_file: Path to compose.yaml file.
|
|
24
|
+
env_file: Path to .env file.
|
|
25
|
+
include_routers: If True, registers base routers (envs, containers, deployment).
|
|
26
|
+
title: FastAPI application title.
|
|
27
|
+
description: FastAPI application description.
|
|
28
|
+
version: Application version string.
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
FastAPI app ready to use or extend.
|
|
32
|
+
"""
|
|
33
|
+
app = FastAPI(
|
|
34
|
+
title=title,
|
|
35
|
+
description=description,
|
|
36
|
+
version=version,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
if include_routers:
|
|
40
|
+
config_service = ConfigService(compose_file, env_file)
|
|
41
|
+
env_routes = EnvRoutes(config_service)
|
|
42
|
+
container_routes = ContainerRoutes(config_service)
|
|
43
|
+
deployment_routes = DeploymentRoutes(config_service)
|
|
44
|
+
|
|
45
|
+
app.include_router(env_routes.router)
|
|
46
|
+
app.include_router(container_routes.router)
|
|
47
|
+
app.include_router(deployment_routes.router)
|
|
48
|
+
|
|
49
|
+
return app
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
__all__ = [
|
|
53
|
+
"ConfigService",
|
|
54
|
+
"EnvRoutes",
|
|
55
|
+
"ContainerRoutes",
|
|
56
|
+
"DeploymentRoutes",
|
|
57
|
+
"AppBuilder",
|
|
58
|
+
"create_app",
|
|
59
|
+
]
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Application builder for composing the FastAPI app and custom routers."""
|
|
2
|
+
from typing import List, Tuple
|
|
3
|
+
|
|
4
|
+
from fastapi import APIRouter, FastAPI
|
|
5
|
+
|
|
6
|
+
from .services.config import ConfigService
|
|
7
|
+
from .routers.environment import EnvRoutes
|
|
8
|
+
from .routers.container import ContainerRoutes
|
|
9
|
+
from .routers.deployment import DeploymentRoutes
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AppBuilder:
|
|
13
|
+
"""
|
|
14
|
+
Builder for constructing a Base Deployment Controller FastAPI application.
|
|
15
|
+
|
|
16
|
+
Allows registration of custom routers before building the final app.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
compose_file: Path to Docker Compose file.
|
|
20
|
+
env_file: Path to environment variables file.
|
|
21
|
+
title: FastAPI application title.
|
|
22
|
+
description: FastAPI application description.
|
|
23
|
+
version: Application version string.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
compose_file: str = "compose.yaml",
|
|
29
|
+
env_file: str = ".env",
|
|
30
|
+
title: str = "Base Deployment Controller",
|
|
31
|
+
description: str = "REST API for managing base deployment",
|
|
32
|
+
version: str = "1.0.0",
|
|
33
|
+
) -> None:
|
|
34
|
+
"""
|
|
35
|
+
Initialize the builder and register default routers.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
compose_file: Path to Docker Compose file.
|
|
39
|
+
env_file: Path to environment variables file.
|
|
40
|
+
title: FastAPI application title.
|
|
41
|
+
description: FastAPI application description.
|
|
42
|
+
version: Application version string.
|
|
43
|
+
"""
|
|
44
|
+
self.compose_file = compose_file
|
|
45
|
+
self.env_file = env_file
|
|
46
|
+
self.title = title
|
|
47
|
+
self.description = description
|
|
48
|
+
self.version = version
|
|
49
|
+
self._custom_routers: List[Tuple[APIRouter, str]] = []
|
|
50
|
+
|
|
51
|
+
def register_router(self, router: APIRouter, prefix: str = "") -> "AppBuilder":
|
|
52
|
+
"""
|
|
53
|
+
Register a custom router to include when building the app.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
router: Router instance to register.
|
|
57
|
+
prefix: Optional path prefix for the router.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
AppBuilder instance for fluent chaining.
|
|
61
|
+
"""
|
|
62
|
+
self._custom_routers.append((router, prefix))
|
|
63
|
+
return self
|
|
64
|
+
|
|
65
|
+
def build(self) -> FastAPI:
|
|
66
|
+
"""
|
|
67
|
+
Build and return a FastAPI app with base and custom routers.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
FastAPI application instance.
|
|
71
|
+
"""
|
|
72
|
+
app = FastAPI(
|
|
73
|
+
title=self.title,
|
|
74
|
+
description=self.description,
|
|
75
|
+
version=self.version,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
config_service = ConfigService(self.compose_file, self.env_file)
|
|
79
|
+
env_routes = EnvRoutes(config_service)
|
|
80
|
+
container_routes = ContainerRoutes(config_service)
|
|
81
|
+
deployment_routes = DeploymentRoutes(config_service)
|
|
82
|
+
|
|
83
|
+
app.include_router(env_routes.router)
|
|
84
|
+
app.include_router(container_routes.router)
|
|
85
|
+
app.include_router(deployment_routes.router)
|
|
86
|
+
|
|
87
|
+
for router, prefix in self._custom_routers:
|
|
88
|
+
app.include_router(router, prefix=prefix)
|
|
89
|
+
|
|
90
|
+
return app
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Pydantic models for the Base Deployment Controller."""
|
|
2
|
+
|
|
3
|
+
from .environment import (
|
|
4
|
+
EnvVariable,
|
|
5
|
+
EnvVariablesResponse,
|
|
6
|
+
BulkEnvUpdateRequest,
|
|
7
|
+
EnvUpdateResponse,
|
|
8
|
+
)
|
|
9
|
+
from .container import ContainerInfo, ContainersInfoResponse, ContainerControlResponse
|
|
10
|
+
from .deployment import (
|
|
11
|
+
DeploymentStatus,
|
|
12
|
+
DeploymentMetadata,
|
|
13
|
+
DeploymentInfoResponse,
|
|
14
|
+
DeploymentPingResponse,
|
|
15
|
+
DeploymentActionResponse,
|
|
16
|
+
)
|
|
17
|
+
from .compose import ComposeActionResponse
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"EnvVariable",
|
|
21
|
+
"EnvVariablesResponse",
|
|
22
|
+
"BulkEnvUpdateRequest",
|
|
23
|
+
"EnvUpdateResponse",
|
|
24
|
+
"ContainerInfo",
|
|
25
|
+
"ContainersInfoResponse",
|
|
26
|
+
"ContainerControlResponse",
|
|
27
|
+
"DeploymentStatus",
|
|
28
|
+
"DeploymentMetadata",
|
|
29
|
+
"DeploymentInfoResponse",
|
|
30
|
+
"DeploymentPingResponse",
|
|
31
|
+
"DeploymentActionResponse",
|
|
32
|
+
"ComposeActionResponse",
|
|
33
|
+
]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Docker Compose operation models."""
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, Field
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ComposeActionResponse(BaseModel):
|
|
8
|
+
"""Response after executing a docker-compose action (up/stop/restart)."""
|
|
9
|
+
|
|
10
|
+
success: bool = Field(..., description="Operation success status")
|
|
11
|
+
message: str = Field(..., description="Operation result message")
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Container models."""
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, Field, field_validator
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ContainerInfo(BaseModel):
|
|
9
|
+
"""Docker container information and service metadata."""
|
|
10
|
+
|
|
11
|
+
name: str = Field(..., description="Container name")
|
|
12
|
+
image: str = Field(..., description="Container image")
|
|
13
|
+
status: str = Field(..., description="Container status")
|
|
14
|
+
started_at: Optional[datetime] = Field(None, description="Container start time")
|
|
15
|
+
ports: list[str] = Field(..., description="Exposed ports")
|
|
16
|
+
depends_on: list[str] = Field(..., description="Service dependencies")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ContainersInfoResponse(BaseModel):
|
|
20
|
+
"""Response with list of containers and their current status."""
|
|
21
|
+
|
|
22
|
+
containers: list[ContainerInfo] = Field(..., description="List of containers")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ContainerControlResponse(BaseModel):
|
|
26
|
+
"""Response after executing a control action on a container."""
|
|
27
|
+
|
|
28
|
+
success: bool = Field(..., description="Action success status")
|
|
29
|
+
container: str = Field(..., description="Container name")
|
|
30
|
+
action: str = Field(..., description="Action performed")
|
|
31
|
+
message: str = Field(..., description="Status message")
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Deployment models."""
|
|
2
|
+
from enum import Enum
|
|
3
|
+
|
|
4
|
+
from .environment import EnvVariable
|
|
5
|
+
from pydantic import BaseModel, Field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class DeploymentStatus(str, Enum):
|
|
9
|
+
"""
|
|
10
|
+
Deployment status enumeration.
|
|
11
|
+
|
|
12
|
+
Values:
|
|
13
|
+
running: All services running.
|
|
14
|
+
partially_running: Some services running.
|
|
15
|
+
stopped: No services running.
|
|
16
|
+
unknown: Status cannot be determined.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
RUNNING = "running"
|
|
20
|
+
PARTIALLY_RUNNING = "partially_running"
|
|
21
|
+
STOPPED = "stopped"
|
|
22
|
+
UNKNOWN = "unknown"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class DeploymentMetadata(BaseModel):
|
|
26
|
+
"""Deployment metadata from x-metadata section in compose.yaml."""
|
|
27
|
+
|
|
28
|
+
id: str = Field(..., description="Deployment unique identifier")
|
|
29
|
+
name: str = Field(..., description="Deployment name")
|
|
30
|
+
description: str = Field(..., description="Deployment description")
|
|
31
|
+
version: str = Field(..., description="Deployment version")
|
|
32
|
+
author: str = Field(..., description="Deployment author")
|
|
33
|
+
changelog: str = Field(..., description="Deployment changelog")
|
|
34
|
+
documentation_url: str = Field(..., description="Documentation URL")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class DeploymentInfoResponse(BaseModel):
|
|
38
|
+
"""Response with basic deployment information."""
|
|
39
|
+
|
|
40
|
+
metadata: DeploymentMetadata = Field(..., description="Deployment metadata")
|
|
41
|
+
status: DeploymentStatus
|
|
42
|
+
env_vars: dict[str, EnvVariable] = Field(..., description="List of environment variables")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class DeploymentPingResponse(BaseModel):
|
|
46
|
+
"""Response for deployment ping endpoint."""
|
|
47
|
+
|
|
48
|
+
success: bool = Field(..., description="Ping success status")
|
|
49
|
+
message: str = Field(..., description="Ping message")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class DeploymentActionResponse(BaseModel):
|
|
53
|
+
"""Response after performing a deployment action."""
|
|
54
|
+
|
|
55
|
+
success: bool = Field(..., description="Action success status")
|
|
56
|
+
action: str = Field(..., description="Action performed")
|
|
57
|
+
message: str = Field(..., description="Status message")
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Environment variable models."""
|
|
2
|
+
from pydantic import BaseModel, Field
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class EnvVariable(BaseModel):
|
|
6
|
+
"""Environment variable model with metadata from x-env-vars schema."""
|
|
7
|
+
|
|
8
|
+
name: str = Field(..., description="Variable name")
|
|
9
|
+
description: str = Field(..., description="Variable description")
|
|
10
|
+
default: str = Field(..., description="Default value")
|
|
11
|
+
value: str = Field(..., description="Current value")
|
|
12
|
+
type: str = Field(..., description="Type constraint")
|
|
13
|
+
advanced: bool = Field(..., description="Is advanced variable")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class EnvVariablesResponse(BaseModel):
|
|
17
|
+
"""Response for listing all environment variables."""
|
|
18
|
+
|
|
19
|
+
variables: list[EnvVariable] = Field(..., description="List of environment variables")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class BulkEnvUpdateRequest(BaseModel):
|
|
23
|
+
"""Request to update multiple environment variables in bulk."""
|
|
24
|
+
|
|
25
|
+
variables: dict[str, str] = Field(..., description="Variables to update")
|
|
26
|
+
restart_services: bool = Field(
|
|
27
|
+
default=True,
|
|
28
|
+
description=(
|
|
29
|
+
"Whether to restart affected services after updating the variables."
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class EnvUpdateResponse(BaseModel):
|
|
35
|
+
"""Response after updating environment variables."""
|
|
36
|
+
|
|
37
|
+
success: bool = Field(..., description="Update success status")
|
|
38
|
+
updated: list[str] = Field(..., description="List of updated variables")
|
|
39
|
+
message: str = Field(..., description="Status message")
|
|
40
|
+
restarted_services: dict[str, bool] = Field(
|
|
41
|
+
default_factory=dict, description="Services restarted and their status"
|
|
42
|
+
)
|