Skip to content

Commit 23ed9fd

Browse files
committed
Add health checks for the sample app databases
1 parent 208bd83 commit 23ed9fd

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

sample-apps/common.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dev: check-zen-go
1919
@PORT=$(PORT) go run -toolexec="$(ZENGO) toolexec" .
2020

2121
start-database:
22-
@cd ../databases/ && docker compose up $(DB_SERVICE) -d
22+
@cd ../databases/ && docker compose up $(DB_SERVICE) -d --wait
2323

2424
stop-database:
2525
@cd ../databases/ && docker compose down

sample-apps/databases/docker-compose.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ services:
66
volumes:
77
- postgres_db_data:/var/lib/postgresql/data
88
- ./postgres_init.sql:/docker-entrypoint-initdb.d/init.sql
9-
109
environment:
1110
POSTGRES_DB: "db"
1211
POSTGRES_USER: "user"
1312
POSTGRES_PASSWORD: "password"
1413
ports:
1514
- "5432:5432"
15+
healthcheck:
16+
test: ["CMD-SHELL", "pg_isready -U user -d db"]
17+
interval: 1s
18+
timeout: 5s
19+
retries: 30
1620
mysql_database:
1721
image: mysql
1822
container_name: sample_mysql_db
@@ -28,6 +32,11 @@ services:
2832
ports:
2933
- "3306:3306"
3034
command: --init-file /data/application/init.sql
35+
healthcheck:
36+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "user", "-ppassword"]
37+
interval: 1s
38+
timeout: 5s
39+
retries: 30
3140
mssql_database:
3241
build: ./mssql_database
3342
container_name: sample_mssql_db
@@ -39,6 +48,11 @@ services:
3948
- "1433:1433"
4049
volumes:
4150
- mssql_db_data:/var/opt/mssql
51+
healthcheck:
52+
test: ["CMD-SHELL", "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'Strong!Passw0rd' -Q 'SELECT 1' -b -o /dev/null"]
53+
interval: 1s
54+
timeout: 5s
55+
retries: 30
4256

4357
volumes:
4458
postgres_db_data:

0 commit comments

Comments
 (0)