Add new infra architecture

This commit is contained in:
Urtzi Alfaro
2026-01-19 11:55:17 +01:00
parent 21d35ea92b
commit 35f164f0cd
311 changed files with 13241 additions and 3700 deletions

View File

@@ -0,0 +1,82 @@
# infrastructure/kubernetes/base/jobs/external-data-init-job.yaml
# One-time job to initialize 24 months of historical data for all enabled cities
apiVersion: batch/v1
kind: Job
metadata:
name: external-data-init
namespace: bakery-ia
labels:
app: external-service
component: data-initialization
spec:
ttlSecondsAfterFinished: 86400
backoffLimit: 3
template:
metadata:
labels:
app: external-service
job: data-init
spec:
imagePullSecrets:
- name: dockerhub-creds
restartPolicy: OnFailure
initContainers:
- name: wait-for-db
image: postgres:17-alpine
command:
- sh
- -c
- |
until pg_isready -h $EXTERNAL_DB_HOST -p $DB_PORT -U $EXTERNAL_DB_USER; do
echo "Waiting for database..."
sleep 2
done
echo "Database is ready"
envFrom:
- configMapRef:
name: bakery-config
- secretRef:
name: database-secrets
- name: wait-for-migration
image: postgres:17-alpine
command:
- sh
- -c
- |
echo "Waiting for external-service migration to complete..."
sleep 15
echo "Migration should be complete"
envFrom:
- configMapRef:
name: bakery-config
containers:
- name: data-loader
image: bakery/external-service:latest
imagePullPolicy: Always
command:
- python
- -m
- app.jobs.initialize_data
args:
- "--months=6" # Reduced from 24 to avoid memory/rate limit issues
- "--log-level=INFO"
envFrom:
- configMapRef:
name: bakery-config
- secretRef:
name: database-secrets
- secretRef:
name: external-api-secrets
resources:
requests:
memory: "2Gi" # Increased from 1Gi
cpu: "500m"
limits:
memory: "4Gi" # Increased from 2Gi
cpu: "1000m"

View File

@@ -0,0 +1,58 @@
# Enhanced migration job for external service with automatic table creation
apiVersion: batch/v1
kind: Job
metadata:
name: external-migration
namespace: bakery-ia
labels:
app.kubernetes.io/name: external-migration
app.kubernetes.io/component: migration
app.kubernetes.io/part-of: bakery-ia
spec:
backoffLimit: 3
template:
metadata:
labels:
app.kubernetes.io/name: external-migration
app.kubernetes.io/component: migration
spec:
imagePullSecrets:
- name: dockerhub-creds
- name: ghcr-creds
initContainers:
- name: wait-for-db
image: postgres:17-alpine
command: ["sh", "-c", "until pg_isready -h external-db-service -p 5432; do sleep 2; done"]
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
containers:
- name: migrate
image: bakery/external-service
command: ["python", "/app/shared/scripts/run_migrations.py", "external"]
env:
- name: EXTERNAL_DATABASE_URL
valueFrom:
secretKeyRef:
name: database-secrets
key: EXTERNAL_DATABASE_URL
- name: DB_FORCE_RECREATE
valueFrom:
configMapKeyRef:
name: bakery-config
key: DB_FORCE_RECREATE
optional: true
- name: LOG_LEVEL
value: "INFO"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"
restartPolicy: OnFailure