🔧 Fix Django 4.0+ CSRF_TRUSTED_ORIGINS and CI settings
Some checks failed
continuous-integration/drone/push Build is failing

 Fixed issues:
- Added proper CSRF_TRUSTED_ORIGINS with schemes (http://, https://)
- Added missing sys import in test settings
- Updated ALLOWED_HOSTS to include 'postgres' container
- Removed duplicate database creation in CI pipeline
- Fixed empty CSRF_TRUSTED_ORIGINS causing Django 4.0.E001 error

🐳 CI/CD improvements:
- Database container properly referenced in settings
- Test environment variables correctly configured
- Eliminated database creation conflicts

Ready for trusted repository CI/CD execution!
This commit is contained in:
2025-11-25 07:39:21 +09:00
parent 33f128d5c6
commit 3523b38e0b
2 changed files with 13 additions and 9 deletions

View File

@@ -60,7 +60,7 @@ steps:
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/smartsoltech_test DATABASE_URL: postgresql://postgres:postgres@postgres:5432/smartsoltech_test
SECRET_KEY: test-secret-key-for-ci-very-long-and-secure-key-12345 SECRET_KEY: test-secret-key-for-ci-very-long-and-secure-key-12345
DEBUG: "False" DEBUG: "False"
ALLOWED_HOSTS: localhost,127.0.0.1 ALLOWED_HOSTS: localhost,127.0.0.1,postgres
DJANGO_SETTINGS_MODULE: smartsoltech.settings_test DJANGO_SETTINGS_MODULE: smartsoltech.settings_test
commands: commands:
- apt-get update && apt-get install -y libpq-dev gcc curl postgresql-client - apt-get update && apt-get install -y libpq-dev gcc curl postgresql-client
@@ -70,8 +70,6 @@ steps:
- sleep 15 - sleep 15
- echo "Checking database connection..." - echo "Checking database connection..."
- until pg_isready -h postgres -p 5432 -U postgres; do echo "Waiting for postgres..."; sleep 2; done - until pg_isready -h postgres -p 5432 -U postgres; do echo "Waiting for postgres..."; sleep 2; done
- echo "Creating test database..."
- PGPASSWORD=postgres createdb -h postgres -U postgres smartsoltech_test || echo "Database already exists"
- echo "Checking migrations..." - echo "Checking migrations..."
- cd smartsoltech - cd smartsoltech
- python manage.py check --settings=smartsoltech.settings_test - python manage.py check --settings=smartsoltech.settings_test
@@ -87,7 +85,7 @@ steps:
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/smartsoltech_test DATABASE_URL: postgresql://postgres:postgres@postgres:5432/smartsoltech_test
SECRET_KEY: test-secret-key-for-ci-very-long-and-secure-key-12345 SECRET_KEY: test-secret-key-for-ci-very-long-and-secure-key-12345
DEBUG: "False" DEBUG: "False"
ALLOWED_HOSTS: localhost,127.0.0.1 ALLOWED_HOSTS: localhost,127.0.0.1,postgres
TELEGRAM_BOT_TOKEN: test-token-for-ci TELEGRAM_BOT_TOKEN: test-token-for-ci
DJANGO_SETTINGS_MODULE: smartsoltech.settings_test DJANGO_SETTINGS_MODULE: smartsoltech.settings_test
commands: commands:

View File

@@ -1,12 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
import sys
import dj_database_url import dj_database_url
from .settings import * from .settings import *
# Переопределяем настройки для CI/CD тестирования
print("ALLOWED_HOSTS:", ALLOWED_HOSTS)
print("CSRF_TRUSTED_ORIGINS:", CSRF_TRUSTED_ORIGINS)
print("🧪 Test settings loaded") print("🧪 Test settings loaded")
# База данных для тестирования # База данных для тестирования
@@ -14,7 +11,7 @@ DATABASES = {
'default': dj_database_url.config( 'default': dj_database_url.config(
default=os.environ.get( default=os.environ.get(
'DATABASE_URL', 'DATABASE_URL',
'postgresql://postgres:postgres@postgres_test:5432/smartsoltech_test' 'postgresql://postgres:postgres@postgres:5432/smartsoltech_test'
) )
) )
} }
@@ -33,6 +30,15 @@ DEBUG = os.environ.get('DEBUG', 'False').lower() in ['true', '1', 'yes']
# Разрешенные хосты для CI # Разрешенные хосты для CI
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', 'localhost,127.0.0.1,postgres,*').split(',') ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', 'localhost,127.0.0.1,postgres,*').split(',')
# CSRF настройки для тестирования
CSRF_TRUSTED_ORIGINS = [
'http://localhost',
'http://127.0.0.1',
'http://postgres',
'https://smartsoltech.kr'
]
print("🌐 Allowed hosts:", ALLOWED_HOSTS) print("🌐 Allowed hosts:", ALLOWED_HOSTS)
# Упрощенный хеширователь паролей для быстрых тестов # Упрощенный хеширователь паролей для быстрых тестов