Skip to content

Commit

Permalink
Added wait script to ping mySQL db container until it's up
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinyanakiev committed Sep 7, 2020
1 parent 6fb648f commit 705d90f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .env.default
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
DATABASE_HOST=localhost
MYSQL_DATABASE=cherrytwist
MYSQL_ROOT_PASSWORD=toor
MYSQL_ROOT_PASSWORD=toor
WAIT_HOSTS=localhost:3306
WAIT_HOSTS_TIMEOUT=300
WAIT_SLEEP_INTERVAL=30
WAIT_HOST_CONNECT_TIMEOUT=30

COMPOSE_PROJECT_NAME=cherrytwist-server
4 changes: 4 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
DATABASE_HOST=db
MYSQL_DATABASE=cherrytwist
MYSQL_ROOT_PASSWORD=toor
WAIT_HOSTS=db:3306
WAIT_HOSTS_TIMEOUT=300
WAIT_SLEEP_INTERVAL=30
WAIT_HOST_CONNECT_TIMEOUT=30

COMPOSE_PROJECT_NAME=cherrytwist-server
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ RUN npm install
COPY ./src ./src
COPY ./tsconfig.json .

## Add the wait script to the image
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.7.3/wait /wait
RUN chmod +x /wait

EXPOSE 4000
CMD [ "npm", "start" ]
6 changes: 5 additions & 1 deletion docker-compose.debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ services:
- DATABASE_HOST
- MYSQL_ROOT_PASSWORD
- MYSQL_DATABASE
- WAIT_HOSTS
- WAIT_HOSTS_TIMEOUT
- WAIT_SLEEP_INTERVAL
- WAIT_HOST_CONNECT_TIMEOUT
depends_on:
- db
restart: always
ports:
- 4000:4000
- 9330:9330
command: ["npm", "--inspect=0.0.0.0:9330", "start"]
command: sh -c "/wait && npm --inspect=0.0.0.0:9330 start"
db:
image: mysql:8.0.11
networks:
Expand Down
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ services:
- DATABASE_HOST
- MYSQL_ROOT_PASSWORD
- MYSQL_DATABASE
- WAIT_HOSTS
- WAIT_HOSTS_TIMEOUT
- WAIT_SLEEP_INTERVAL
- WAIT_HOST_CONNECT_TIMEOUT
depends_on:
- db
restart: always
ports:
- 4000:4000
command: ["npm", "start"]
command: sh -c "/wait && npm start"
db:
container_name: ct_server_db
image: mysql:8.0.11
Expand Down

0 comments on commit 705d90f

Please sign in to comment.