feat: store leads in PostgreSQL instead of SQLite
- server.js uses pg (pinned 8.23.1), reads DATABASE_URL, creates the leads table on start, fails fast if Postgres is unreachable - tests run against a real Postgres in a throwaway schema - CI runs the test image against a throwaway Postgres on DinD - k8s: Postgres 18 StatefulSet (Longhorn, 2Gi), init container wait, password secret, network policy app-to-postgres; app no longer needs a volume or Recreate - README: DBeaver via port-forward, CSV export via docs/export-leads.sql Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfmHGGiYUjNcvJoyzdf
This commit is contained in:
1 parent
5bb2a7343d
commit
f78bd635a2
15 files changed
+508
-166
No files matched your search
+24
-27
@@ -1,18 +1,3 @@
|
||||
# Leads live in a SQLite file on this volume. ReadWriteOnce + 1 replica + Recreate: SQLite has a
|
||||
# single writer, so two pods must never hold the file at once (not even during a rollout).
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: ins-landing-page-data
|
||||
namespace: ins-landing-page
|
||||
spec:
|
||||
storageClassName: longhorn
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
@@ -32,8 +17,6 @@ metadata:
|
||||
namespace: ins-landing-page
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
selector:
|
||||
matchLabels:
|
||||
app: ins-landing-page
|
||||
@@ -49,7 +32,23 @@ spec:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 1000 # the image's `node` user
|
||||
runAsGroup: 1000
|
||||
fsGroup: 1000 # so the app can write to the Longhorn volume
|
||||
# Start the app only once Postgres answers, instead of crash-looping into a growing back-off
|
||||
# after a first install or a node restart. Same image as the StatefulSet, so nothing extra is pulled.
|
||||
initContainers:
|
||||
- name: wait-for-postgres
|
||||
image: postgres:18
|
||||
command: ["sh", "-c", "until pg_isready -h postgres -p 5432 -U ins -d ins; do sleep 2; done"]
|
||||
resources:
|
||||
requests:
|
||||
cpu: 10m
|
||||
memory: 16Mi
|
||||
limits:
|
||||
memory: 64Mi
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
readOnlyRootFilesystem: true
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
containers:
|
||||
- name: ins-landing-page
|
||||
# One moving tag per profile (CI); the rollout restarts the pod to pull it.
|
||||
@@ -58,14 +57,16 @@ spec:
|
||||
env:
|
||||
- name: PORT
|
||||
value: "3000"
|
||||
- name: DB_PATH
|
||||
value: /data/leads.db
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: ins-landing-page-db
|
||||
key: POSTGRES_PASSWORD
|
||||
- name: DATABASE_URL
|
||||
value: postgres://ins:$(POSTGRES_PASSWORD)@postgres:5432/ins
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 3000
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
@@ -89,7 +90,3 @@ spec:
|
||||
readOnlyRootFilesystem: true
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: ins-landing-page-data
|
||||
Reference in new issue
Block a user