Skip to content

Commit 26291e7

Browse files
authored
Merge pull request #5 from ResEmCode/infra/docker-nginx
infra: create prisma migrate bash script and healthcheck
2 parents 8b7fb52 + 2c2fd47 commit 26291e7

File tree

6 files changed

+565
-14
lines changed

6 files changed

+565
-14
lines changed

infra/docker-compose.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11

22
services:
33
postgres:
4-
image: postgres:15-alpine
4+
image: postgres:17-alpine
55
container_name: postgres
66
restart: always
77
env_file:
88
- .env
9+
healthcheck:
10+
test: [ "CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB" ]
11+
interval: 5s
12+
timeout: 5s
13+
retries: 5
914
volumes:
1015
- postgres:/var/lib/postgresql/data
1116
networks:
@@ -21,7 +26,8 @@ services:
2126
ports:
2227
- "3001:3000"
2328
depends_on:
24-
- postgres
29+
postgres:
30+
condition: service_healthy
2531
networks:
2632
- app-network
2733

server/Dockerfile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11

2-
FROM node:20-alpine as builder
2+
FROM node:22-alpine as builder
33

44
WORKDIR /app
55

66
COPY package*.json ./
7-
COPY prisma ./prisma/
8-
9-
10-
RUN npm ci && npx prisma generate
7+
RUN npm ci
118

129
COPY . .
1310

11+
RUN npx prisma generate
12+
1413

1514
RUN npm run build && npm cache clean --force
1615

17-
FROM node:20-alpine
16+
FROM node:22-alpine
1817

1918
WORKDIR /app
2019

20+
COPY --chown=node:node docker/entrypoint.sh ./entrypoint.sh
21+
RUN chmod +x ./entrypoint.sh
22+
2123
COPY --from=builder --chown=node:node /app/node_modules ./node_modules
2224
COPY --from=builder --chown=node:node /app/package*.json ./
2325
COPY --from=builder --chown=node:node /app/dist ./dist
2426
COPY --from=builder --chown=node:node /app/prisma ./prisma
2527

28+
29+
COPY --from=builder --chown=node:node /app/prisma.config.ts ./
30+
2631
USER node
2732

2833
EXPOSE 3000
2934

30-
CMD ["node", "dist/src/main"]
35+
ENTRYPOINT ["./entrypoint.sh"]

server/docker/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
set -e
3+
4+
echo "[DEBUG] Waiting for postgres (sleeping 5s)..."
5+
sleep 5
6+
7+
echo "[DEBUG] Start prisma migration"
8+
npx prisma migrate deploy
9+
10+
echo "[DEBUG] Starting application..."
11+
exec node dist/src/main.js

0 commit comments

Comments
 (0)