2026-01-14 04:53:21 +00:00
|
|
|
# Infrastructure Schemas\n\nThis directory contains Nickel type-safe schemas for infrastructure configuration generation.\n\n## Overview\n\nThese schemas provide type contracts and validation for multi-format infrastructure configuration generation:\n\n- **Docker Compose** (`docker-compose.ncl`) - Container orchestration via Docker Compose\n- **Kubernetes** (`kubernetes.ncl`) - Kubernetes manifest generation (Deployments, Services, ConfigMaps)\n- **Nginx** (`nginx.ncl`) - Reverse proxy and load balancer configuration\n- **Prometheus** (`prometheus.ncl`) - Metrics collection and monitoring\n- **Systemd** (`systemd.ncl`) - System service units for standalone deployments\n- **OCI Registry** (`oci-registry.ncl`) - Container registry backend configuration (Zot, Distribution, Harbor)\n\n## Key Features\n\n### 1. Mode-Based Presets\n\nEach schema includes presets for different deployment modes:\n\n- **solo**: Single-node deployments (minimal resources)\n- **multiuser**: Staging/small production (2 replicas, HA)\n- **enterprise**: Large-scale production (3+ replicas, distributed storage)\n- **cicd**: CI/CD pipeline deployments\n\n### 2. Type Safety\n\n```\n# All fields are strongly typed with validation\nResourceLimits = {\n cpus | String, # Type: string\n memory | String,\n},\n\n# Enum validation\nServiceType = [| 'ClusterIP, 'NodePort, 'LoadBalancer |],\n\n# Numeric range validation\nPort = Number | {\n predicate = fun n => n > 0 && n < 65536,\n}\n```\n\n### 3. Export Formats\n\nSchemas export to multiple formats:\n\n```\n# Export as YAML (K8s, Docker Compose)\nnickel export --format yaml provisioning/schemas/infrastructure/kubernetes.ncl\n\n# Export as JSON (OCI Registry, Prometheus configs)\nnickel export --format json provisioning/schemas/infrastructure/oci-registry.ncl\n\n# Export as TOML (systemd, Nginx)\nnickel export --format toml provisioning/schemas/infrastructure/systemd.ncl\n```\n\n## Single Source of Truth Pattern\n\nDefine service configuration once, generate multiple infrastructure outputs:\n\n```\norchestrator.ncl (Platform Service Schema)\n ↓\nInfrastructure Schemas (Docker, Kubernetes, Nginx, etc.)\n ↓\n[Multiple Outputs]\n├─→ docker-compose.yaml\n├─→ kubernetes/deployment.yaml\n├─→ nginx.conf\n├─→ prometheus.yml\n└─→ systemd/orchestrator.service\n```\n\n### Example: Service Port Definition\n\n```\n# Platform service schema (provisioning/schemas/platform/schemas/orchestrator.ncl)\nserver = {\n port | Number, # Define port once\n}\n\n# Used in Docker Compose\ndocker-compose = {\n services.orchestrator = {\n ports = ["%{orchestrator.server.port}:8080"],\n }\n}\n\n# Used in Kubernetes\nkubernetes = {\n containers.ports = [{\n containerPort = orchestrator.server.port,\n }]\n}\n\n# Used in Nginx\nnginx = {\n upstreams.orchestrator.servers = [{\n address = "orchestrator:%{orchestrator.server.port}",\n }]\n}\n```\n\n**Benefit**: Change port in one place, all infrastructure configs update automatically.\n\n## Validation Before Deployment\n\n```\n# Type check schema\nnickel typecheck provisioning/schemas/infrastructure/docker-compose.ncl\n\n# Validate export\nnickel export --format json provisioning/schemas/infrastructure/kubernetes.ncl \n | jq . # Validate JSON structure\n\n# Check generated YAML\nnickel export --format yaml provisioning/schemas/infrastructure/kubernetes.ncl \n | kubectl apply --dry-run=client -f -\n```\n\n## File Structure\n\n```\ninfrastructure/\n├── README.md # This file\n├── docker-compose.ncl # Docker Compose schema (232 lines)\n├── kubernetes.ncl # Kubernetes manifests (376 lines)\n├── nginx.ncl # Nginx configuration (233 lines)\n├── prometheus.ncl # Prometheus configuration (280 lines)\n├── systemd.ncl # Systemd service units (235 lines)\n└── oci-registry.ncl # OCI Registry configuration (221 lines)\n```\n\n**Total**: 1,577 lines of type-safe inf
|