Skip to content

Commit 3485ad3

Browse files
committed
Updared docker file
1 parent 8883ae3 commit 3485ad3

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

docker-compose.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
version: '3'
22
services:
3+
postgres:
4+
image: postgres
5+
ports:
6+
- "5432:5432"
7+
environment:
8+
POSTGRES_USER: postgres
9+
POSTGRES_PASSWORD: postgres
10+
POSTGRES_DB: ecosync
11+
312
frontend:
413
build:
514
context: ./client
@@ -23,11 +32,3 @@ services:
2332
env_file:
2433
- .env
2534

26-
postgres:
27-
image: postgres
28-
ports:
29-
- "5432:5432"
30-
environment:
31-
POSTGRES_USER: postgres
32-
POSTGRES_PASSWORD: postgres
33-
POSTGRES_DB: ecosync

server/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ WORKDIR /usr/src/app
55

66
COPY package*.json ./
77

8-
RUN npm install
8+
RUN apt-get update && apt-get install -y postgresql-client
99

1010
COPY . .
1111

1212
EXPOSE 8585
1313

14-
CMD ["npx", "nodemon"]
14+
CMD ["sh", "-c", "until pg_isready -h postgres -p 5432; do sleep 1; done && npm i && npm run dev"]
15+
# CMD ["npx", "nodemon"]

server/wait-for.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
host="$1"
6+
shift
7+
cmd="$@"
8+
9+
# Wait for PostgreSQL to be ready
10+
until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$host" -U postgres -d ecosync -c '\q'; do
11+
>&2 echo "PostgreSQL is unavailable - sleeping"
12+
sleep 1
13+
done
14+
15+
>&2 echo "PostgreSQL is up - executing command"
16+
exec $cmd

0 commit comments

Comments
 (0)