From 4acb5885e85c96b8793b14faf0bc39998f1d38a8 Mon Sep 17 00:00:00 2001 From: Stiftung Development Date: Sat, 6 Sep 2025 20:48:53 +0200 Subject: [PATCH] fix: resolve CI database connection issues - Fix .env file location for Django in CI (app/.env instead of .env) - Add PostgreSQL client tools installation - Add proper PostgreSQL service configuration with ports - Add Redis port mapping for proper service access - Add wait step to ensure PostgreSQL is ready before migrations - Fix environment variable handling in GitHub Actions --- .github/workflows/ci-cd.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 2f7cac2..ddeacb5 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -18,8 +18,11 @@ jobs: postgres: image: postgres:15 env: + POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: test_stiftung + ports: + - 5432:5432 options: >- --health-cmd pg_isready --health-interval 10s @@ -28,6 +31,8 @@ jobs: redis: image: redis:7-alpine + ports: + - 6379:6379 options: >- --health-cmd "redis-cli ping" --health-interval 10s @@ -52,12 +57,15 @@ jobs: - name: Install dependencies run: | + sudo apt-get update + sudo apt-get install -y postgresql-client python -m pip install --upgrade pip pip install -r app/requirements.txt - name: Set up environment run: | - cp env-template.txt .env + cp env-template.txt app/.env + cd app echo "DJANGO_DEBUG=1" >> .env echo "DJANGO_SECRET_KEY=test-secret-key-for-ci" >> .env echo "POSTGRES_DB=test_stiftung" >> .env @@ -67,6 +75,14 @@ jobs: echo "DB_PORT=5432" >> .env echo "REDIS_URL=redis://localhost:6379/0" >> .env + - name: Wait for PostgreSQL + run: | + while ! pg_isready -h localhost -p 5432 -U postgres; do + echo "Waiting for PostgreSQL..." + sleep 2 + done + echo "PostgreSQL is ready!" + - name: Run migrations working-directory: ./app env: