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:
18
.github/workflows/ci-cd.yml
vendored
18
.github/workflows/ci-cd.yml
vendored
@@ -18,8 +18,11 @@ jobs:
|
|||||||
postgres:
|
postgres:
|
||||||
image: postgres:15
|
image: postgres:15
|
||||||
env:
|
env:
|
||||||
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_PASSWORD: postgres
|
POSTGRES_PASSWORD: postgres
|
||||||
POSTGRES_DB: test_stiftung
|
POSTGRES_DB: test_stiftung
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
options: >-
|
options: >-
|
||||||
--health-cmd pg_isready
|
--health-cmd pg_isready
|
||||||
--health-interval 10s
|
--health-interval 10s
|
||||||
@@ -28,6 +31,8 @@ jobs:
|
|||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis:7-alpine
|
image: redis:7-alpine
|
||||||
|
ports:
|
||||||
|
- 6379:6379
|
||||||
options: >-
|
options: >-
|
||||||
--health-cmd "redis-cli ping"
|
--health-cmd "redis-cli ping"
|
||||||
--health-interval 10s
|
--health-interval 10s
|
||||||
@@ -52,12 +57,15 @@ jobs:
|
|||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y postgresql-client
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install -r app/requirements.txt
|
pip install -r app/requirements.txt
|
||||||
|
|
||||||
- name: Set up environment
|
- name: Set up environment
|
||||||
run: |
|
run: |
|
||||||
cp env-template.txt .env
|
cp env-template.txt app/.env
|
||||||
|
cd app
|
||||||
echo "DJANGO_DEBUG=1" >> .env
|
echo "DJANGO_DEBUG=1" >> .env
|
||||||
echo "DJANGO_SECRET_KEY=test-secret-key-for-ci" >> .env
|
echo "DJANGO_SECRET_KEY=test-secret-key-for-ci" >> .env
|
||||||
echo "POSTGRES_DB=test_stiftung" >> .env
|
echo "POSTGRES_DB=test_stiftung" >> .env
|
||||||
@@ -67,6 +75,14 @@ jobs:
|
|||||||
echo "DB_PORT=5432" >> .env
|
echo "DB_PORT=5432" >> .env
|
||||||
echo "REDIS_URL=redis://localhost:6379/0" >> .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
|
- name: Run migrations
|
||||||
working-directory: ./app
|
working-directory: ./app
|
||||||
env:
|
env:
|
||||||
|
|||||||
Reference in New Issue
Block a user