File tree Expand file tree Collapse file tree 3 files changed +34
-17
lines changed Expand file tree Collapse file tree 3 files changed +34
-17
lines changed Original file line number Diff line number Diff line change @@ -7,31 +7,35 @@ services:
7
7
environment :
8
8
POSTGRES_USER : " ${POSTGRES_USER}"
9
9
POSTGRES_PASSWORD : " ${POSTGRES_PASSWORD}"
10
- POSTGRES_DB : " ${POSTGRES_DB}"
10
+ POSTGRES_DB : ${POSTGRES_DB}
11
11
volumes :
12
12
- ./docker_test_db:/var/lib/postgresql/data
13
+ healthcheck :
14
+ test : ["CMD-SHELL", "sh -c 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}'"]
15
+ interval : 5s
16
+ timeout : 60s
17
+ retries : 5
18
+ start_period : 80s
13
19
server :
14
20
container_name : server
15
21
build :
16
22
context : ./server
17
23
dockerfile : Dockerfile
18
- # command: npm start
19
24
ports :
20
25
- " 7999:8000"
26
+ command : bash -c "npx prisma migrate dev && npx prisma db seed && npm start"
21
27
environment :
22
28
DATABASE_URL : " ${DATABASE_URL}"
23
29
PORT : " ${PORT}"
24
30
depends_on :
25
- - postgres
31
+ postgres :
32
+ condition : service_healthy
26
33
client :
27
34
container_name : client
28
35
build :
29
36
context : ./client
30
37
dockerfile : Dockerfile
31
- # command: npm start
32
38
ports :
33
39
- " 4174:4173"
34
- # environment:
35
- # VITE_SERVER_URL: "${VITE_SERVER_URL}"
36
40
depends_on :
37
41
- server
Original file line number Diff line number Diff line change 1
1
FROM node:18
2
+ ARG DATABASE_URL="postgresql://john_doe:john.doe@postgres:5432/docker_test_db?schema=public"
3
+ ENV DATABASE_URL=$DATABASE_URL
2
4
WORKDIR /server
3
5
COPY package.json ./
4
6
COPY package-lock.json ./
5
7
COPY . .
6
8
RUN npm install
7
- RUN npx prisma generate
8
- CMD ["npm" , "start" ]
9
+ RUN npx prisma generate
Original file line number Diff line number Diff line change @@ -408,12 +408,24 @@ async function main() {
408
408
} ) ;
409
409
}
410
410
411
- main ( )
412
- . then ( async ( ) => {
413
- await prisma . $disconnect ( ) ;
414
- } )
415
- . catch ( async ( e ) => {
416
- console . error ( e ) ;
417
- await prisma . $disconnect ( ) ;
418
- process . exit ( 1 ) ;
419
- } ) ;
411
+ async function init ( ) {
412
+ const users = await prisma . user . count ( ) ;
413
+
414
+ console . log ( users )
415
+
416
+ if ( users === 0 ) {
417
+ main ( )
418
+ . then ( async ( ) => {
419
+ await prisma . $disconnect ( ) ;
420
+ } )
421
+ . catch ( async ( e ) => {
422
+ console . error ( e ) ;
423
+ await prisma . $disconnect ( ) ;
424
+ process . exit ( 1 ) ;
425
+ } ) ;
426
+ } else {
427
+ console . log ( "Database seeding is not needed" ) ;
428
+ }
429
+ }
430
+
431
+ init ( )
You can’t perform that action at this time.
0 commit comments