Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ api/ Route handlers and Pydantic schemas
auth/ JWT, RBAC, rate limiting
database/ SQLAlchemy models and session lifecycle
services/ Kubernetes, Terraform, deployment, monitoring logic
web/ Developer dashboard served by FastAPI
kubernetes/ Cluster RBAC and network policy examples
terraform/ AWS Terraform templates
helm/ Helm chart for the API itself
Expand Down Expand Up @@ -66,6 +67,8 @@ Monitoring:

Swagger/OpenAPI is available at `/docs`.

The developer dashboard is available at `/dashboard/`.

## Local Development

Create an environment file:
Expand All @@ -90,6 +93,15 @@ python3 -m venv .venv
./.venv/bin/uvicorn app.main:app --reload
```

Open the dashboard:

```text
http://127.0.0.1:8000/dashboard/
```

The dashboard lets developers register/login, deploy Docker images, see app status, delete deployments, and fetch pod logs.
It also includes app-template and image-catalog dropdowns so developers can start from known defaults and still override the generated values.

Register and log in:

```bash
Expand Down
69 changes: 69 additions & 0 deletions api/routes/catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from fastapi import APIRouter

router = APIRouter()

APP_TEMPLATES = [
{
"id": "nginx-web",
"name": "Nginx web app",
"description": "Official nginx image that serves a default HTTP page on port 80.",
"default_app_name": "nginx-web",
"image": "nginx:1.25",
"port": 80,
"replicas": 2,
"min_replicas": 1,
"max_replicas": 5,
"cpu_threshold": 70,
},
{
"id": "apache-web",
"name": "Apache web app",
"description": "Official Apache HTTP server image that works as a simple web deployment.",
"default_app_name": "apache-web",
"image": "httpd:2.4",
"port": 80,
"replicas": 2,
"min_replicas": 1,
"max_replicas": 5,
"cpu_threshold": 70,
},
{
"id": "whoami-api",
"name": "Whoami API",
"description": "Tiny HTTP app that returns request and container details.",
"default_app_name": "whoami-api",
"image": "traefik/whoami:v1.10",
"port": 80,
"replicas": 2,
"min_replicas": 1,
"max_replicas": 6,
"cpu_threshold": 70,
},
{
"id": "hello-web",
"name": "Hello web app",
"description": "Nginx demo app that serves a simple hello page.",
"default_app_name": "hello-web",
"image": "nginxdemos/hello:plain-text",
"port": 80,
"replicas": 2,
"min_replicas": 1,
"max_replicas": 5,
"cpu_threshold": 70,
},
]

IMAGE_CATALOG = [
{"label": "nginx 1.25", "image": "nginx:1.25", "port": 80},
{"label": "httpd 2.4", "image": "httpd:2.4", "port": 80},
{"label": "traefik whoami", "image": "traefik/whoami:v1.10", "port": 80},
{"label": "nginx hello demo", "image": "nginxdemos/hello:plain-text", "port": 80},
]


@router.get("")
def get_catalog():
return {
"apps": APP_TEMPLATES,
"images": IMAGE_CATALOG,
}
14 changes: 14 additions & 0 deletions api/routes/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@

router = APIRouter()


@router.get("", response_model=list[DeploymentResponse])
def list_deployments(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
return (
db.query(Deployment)
.filter(Deployment.owner_id == current_user.id)
.order_by(Deployment.created_at.desc())
.all()
)


@router.post("", response_model=DeploymentResponse, status_code=201)
def create_deployment_route(
request: DeploymentCreateRequest,
Expand Down
4 changes: 3 additions & 1 deletion api/schemas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Any, Dict, Optional
from typing import Any, Dict, List, Optional

from pydantic import BaseModel, Field, validator

Expand Down Expand Up @@ -49,6 +49,8 @@ class DeploymentCreateRequest(BaseModel):
cpu_threshold: int = Field(default=70, ge=10, le=95)
ingress_host: Optional[str] = Field(default=None, max_length=253)
env: Dict[str, str] = Field(default_factory=dict)
command: Optional[List[str]] = None
args: Optional[List[str]] = None

@validator("max_replicas")
def max_gte_min(cls, value, values):
Expand Down
11 changes: 10 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from fastapi import Depends, FastAPI
from api.routes import auth, infrastructure, deployments, kubernetes, monitoring
from fastapi.responses import RedirectResponse
from fastapi.staticfiles import StaticFiles
from api.routes import auth, catalog, deployments, infrastructure, kubernetes, monitoring
from auth.rate_limit import rate_limiter
from app.config import settings
from app.logger import setup_logging
Expand Down Expand Up @@ -36,10 +38,12 @@ def on_startup():
tags=["deployments"],
dependencies=[Depends(rate_limiter)],
)
app.include_router(catalog.router, prefix="/catalog", tags=["catalog"], dependencies=[Depends(rate_limiter)])
app.include_router(kubernetes.router, prefix="/kubernetes", tags=["kubernetes"], dependencies=[Depends(rate_limiter)])
app.include_router(monitoring.router, prefix="/monitoring", tags=["monitoring"], dependencies=[Depends(rate_limiter)])
app.include_router(kubernetes.router, tags=["kubernetes"], dependencies=[Depends(rate_limiter)])
app.include_router(monitoring.router, tags=["monitoring"], dependencies=[Depends(rate_limiter)])
app.mount("/dashboard", StaticFiles(directory="web", html=True), name="dashboard")


@app.get("/healthz")
Expand All @@ -55,3 +59,8 @@ def readiness_check():
"kubernetes_dry_run": settings.KUBERNETES_DRY_RUN,
"terraform_dry_run": settings.TERRAFORM_DRY_RUN,
}


@app.get("/")
def root():
return RedirectResponse(url="/dashboard/")
12 changes: 11 additions & 1 deletion services/deployment_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def create_deployment(
port: int = 80,
replicas: int = 1,
secret_name: Optional[str] = None,
command: Optional[list[str]] = None,
args: Optional[list[str]] = None,
):
if settings.KUBERNETES_DRY_RUN:
logger.info("Dry run: deployment %s/%s with image %s would be created", namespace, name, image)
Expand All @@ -78,6 +80,8 @@ def create_deployment(
env_from=[
client.V1EnvFromSource(secret_ref=client.V1SecretEnvSource(name=secret_name))
] if secret_name else None,
command=command,
args=args,
)
template = client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(labels={"app": name}),
Expand Down Expand Up @@ -154,7 +158,11 @@ def provision_application(db: Session, user: User, request: DeploymentCreateRequ
ingress_host=ingress_host,
url=f"https://{ingress_host}",
status="provisioning",
metadata_json={"env_keys": sorted(request.env.keys())},
metadata_json={
"env_keys": sorted(request.env.keys()),
"command": request.command,
"args": request.args,
},
)
db.add(deployment)
db.commit()
Expand All @@ -171,6 +179,8 @@ def provision_application(db: Session, user: User, request: DeploymentCreateRequ
request.port,
request.replicas,
secret_name=f"{request.name}-env" if request.env else None,
command=request.command,
args=request.args,
),
expose_service(namespace, request.name, 80, request.port),
create_ingress(namespace, request.name, request.name, 80, ingress_host),
Expand Down
Loading
Loading