add local cluster config

This commit is contained in:
2026-05-13 12:53:55 -03:00
parent 957e45b8ad
commit 55aa31eff5
18 changed files with 313 additions and 5 deletions

View File

@@ -1,7 +1,8 @@
.PHONY: up down seed invoke install logs console clean graphs docs
.PHONY: up down seed invoke install logs console clean graphs docs kind tilt-up tilt-down
PY ?= .venv/bin/python
PIP ?= .venv/bin/pip
COMPOSE := docker compose -f ctrl/docker-compose.yml
DOT_SRC := $(wildcard docs/graphs/*.dot)
SVG_OUT := $(DOT_SRC:.dot=.svg)
@@ -11,18 +12,27 @@ install:
$(PIP) install -r requirements.txt
up:
docker compose up -d
$(COMPOSE) up -d
@echo "MinIO API: http://localhost:9000"
@echo "MinIO console: http://localhost:9001 (minioadmin / minioadmin)"
down:
docker compose down
$(COMPOSE) down
clean:
docker compose down -v
$(COMPOSE) down -v
logs:
docker compose logs -f minio
$(COMPOSE) logs -f minio
kind:
bash ctrl/kind-config.sh
tilt-up:
cd ctrl && tilt up --context kind-eth
tilt-down:
cd ctrl && tilt down --context kind-eth
seed:
@if [ -z "$$SOURCE_DIR" ]; then echo "set SOURCE_DIR=<path-to-pdfs>"; exit 2; fi

3
ctrl/Dockerfile.docs Normal file
View File

@@ -0,0 +1,3 @@
FROM nginx:alpine
COPY docs/ /usr/share/nginx/html/
COPY ctrl/nginx.conf /etc/nginx/conf.d/default.conf

10
ctrl/Dockerfile.lambda Normal file
View File

@@ -0,0 +1,10 @@
FROM python:3.13-slim
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY lambda_function.py invoke.py seed.py ./
CMD ["sleep", "infinity"]

50
ctrl/Tiltfile Normal file
View File

@@ -0,0 +1,50 @@
# ETH — Tilt development environment
# Usage: cd ctrl && tilt up
# Cluster: kind (name: eth — create via ./kind-config.sh)
# Entry point: http://localhost:8050 (or http://eth.local.ar via Caddy)
allow_k8s_contexts('kind-eth')
# Hard guard: Tilt snapshots the kubectl context at startup (before parsing
# this file), so we can't switch it from here. Prefer `tilt up --context
# kind-eth` to bypass the shell's global context entirely.
if k8s_context() != 'kind-eth':
fail("Wrong kubectl context: '%s'. Run with: tilt up --context kind-eth" % k8s_context())
local('kubectl --context kind-eth create namespace eth --dry-run=client -o yaml | kubectl --context kind-eth apply -f -')
k8s_yaml(kustomize('k8s/overlays/dev'))
# --- Images ---
docker_build(
'eth-lambda',
context='..',
dockerfile='Dockerfile.lambda',
ignore=['.git', 'def', '.venv', 'docs', '__pycache__', '.pytest_cache'],
live_update=[
sync('../lambda_function.py', '/app/lambda_function.py'),
sync('../invoke.py', '/app/invoke.py'),
sync('../seed.py', '/app/seed.py'),
],
)
docker_build(
'eth-docs',
context='..',
dockerfile='Dockerfile.docs',
live_update=[
sync('../docs', '/usr/share/nginx/html'),
],
)
# --- Resources ---
k8s_resource('minio')
k8s_resource('lambda', resource_deps=['minio'])
k8s_resource('docs')
k8s_resource(
objects=['eth:namespace', 'eth-config:configmap'],
new_name='infra',
)

3
ctrl/invoke.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
set -euo pipefail
kubectl --context kind-eth -n eth exec -i deploy/lambda -- python invoke.py "$@"

View File

@@ -0,0 +1,14 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: eth-config
namespace: eth
data:
BUCKET_NAME: "my-company-reports-bucket"
PREFIX: "2026/04/"
URL_EXPIRY_SECONDS: "900"
S3_ENDPOINT_URL: "http://minio:9000"
AWS_ACCESS_KEY_ID: "minioadmin"
AWS_SECRET_ACCESS_KEY: "minioadmin"
AWS_REGION: "us-east-1"
AWS_DEFAULT_REGION: "us-east-1"

44
ctrl/k8s/base/docs.yaml Normal file
View File

@@ -0,0 +1,44 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: docs
namespace: eth
spec:
replicas: 1
selector:
matchLabels:
app: docs
template:
metadata:
labels:
app: docs
spec:
containers:
- name: docs
image: eth-docs
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 2
periodSeconds: 10
resources:
requests:
memory: 32Mi
cpu: 50m
limits:
memory: 128Mi
---
apiVersion: v1
kind: Service
metadata:
name: docs
namespace: eth
spec:
selector:
app: docs
ports:
- port: 80
targetPort: 80

View File

@@ -0,0 +1,11 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: eth
resources:
- namespace.yaml
- configmap.yaml
- minio.yaml
- lambda.yaml
- docs.yaml

29
ctrl/k8s/base/lambda.yaml Normal file
View File

@@ -0,0 +1,29 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: lambda
namespace: eth
spec:
replicas: 1
selector:
matchLabels:
app: lambda
template:
metadata:
labels:
app: lambda
spec:
containers:
- name: lambda
image: eth-lambda
command: ["sleep", "infinity"]
workingDir: /app
envFrom:
- configMapRef:
name: eth-config
resources:
requests:
memory: 128Mi
cpu: 100m
limits:
memory: 512Mi

63
ctrl/k8s/base/minio.yaml Normal file
View File

@@ -0,0 +1,63 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: minio
namespace: eth
spec:
replicas: 1
selector:
matchLabels:
app: minio
template:
metadata:
labels:
app: minio
spec:
containers:
- name: minio
image: minio/minio:latest
args: ["server", "/data", "--console-address", ":9001"]
env:
- name: MINIO_ROOT_USER
value: minioadmin
- name: MINIO_ROOT_PASSWORD
value: minioadmin
ports:
- containerPort: 9000
name: api
- containerPort: 9001
name: console
readinessProbe:
httpGet:
path: /minio/health/live
port: 9000
initialDelaySeconds: 5
periodSeconds: 10
volumeMounts:
- name: data
mountPath: /data
resources:
requests:
memory: 128Mi
cpu: 100m
limits:
memory: 512Mi
volumes:
- name: data
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: minio
namespace: eth
spec:
selector:
app: minio
ports:
- name: api
port: 9000
targetPort: 9000
- name: console
port: 9001
targetPort: 9001

View File

@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: eth

10
ctrl/k8s/kind-config.yaml Normal file
View File

@@ -0,0 +1,10 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: eth
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30050
hostPort: 8050
listenAddress: "0.0.0.0"
protocol: TCP

View File

@@ -0,0 +1,17 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
patches:
- target:
kind: Service
name: docs
patch: |
- op: replace
path: /spec/type
value: NodePort
- op: add
path: /spec/ports/0/nodePort
value: 30050

12
ctrl/kind-config.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
if kind get clusters 2>/dev/null | grep -qx eth; then
echo "kind cluster 'eth' already exists"
else
echo "creating kind cluster 'eth'..."
kind create cluster --config k8s/kind-config.yaml
fi
kubectl config use-context kind-eth

9
ctrl/nginx.conf Normal file
View File

@@ -0,0 +1,9 @@
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
}

14
ctrl/project.json Normal file
View File

@@ -0,0 +1,14 @@
{
"images": [
{
"name": "eth/lambda",
"dockerfile": "ctrl/Dockerfile.lambda",
"context": "."
},
{
"name": "eth/docs",
"dockerfile": "ctrl/Dockerfile.docs",
"context": "."
}
]
}

5
ctrl/tilt_config.json Normal file
View File

@@ -0,0 +1,5 @@
{
"kind_cluster_name": "eth",
"kind_config": "k8s/kind-config.yaml",
"default_registry": ""
}