Skip to content

Commit

Permalink
Changing container start commands to use healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Dias committed Aug 24, 2020
1 parent 71a05dd commit edb3e95
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 45 deletions.
10 changes: 5 additions & 5 deletions Makefile
Expand Up @@ -69,15 +69,15 @@ compose-stop:

# start all containers
.PHONY: compose-up
compose-up:
@mkdir -p docker_data && docker-compose up -d
compose-up: dependencies/up
@docker-compose up william

# start only the dependency containers
.PHONY: dependencies/up
dependencies/up:
@mkdir -p docker_data && docker-compose up -d postgres oauth2-server
@until docker exec $(pg_docker_image) pg_isready; do echo 'Waiting Postgres...' && sleep 1; done
@until curl -sL "http://localhost:9000/.well-known/openid-configuration" -o /dev/null; do echo 'Waiting OAuth2 server...' && sleep 1; done
@until docker inspect --format "{{json .State.Health.Status }}" Will.IAM_postgres_1 | grep -q "healthy"; do echo 'Waiting Postgres...' && sleep 1; done
@until docker inspect --format "{{json .State.Health.Status }}" Will.IAM_oauth2_server_1 | grep -q "healthy"; do echo 'Waiting OAuth2 server...' && sleep 1; done
@sleep 2

.PHONY: db/setup
Expand All @@ -90,7 +90,7 @@ db/setup-test: db/up db/create-user db/create-test db/migrate-test
.PHONY: db/up
db/up:
@mkdir -p docker_data && docker-compose up -d postgres
@until docker exec $(pg_docker_image) pg_isready; do echo 'Waiting Postgres...' && sleep 1; done
@until docker inspect --format "{{json .State.Health.Status }}" Will.IAM_postgres_1 | grep -q "healthy"; do echo 'Waiting Postgres...' && sleep 1; done
@sleep 2

.PHONY: db/create-user
Expand Down
17 changes: 14 additions & 3 deletions docker-compose.yml
@@ -1,4 +1,4 @@
version: '2'
version: '3.4'
services:
william:
image: golang:1.13-alpine
Expand All @@ -14,13 +14,18 @@ services:
- WILLIAM_EXTENSIONS_PG_HOST=postgres
- WILLIAM_EXTENSIONS_PG_PORT=5432
container_name: Will.IAM_app_1
command: "sh -c 'chmod +x ./wait-for-it.sh && ./wait-for-it.sh postgres oauth2-server:9000 -- go mod download && make run'"
command: "sh -c 'apk add make && go mod download && make run'"
oauth2-server:
image: node:14.8
ports:
- 9000:9000
container_name: Will.IAM_oauth2_server_1
command: bash -c "npm install -g oauth2-mock-server && oauth2-mock-server -p 9000"
command: sh -c "npm install -g oauth2-mock-server && oauth2-mock-server -p 9000"
healthcheck:
test: ["CMD", "curl", "http://localhost:9000/.well-known/openid-configuration"]
interval: 1s
timeout: 10s
retries: 5
postgres:
image: postgres:9.6
ports:
Expand All @@ -34,3 +39,9 @@ services:
- "max_connections=9999"
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
healthcheck:
test: ["CMD", "pg_isready"]
interval: 1s
timeout: 10s
retries: 5

37 changes: 0 additions & 37 deletions wait-for-it.sh

This file was deleted.

0 comments on commit edb3e95

Please sign in to comment.