# UNT — Tilt development environment
# Usage: cd ctrl && tilt up
# Cluster: kind (name: unt)
# Entry point: http://localhost:8040

allow_k8s_contexts('kind-unt')

# Create namespace first to avoid race conditions
local('kubectl create namespace unt --dry-run=client -o yaml | kubectl apply -f -')

# Apply k8s manifests via kustomize (dev overlay)
k8s_yaml(kustomize('k8s/overlays/dev'))

# --- Images ---

# FastAPI + MCP servers + agents (Python backend)
docker_build(
    'unt-api',
    context='..',
    dockerfile='Dockerfile.api',
    ignore=['.git', 'def', 'ui', '.claude', 'tests', '.venv', 'node_modules'],
    live_update=[
        sync('../mcp_servers', '/app/mcp_servers'),
        sync('../agents', '/app/agents'),
        sync('../api', '/app/api'),
    ],
)

# Vue UI — context is project root so framework link resolves
docker_build(
    'unt-ui',
    context='..',
    dockerfile='Dockerfile.ui',
    live_update=[
        sync('../ui/app/src', '/ui/app/src'),
        sync('../ui/app/index.html', '/ui/app/index.html'),
        sync('../ui/app/vite.config.ts', '/ui/app/vite.config.ts'),
        sync('../ui/framework/src', '/ui/framework/src'),
    ],
)

# --- Resources ---

k8s_resource('postgres')
k8s_resource('api', resource_deps=['postgres'])
k8s_resource('ui', resource_deps=['api'], port_forwards=['8040:80'])

# Group infra resources
k8s_resource(
    objects=['unt:namespace', 'unt-config:configmap'],
    new_name='infra',
)
