Skip to content

Commit

Permalink
Merge pull request #300 from silinternational/feature/healthcheck
Browse files Browse the repository at this point in the history
replace whenavail with healthcheck
  • Loading branch information
briskt authored Dec 11, 2024
2 parents 951dd0e + d3aed99 commit 5fd5b6f
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 49 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ upDb:
docker compose up -d db

yiimigrate:
docker compose run --rm cli whenavail db 3306 100 ./yii migrate --interactive=0
docker compose run --rm cli ./yii migrate --interactive=0

yiimigratelocal:
docker compose run --rm cli whenavail db 3306 100 ./yii migrate --migrationPath=console/migrations-local/ --interactive=0
docker compose run --rm cli ./yii migrate --migrationPath=console/migrations-local/ --interactive=0

basemodels:
docker compose run --rm cli whenavail db 3306 100 ./rebuildbasemodels.sh
docker compose run --rm cli ./rebuildbasemodels.sh

yiimigratetestDb:
docker compose run --rm cli bash -c 'MYSQL_HOST=testDb MYSQL_DATABASE=test whenavail testDb 3306 100 ./yii migrate --interactive=0'
docker compose run --rm cli bash -c 'MYSQL_HOST=testDb MYSQL_DATABASE=test ./yii migrate --interactive=0'

yiimigratetestDblocal:
docker compose run --rm cli bash -c 'MYSQL_HOST=testDb MYSQL_DATABASE=test whenavail testDb 3306 100 ./yii migrate --migrationPath=console/migrations-test/ --interactive=0'
docker compose run --rm cli bash -c 'MYSQL_HOST=testDb MYSQL_DATABASE=test ./yii migrate --migrationPath=console/migrations-test/ --interactive=0'

rmTestDb:
docker compose kill testDb
Expand Down
40 changes: 34 additions & 6 deletions actions-services.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
x-db_healthcheck: &db_healthcheck
healthcheck:
test: [ "CMD", "healthcheck.sh", "--connect", "--innodb_initialized" ]
start_period: 10s
interval: 10s
timeout: 5s
retries: 3

services:
db:
image: mariadb:10
Expand All @@ -6,6 +14,7 @@ services:
MYSQL_DATABASE: test
MYSQL_USER: idpmgmt
MYSQL_PASSWORD: idpmgmt
<<: *db_healthcheck

zxcvbn:
image: wcjr/zxcvbn-api:1.1.0
Expand All @@ -15,10 +24,14 @@ services:
app:
build: .
depends_on:
- db
- zxcvbn
- broker
# - ldapload
db:
condition: service_healthy
zxcvbn:
condition: service_started
broker:
condition: service_healthy
# ldapload:
# condition: service_started
environment:
MYSQL_HOST: db
MYSQL_DATABASE: test
Expand Down Expand Up @@ -55,11 +68,13 @@ services:
MYSQL_DATABASE: app
MYSQL_USER: user
MYSQL_PASSWORD: pass
<<: *db_healthcheck

broker:
image: silintl/idp-id-broker:6
depends_on:
- brokerDb
brokerDb:
condition: service_healthy
volumes:
- ./dockerbuild/broker/run-broker.sh:/data/run-broker.sh
- ./dockerbuild/broker/m381901_235959_insert_test_data.php:/data/console/migrations/m381901_235959_insert_test_data.php
Expand Down Expand Up @@ -90,15 +105,28 @@ services:
MFA_WEBAUTHN_apiKey: not_needed_here
MFA_WEBAUTHN_apiSecret: not_needed_here
command: ./run-broker.sh
healthcheck:
test: nc -vz localhost 80
start_period: 1s
interval: 5s
timeout: 1s
retries: 30

ldap:
build: ./dockerbuild/ldap
environment:
DEBUG_LEVEL: 320
healthcheck:
test: nc -vz localhost 389
start_period: 1s
interval: 5s
timeout: 1s
retries: 90

ldapload:
build: ./dockerbuild/ldap
depends_on:
- ldap
ldap:
condition: service_healthy
working_dir: /data
command: ./load_ldap.sh
3 changes: 1 addition & 2 deletions application/run-tests-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ composer install --prefer-dist --no-interaction --optimize-autoloader --no-progr
mkdir -p /data/runtime/mail

# Run database migrations
whenavail ${MYSQL_HOST} 3306 100 /data/yii migrate --interactive=0
/data/yii migrate --interactive=0

# Start apache
apache2ctl start

# Run codeception tests
whenavail broker 80 100 echo "broker ready"
/data/vendor/bin/codecept run api -d
TESTRESULTS_API=$?

Expand Down
3 changes: 1 addition & 2 deletions application/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ composer install --prefer-dist --no-interaction --optimize-autoloader --no-progr
mkdir -p /data/runtime/mail

# Run database migrations
whenavail ${MYSQL_HOST} 3306 100 /data/yii migrate --interactive=0
/data/yii migrate --interactive=0

# Install and enable xdebug for code coverage
apt-get update && apt-get install -y php-xdebug

# Run codeception tests
whenavail broker 80 100 echo "broker ready, running unit tests..."
./vendor/bin/codecept run unit

# Run local behat tests
Expand Down
67 changes: 53 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
x-db_healthcheck: &db_healthcheck
healthcheck:
test: [ "CMD", "healthcheck.sh", "--connect", "--innodb_initialized" ]
start_period: 10s
interval: 10s
timeout: 5s
retries: 3

services:

db:
Expand All @@ -7,6 +15,7 @@ services:
MYSQL_DATABASE: pwmgr
MYSQL_USER: idpmgmt
MYSQL_PASSWORD: idpmgmt
<<: *db_healthcheck

testDb:
image: mariadb:10
Expand All @@ -15,6 +24,7 @@ services:
MYSQL_DATABASE: test
MYSQL_USER: idpmgmt
MYSQL_PASSWORD: idpmgmt
<<: *db_healthcheck

phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
Expand All @@ -32,8 +42,10 @@ services:
ports:
- "51155:80"
depends_on:
- db
- email
db:
condition: service_healthy
email:
condition: service_started
env_file:
- ./common.env
- ./local.env
Expand All @@ -43,9 +55,12 @@ services:
volumes:
- ./application:/data
depends_on:
- testDb
- zxcvbn
- broker
testDb:
condition: service_healthy
zxcvbn:
condition: service_started
broker:
condition: service_healthy
env_file:
- ./common.env
- ./test.env
Expand All @@ -62,8 +77,10 @@ services:
- ./application:/data
- ./dockerbuild/dev-ldap.conf:/etc/ldap/ldap.conf
depends_on:
- testDb
- zxcvbn
db:
condition: service_healthy
zxcvbn:
condition: service_started
env_file:
- ./common.env
- ./test.env
Expand All @@ -80,8 +97,10 @@ services:
- ./application:/data
- ./dockerbuild/dev-ldap.conf:/etc/ldap/ldap.conf
depends_on:
- testDb
- zxcvbn
testDb:
condition: service_healthy
zxcvbn:
condition: service_started
env_file:
- ./common.env
- ./test.env
Expand All @@ -98,6 +117,9 @@ services:
volumes:
- ./application:/data
- ${COMPOSER_CACHE_DIR}:/composer
depends_on:
testDb:
condition: service_healthy
working_dir: /data
user: "${DOCKER_UIDGID}"
env_file:
Expand All @@ -108,8 +130,12 @@ services:
email:
image: silintl/email-service:1
depends_on:
- emaildb
- emailcron
emaildb:
condition: service_healthy
emailcron:
condition: service_started
environment:
MYSQL_HOST: emaildb
env_file:
- ./email.common.env
- ./email.local.env
Expand All @@ -119,7 +145,10 @@ services:
emailcron:
image: silintl/email-service:1
depends_on:
- emaildb
emaildb:
condition: service_healthy
environment:
MYSQL_HOST: emaildb
env_file:
- ./email.common.env
- ./email.local.env
Expand All @@ -131,6 +160,7 @@ services:
- ./email.common.env
environment:
MYSQL_ROOT_PASSWORD: not-a-secret
<<: *db_healthcheck

emailpma:
image: phpmyadmin/phpmyadmin:latest
Expand All @@ -151,6 +181,7 @@ services:
MYSQL_DATABASE: broker
MYSQL_USER: broker
MYSQL_PASSWORD: broker
<<: *db_healthcheck

brokerpma:
image: phpmyadmin/phpmyadmin:latest
Expand All @@ -166,7 +197,8 @@ services:
ports:
- "51154:80"
depends_on:
- brokerDb
brokerDb:
condition: service_healthy
volumes:
- ./dockerbuild/broker/run-broker.sh:/data/run-broker.sh
- ./dockerbuild/broker/m381901_235959_insert_test_data.php:/data/console/migrations/m381901_235959_insert_test_data.php
Expand Down Expand Up @@ -200,11 +232,18 @@ services:

ldap:
build: ./dockerbuild/ldap
healthcheck:
test: nc -vz localhost 389
start_period: 1s
interval: 1s
timeout: 5s
retries: 90

ldapload:
build: ./dockerbuild/ldap
depends_on:
- ldap
ldap:
condition: service_healthy
working_dir: /data
command: ./load_ldap.sh

Expand Down
2 changes: 1 addition & 1 deletion dockerbuild/broker/run-broker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ composer install --no-interaction --no-scripts --no-progress
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi

# Try to run database migrations
whenavail $MYSQL_HOST 3306 100 ./yii migrate --interactive=0
./yii migrate --interactive=0

# If that failed, exit.
rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
Expand Down
18 changes: 0 additions & 18 deletions dockerbuild/ldap/load_ldap.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
#!/bin/bash

# Simple replication of whenavail script
TIMEOUT=10;

while true; do
if nc -z -v ldap 389; then
break
fi

if [[ $TIMEOUT == 0 ]]; then
exit 42
else
TIMEOUT=$(( $TIMEOUT-1 ))
fi

sleep 1
done


ldapadd -h ldap -p 389 -f /root/fakerep.ldif -x -c -D 'cn=Manager,dc=acme,dc=org' -w admin
ldapadd -h ldap -p 389 -f /root/fakepeople.ldif -x -c -D 'cn=Manager,dc=acme,dc=org' -w admin
1 change: 0 additions & 1 deletion email.common.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ MAILER_HOST=dummy
MAILER_USERNAME=dummy
MAILER_PASSWORD=dummy

MYSQL_HOST=emaildb
MYSQL_DATABASE=email
MYSQL_USER=email
MYSQL_PASSWORD=email

0 comments on commit 5fd5b6f

Please sign in to comment.