diff --git a/backend/Dockerfile b/backend/Dockerfile index fda6591..84bdb5a 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -8,6 +8,12 @@ # migrate One-shot Drizzle migrations (used as a k8s initContainer) ARG NODE_VERSION=22 +# The backend's dependency tree has unresolved peer conflicts (e.g. +# x402-stellar wants @stellar/stellar-sdk@^12 while the app uses ^15), so npm +# needs --legacy-peer-deps until that is fixed upstream +# (tracked in https://github.com/SynapsVault/backend/issues). Override with +# --build-arg NPM_FLAGS= once the upstream peer dependency issue is resolved. +ARG NPM_FLAGS=--legacy-peer-deps # Once upstream peer dependency conflicts (x402-stellar vs @stellar/stellar-sdk) # are resolved, drop --legacy-peer-deps by passing --build-arg NPM_FLAGS="" or # leaving NPM_FLAGS empty when the lockfile is clean. diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 93b865c..a31915e 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -3,6 +3,10 @@ # that repository; this file lives in the deploy repo. ARG NODE_VERSION=22 +# The frontend repo has no lockfile and conflicting peer dependencies, which +# crash npm's resolver; --legacy-peer-deps works around it until fixed upstream +# (tracked in https://github.com/SynapsVault/frontend/issues). +ARG NPM_FLAGS=--legacy-peer-deps # Once the upstream lockfile and peer dependencies are resolved, drop the # --legacy-peer-deps flag (override with --build-arg NPM_FLAGS=--legacy-peer-deps if needed). ARG NPM_FLAGS="" diff --git a/k8s/backend-deployment.yaml b/k8s/backend-deployment.yaml index 2d2a92f..3b520ba 100644 --- a/k8s/backend-deployment.yaml +++ b/k8s/backend-deployment.yaml @@ -29,6 +29,31 @@ spec: runAsGroup: 1000 seccompProfile: type: RuntimeDefault + initContainers: + # Applies pending Drizzle migrations before the new version starts. + - name: migrate + image: backend-migrate + imagePullPolicy: IfNotPresent + envFrom: + - configMapRef: + name: backend-config + - secretRef: + name: backend-secret + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: ["ALL"] + volumeMounts: + - name: tmp + mountPath: /tmp + resources: + requests: + cpu: "100m" + memory: "128Mi" + limits: + cpu: "500m" + memory: "512Mi" containers: - name: backend image: backend @@ -44,8 +69,12 @@ spec: name: backend-secret securityContext: allowPrivilegeEscalation: false + readOnlyRootFilesystem: true capabilities: drop: ["ALL"] + volumeMounts: + - name: tmp + mountPath: /tmp startupProbe: httpGet: path: /health/live @@ -76,3 +105,6 @@ spec: limits: cpu: "1000m" memory: "512Mi" + volumes: + - name: tmp + emptyDir: {} diff --git a/k8s/frontend-deployment.yaml b/k8s/frontend-deployment.yaml index 3538abc..4f19be9 100644 --- a/k8s/frontend-deployment.yaml +++ b/k8s/frontend-deployment.yaml @@ -19,6 +19,12 @@ spec: labels: app: frontend spec: + securityContext: + runAsNonRoot: true + runAsUser: 101 + runAsGroup: 101 + seccompProfile: + type: RuntimeDefault containers: - name: frontend image: frontend @@ -29,6 +35,16 @@ spec: protocol: TCP securityContext: allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: ["ALL"] + volumeMounts: + - name: nginx-cache + mountPath: /var/cache/nginx + - name: nginx-run + mountPath: /var/run + - name: tmp + mountPath: /tmp startupProbe: httpGet: path: / @@ -59,6 +75,13 @@ spec: limits: cpu: "250m" memory: "128Mi" + volumes: + - name: nginx-cache + emptyDir: {} + - name: nginx-run + emptyDir: {} + - name: tmp + emptyDir: {} --- apiVersion: v1 kind: Service diff --git a/k8s/kustomization.yaml b/k8s/kustomization.yaml index 4e7f22e..3e61e66 100644 --- a/k8s/kustomization.yaml +++ b/k8s/kustomization.yaml @@ -13,6 +13,7 @@ resources: - backend-deployment.yaml - backend-service.yaml - frontend-deployment.yaml + - pdb.yaml - ingress.yaml labels: diff --git a/k8s/pdb.yaml b/k8s/pdb.yaml new file mode 100644 index 0000000..51ddfda --- /dev/null +++ b/k8s/pdb.yaml @@ -0,0 +1,23 @@ +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: backend + labels: + app: backend +spec: + minAvailable: 1 + selector: + matchLabels: + app: backend +--- +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: frontend + labels: + app: frontend +spec: + minAvailable: 1 + selector: + matchLabels: + app: frontend diff --git a/scripts/restore.sh b/scripts/restore.sh index 43795d0..6a744dc 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -14,6 +14,11 @@ # from the backup came back, then drop it # --work-dir