Skip to content

Commit 5b7d06c

Browse files
authored
feat(deploy): orchestrate deployment readiness, decouple backend liveness, and fix PrismaPg (#2762)
1 parent 1876844 commit 5b7d06c

7 files changed

Lines changed: 55 additions & 20 deletions

File tree

backend/openshift.deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ objects:
199199
failureThreshold: 3
200200
livenessProbe:
201201
httpGet:
202-
path: /api/health
202+
path: /api
203203
port: http
204204
periodSeconds: 10
205205
failureThreshold: 3

backend/src/app.controller.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ describe('AppController', () => {
1616
})
1717

1818
describe('root', () => {
19-
it('should return "Hello Backend!"', () => {
20-
expect(appController.getHello()).toBe('Hello Backend!')
19+
it('should return "Backend is live!"', () => {
20+
expect(appController.getHello()).toBe('Backend is live!')
2121
})
2222
})
2323
})

backend/src/app.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common'
33
@Injectable()
44
export class AppService {
55
getHello(): string {
6-
return 'Hello Backend!'
6+
return 'Backend is live!'
77
}
88
}

backend/src/prisma.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class PrismaService extends PrismaClientWithLogs implements OnModuleInit, OnModu
2929
return PrismaService.instance
3030
}
3131
const pool = new Pool({ connectionString: dataSourceURL })
32-
const adapter = new PrismaPg(pool)
32+
const adapter = new PrismaPg(pool, { schema: DB_SCHEMA })
3333
super({
3434
adapter,
3535
errorFormat: 'pretty',

backend/test/app.e2e-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ describe('AppController (e2e)', () => {
1515
await app.init()
1616
})
1717

18-
it('/ (GET)', () => request(app.getHttpServer()).get('/').expect(200).expect('Hello Backend!'))
18+
it('/ (GET)', () => request(app.getHttpServer()).get('/').expect(200).expect('Backend is live!'))
1919
})

common/openshift.database.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ objects:
9494
readinessProbe:
9595
exec:
9696
command:
97-
- /usr/bin/env
98-
- bash
99-
- "-c"
100-
- psql -q -U $POSTGRES_USER -d $POSTGRES_DB -c 'SELECT 1'
97+
- pg_isready
98+
- -d
99+
- $(POSTGRES_DB)
100+
- -U
101+
- $(POSTGRES_USER)
101102
successThreshold: 1
102103
failureThreshold: 5
103104
initialDelaySeconds: 15
@@ -106,10 +107,11 @@ objects:
106107
livenessProbe:
107108
exec:
108109
command:
109-
- /usr/bin/env
110-
- bash
111-
- "-c"
112-
- psql -q -U $POSTGRES_USER -d $POSTGRES_DB -c 'SELECT 1'
110+
- pg_isready
111+
- -d
112+
- $(POSTGRES_DB)
113+
- -U
114+
- $(POSTGRES_USER)
113115
successThreshold: 1
114116
failureThreshold: 5
115117
initialDelaySeconds: 30

frontend/openshift.deploy.yml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,46 @@ objects:
6666
matchLabels:
6767
deployment: ${NAME}-${ZONE}-${COMPONENT}
6868
topologyKey: kubernetes.io/hostname
69+
initContainers:
70+
- name: wait-for-backend
71+
image: ${REGISTRY}/${ORG_NAME}/${NAME}/${COMPONENT}:${IMAGE_TAG}
72+
command:
73+
- /bin/sh
74+
- -c
75+
- |
76+
echo "Waiting for backend to be healthy..."
77+
max_retries=30
78+
attempt=1
79+
until wget -q --spider http://${NAME}-${ZONE}-backend/api/health; do
80+
if [ "$attempt" -ge "$max_retries" ]; then
81+
echo "ERROR: Backend ${NAME}-${ZONE}-backend is not reachable/healthy after ${max_retries} attempts." >&2
82+
exit 1
83+
fi
84+
echo "Backend not ready (attempt ${attempt}/${max_retries}), sleeping..."
85+
attempt=$((attempt + 1))
86+
sleep 2
87+
done
88+
echo "Backend is UP and healthy!"
89+
securityContext:
90+
allowPrivilegeEscalation: false
91+
runAsNonRoot: true
92+
readOnlyRootFilesystem: true
93+
capabilities:
94+
drop: ["ALL"]
95+
seccompProfile:
96+
type: RuntimeDefault
97+
volumeMounts:
98+
- name: caddy-data
99+
mountPath: /tmp/caddy
69100
containers:
70101
- name: ${NAME}
71102
image: ${REGISTRY}/${ORG_NAME}/${NAME}/${COMPONENT}:${IMAGE_TAG}
72103
imagePullPolicy: Always
73104
ports:
74105
- name: http
75106
containerPort: 3000
107+
- name: health
108+
containerPort: 3001
76109
env:
77110
- name: LOG_LEVEL
78111
value: ${LOG_LEVEL}
@@ -109,20 +142,20 @@ objects:
109142
mountPath: /tmp/coraza
110143
startupProbe:
111144
httpGet:
112-
path: /
113-
port: http
145+
path: /health
146+
port: health
114147
periodSeconds: 5
115148
failureThreshold: 30
116149
readinessProbe:
117150
httpGet:
118-
path: /
119-
port: http
151+
path: /health
152+
port: health
120153
periodSeconds: 5
121154
failureThreshold: 3
122155
livenessProbe:
123156
httpGet:
124-
path: /
125-
port: http
157+
path: /health
158+
port: health
126159
periodSeconds: 10
127160
failureThreshold: 3
128161
lifecycle:

0 commit comments

Comments
 (0)