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
This commit is contained in:
Stiftung Development
2025-09-06 20:48:53 +02:00
parent c8afaaba6a
commit 4acb5885e8

View File

@@ -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: