Skip to content

Commit bd1a92d

Browse files
committed
Improve service startup reliability and DB readiness checks
Adds healthcheck to the database service in docker-compose and ensures the web service waits for the database to be healthy before starting. Updates script.sh to wait for the database to be ready before proceeding. Enhances the Cypress workflow to retry DXCC population for improved test reliability.
1 parent ca5df78 commit bd1a92d

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

.github/workflows/cypress-tests.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ jobs:
5959
done
6060
6161
- name: Populate dxcc_entities table
62-
run: curl "http://localhost/index.php/update/dxcc"
62+
run: |
63+
for i in `seq 1 10`; do
64+
if curl -f "http://localhost/index.php/update/dxcc"; then
65+
echo "DXCC entities populated successfully"
66+
break
67+
else
68+
echo "Failed to populate DXCC entities, retrying in 10 seconds... (attempt $i/10)"
69+
sleep 10
70+
fi
71+
done
6372
6473
- name: Run Cypress tests
6574
run: npx cypress run

docker-compose.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ services:
1414
- ./:/var/www/html:rw
1515
command: ["./script.sh"]
1616
depends_on:
17-
- db
17+
db:
18+
condition: service_healthy
1819
networks:
1920
- mynet
2021

@@ -28,5 +29,12 @@ services:
2829
- db_data:/var/lib/mysql
2930
networks:
3031
- mynet
32+
healthcheck:
33+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
34+
timeout: 20s
35+
retries: 10
36+
interval: 10s
37+
start_period: 30s
38+
3139
volumes:
3240
db_data: {}

script.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ rm -rf /install
7979

8080
echo "Replacement complete."
8181

82+
# Wait for database to be ready
83+
echo "Waiting for database to be ready..."
84+
until mysql -h"$MYSQL_HOST" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -e "SELECT 1" > /dev/null 2>&1; do
85+
echo "Database is not ready yet. Waiting 5 seconds..."
86+
sleep 5
87+
done
88+
echo "Database is ready!"
89+
8290
# Set Permissions
8391
chown -R root:www-data /var/www/html/application/config/
8492
chown -R root:www-data /var/www/html/application/logs/

0 commit comments

Comments
 (0)