feat(ci): Ajoute contrôle de disponibilité PostgreSQL

Ajoute un contrôle de disponibilité pour PostgreSQL dans le workflow CI.
This commit is contained in:
Serreau Jovann
2025-07-17 10:02:24 +02:00
parent c909de180c
commit e881a552ca

View File

@@ -88,6 +88,7 @@ jobs:
run: |
docker rm -f vault-ci postgres-ci redis-ci || true
docker network rm ci-network || true
- name: Start services on Docker
run: |
docker network create ci-network
@@ -95,7 +96,40 @@ jobs:
docker run -d --rm --network ci-network -p 15432:5432 --name postgres-ci -e "POSTGRES_DB=symfony_user" -e "POSTGRES_USER=your_db_user" -e "POSTGRES_PASSWORD=app_db_test" postgres:16
docker run -d --rm --network ci-network -p 15433:6379 --name redis-ci redis:latest
echo "Waiting for services to be ready..."
sleep 15
# --- Add PostgreSQL readiness check ---
echo "Checking PostgreSQL readiness..."
# Loop until PostgreSQL is ready to accept connections
# We use the internal container name (postgres-ci) and port (5432)
# The pg_isready command checks if the server is accepting connections
# -h: host, -p: port, -U: user, -d: database
# PGPASSWORD is used to provide the password non-interactively
DB_HOST="127.0.0.1"
DB_PORT="15432"
DB_USER="your_db_user"
DB_NAME="symfony_user"
DB_PASSWORD="app_db_test" # Use the actual password
# Install postgresql-client if pg_isready is not available in the runner image
# This is a common requirement for `pg_isready`
apt-get update && apt-get install -y postgresql-client || true # Install client tools, ignore if already installed
for i in $(seq 1 30); do # Try for up to 30 seconds (30 * 1 second sleep)
PGPASSWORD=$DB_PASSWORD pg_isready -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME
if [ $? -eq 0 ]; then
echo "PostgreSQL is ready!"
break
fi
echo "PostgreSQL not ready yet. Waiting..."
sleep 1
done
PGPASSWORD=$DB_PASSWORD pg_isready -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME
if [ $? -ne 0 ]; then
echo "PostgreSQL did not become ready in time. Exiting."
exit 1
fi
# --- End PostgreSQL readiness check ---
docker ps
- name: Setup PHP for testing