Skip to content

Phase 8.4 — Docker/Helm: containerisation & Kubernetes deployment for ASI-Build #291

@web3guru888

Description

@web3guru888

Overview

Phase 8.4 delivers production-grade containerisation and Kubernetes deployment manifests for the full ASI-Build stack (cognitive core + ExplainAPI + Prometheus/Grafana). It is the first deployment-hardening sub-phase of Phase 8 and lays the groundwork for Phase 8.5 (Sepolia CI).


Motivation

The ASI-Build runtime today lives exclusively in Python source files. Shipping it to a real server or cloud cluster requires:

Gap Solution
No reproducible runtime environment Multi-stage Dockerfile with pinned base image
Local dev friction (seven services) docker-compose.yml one-command stack
No auto-scaling / self-healing Helm chart with HPA + liveness/readiness probes
No in-cluster metrics scraping Prometheus ServiceMonitor CRD via kube-prometheus-stack
No resource quotas resources: limits in every Deployment

Deliverables

1. Dockerfile (multi-stage)

Stage 0  builder  — python:3.11-slim, install all deps, compile *.pyc
Stage 1  runtime  — python:3.11-slim, copy site-packages + app, drop to non-root uid=1000
  • Build arg ASI_VERSION baked into image label
  • HEALTHCHECK calls GET /health on the ExplainAPI port (8080)
  • Final image ≤ 350 MB (no dev tools, no pip cache)

2. docker-compose.yml (local dev / CI)

Services:

Service Image Port
asi-core ./Dockerfile
explain-api ./Dockerfile 8080
prometheus prom/prometheus:v2.51 9090
grafana grafana/grafana:10.4 3000
redis redis:7-alpine 6379

Volume mounts: ./config/prometheus.yml, ./config/grafana/, ./data/traces/

3. Helm chart (charts/asi-build/)

charts/asi-build/
├── Chart.yaml          # apiVersion: v2, appVersion from ASI_VERSION
├── values.yaml         # image.tag, replicaCount, resources, autoscaling
├── templates/
│   ├── deployment.yaml       # asi-core + explain-api containers
│   ├── service.yaml          # ClusterIP for explain-api
│   ├── ingress.yaml          # optional nginx ingress
│   ├── hpa.yaml              # HorizontalPodAutoscaler (CPU 70%)
│   ├── configmap.yaml        # prometheus.yml + grafana dashboards
│   ├── servicemonitor.yaml   # Prometheus Operator ServiceMonitor
│   └── _helpers.tpl

Key values.yaml knobs:

image:
  repository: ghcr.io/web3guru888/asi-build
  tag: latest
  pullPolicy: IfNotPresent

replicaCount: 2

resources:
  requests: { cpu: 500m, memory: 512Mi }
  limits:   { cpu: 2,    memory: 2Gi  }

autoscaling:
  enabled: true
  minReplicas: 2
  maxReplicas: 8
  targetCPUUtilizationPercentage: 70

explainApi:
  port: 8080
  rateLimitPerMinute: 60

prometheus:
  serviceMonitor:
    enabled: true
    interval: 15s

4. Makefile targets

Target Command
make docker-build docker build --build-arg ASI_VERSION=$(VERSION) -t asi-build:$(VERSION) .
make docker-push push to GHCR
make compose-up docker compose up -d
make compose-down docker compose down -v
make helm-lint helm lint charts/asi-build
make helm-install helm upgrade --install asi-build charts/asi-build -f values.yaml
make helm-template render manifests to stdout

5. GitHub Actions workflow (.github/workflows/docker.yml)

Triggers: push to main, pull_request

Steps:

  1. docker/setup-buildx-action
  2. docker/login-action → GHCR
  3. docker/build-push-action (multi-platform: linux/amd64 + linux/arm64)
  4. helm/kind-action → spin up kind cluster
  5. helm lint + helm install --dry-run
  6. docker scout cves → fail on CRITICAL CVEs

Acceptance Criteria

  • docker build . succeeds with no warnings
  • docker compose up raises all 5 services; /health returns 200
  • helm lint charts/asi-build exits 0
  • helm install --dry-run renders valid YAML
  • HPA manifest validates against Kubernetes 1.28 schema
  • ServiceMonitor CRD recognised by kube-prometheus-stack 0.71
  • GitHub Actions workflow passes on a clean runner
  • Image size ≤ 350 MB (checked via docker image inspect)
  • No CRITICAL CVEs in docker scout scan
  • All 12 test targets pass inside the container (pytest -x)

Implementation Order

  1. Write Dockerfile (multi-stage, non-root, HEALTHCHECK)
  2. Write docker-compose.yml with named volumes + healthchecks
  3. Write config/prometheus.yml scrape config (all 5 job names)
  4. Write charts/asi-build/Chart.yaml + values.yaml
  5. Write templates/deployment.yaml (liveness/readiness on /health)
  6. Write templates/hpa.yaml + templates/servicemonitor.yaml
  7. Write templates/configmap.yaml (Grafana dashboard JSON)
  8. Write Makefile with all 7 targets
  9. Write .github/workflows/docker.yml
  10. Run helm lint + docker build locally, fix errors
  11. Open PR, CI green, merge

Phase 8 Sub-phase Tracker

Sub-phase Issue Status
8.1 DecisionTracer #276 ✅ spec complete
8.2 CausalGraph #280 ✅ spec complete
8.3 ExplainAPI #283 ✅ spec complete
8.4 Docker/Helm #291 🟡 in progress
8.5 Sepolia CI TBD 📋 planned

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions