feat: Add migration init container to StatefulSet
- Add migration init container that runs before main app containers - Ensures database migrations are applied on every deployment - Includes all necessary environment variables for migration execution - Disable AUTO_MIGRATE in main container since init container handles it - Prevents race conditions by running migrations before cluster formation This resolves issues where migrations weren't running in cluster mode and ensures new deployments always have the latest schema changes.
This commit is contained in:
parent
eee26074eb
commit
ed2d43f36d
1 changed files with 83 additions and 6 deletions
|
|
@ -45,6 +45,72 @@ spec:
|
|||
serviceAccountName: aprs-service-account
|
||||
imagePullSecrets:
|
||||
- name: ghcr-pull-secret
|
||||
initContainers:
|
||||
- name: wait-for-db
|
||||
image: busybox:1.36.1
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
echo "Waiting for PostgreSQL at 10.0.19.220:5432..."
|
||||
until nc -z 10.0.19.220 5432; do
|
||||
echo "Database not ready, waiting..."
|
||||
sleep 2
|
||||
done
|
||||
echo "Database is ready!"
|
||||
- name: wait-for-redis
|
||||
image: busybox:1.36.1
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- until nc -z redis 6379; do echo waiting for redis; sleep 2; done
|
||||
- name: migrate
|
||||
image: ghcr.io/aprsme/aprs.me:latest
|
||||
imagePullPolicy: Always
|
||||
command: ["/app/bin/aprsme", "eval", "Aprsme.Release.migrate()"]
|
||||
env:
|
||||
- name: DATABASE_URL
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aprs-secret
|
||||
key: database-url
|
||||
- name: DATABASE_SSL
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aprs-secret
|
||||
key: database-ssl
|
||||
- name: DATABASE_SSL_VERIFY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aprs-secret
|
||||
key: database-ssl-verify
|
||||
- name: SECRET_KEY_BASE
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aprs-secret
|
||||
key: secret-key-base
|
||||
- name: MIX_ENV
|
||||
value: "prod"
|
||||
- name: POOL_SIZE
|
||||
value: "1"
|
||||
- name: SKIP_DB_CREATE
|
||||
value: "true"
|
||||
- name: REDIS_URL
|
||||
value: "redis://redis.aprs.svc.cluster.local:6379"
|
||||
- name: PHX_HOST
|
||||
value: "aprs.me"
|
||||
- name: PORT
|
||||
value: "4000"
|
||||
- name: APRS_CALLSIGN
|
||||
value: "W5ISP-1"
|
||||
- name: APRS_FILTER
|
||||
value: "r/33/-96/1000000000000"
|
||||
- name: APRS_PASSCODE
|
||||
value: "15748"
|
||||
- name: APRS_PORT
|
||||
value: "10152"
|
||||
- name: APRS_SERVER
|
||||
value: "dallas.aprs2.net"
|
||||
containers:
|
||||
- name: aprs
|
||||
image: ghcr.io/aprsme/aprs.me:latest
|
||||
|
|
@ -67,7 +133,17 @@ spec:
|
|||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aprs-secret
|
||||
key: database-url-pgbouncer
|
||||
key: database-url
|
||||
- name: DATABASE_SSL
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aprs-secret
|
||||
key: database-ssl
|
||||
- name: DATABASE_SSL_VERIFY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aprs-secret
|
||||
key: database-ssl-verify
|
||||
- name: SECRET_KEY_BASE
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
|
|
@ -115,14 +191,15 @@ spec:
|
|||
- name: DRAIN_TIMEOUT_MS
|
||||
value: "45000"
|
||||
- name: SKIP_DB_CREATE
|
||||
value: "true"
|
||||
value: "true" # Database already exists on external server
|
||||
- name: AUTO_MIGRATE
|
||||
value: "false" # Disabled - migrations now handled by init container
|
||||
resources:
|
||||
limits:
|
||||
memory: "512Mi"
|
||||
cpu: "500m"
|
||||
memory: "1Gi"
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
cpu: "250m"
|
||||
memory: "1Gi"
|
||||
cpu: "500m"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue