From b206a71909e1e4ab9a84d1cbb1f989585187c909 Mon Sep 17 00:00:00 2001 From: ITQ Date: Wed, 28 Feb 2024 00:14:23 +0300 Subject: [PATCH] Fixed getting creditionals for postgre from env --- solution/.dockerignore | 2 ++ solution/.gitignore | 2 ++ solution/Dockerfile | 4 ++-- solution/pulse/pulse/settings.py | 28 ++++++++++++++++++++++------ solution/template.env | 6 ++++++ 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/solution/.dockerignore b/solution/.dockerignore index 9e66e35..26efb71 100644 --- a/solution/.dockerignore +++ b/solution/.dockerignore @@ -1,5 +1,7 @@ .dockerignore Dockerfile README.md +ruff.toml venv/ __pycache__/ +.ruff_cache/ diff --git a/solution/.gitignore b/solution/.gitignore index 68bc17f..ec0f3da 100644 --- a/solution/.gitignore +++ b/solution/.gitignore @@ -158,3 +158,5 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +static/ diff --git a/solution/Dockerfile b/solution/Dockerfile index 98f466f..9fab785 100644 --- a/solution/Dockerfile +++ b/solution/Dockerfile @@ -4,8 +4,8 @@ WORKDIR /app ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 -ENV SERVER_PORT = 8080 -ENV DJANGO_DEBUG = False +ENV SERVER_PORT=8080 +ENV DJANGO_DEBUG=False RUN pip3 install --upgrade pip COPY requirements/prod.txt . diff --git a/solution/pulse/pulse/settings.py b/solution/pulse/pulse/settings.py index 62a52a8..f1b8a02 100644 --- a/solution/pulse/pulse/settings.py +++ b/solution/pulse/pulse/settings.py @@ -63,12 +63,26 @@ WSGI_APPLICATION = "pulse.wsgi.application" POSTGRES_CONN = os.getenv("POSTGRES_CONN") -DATABASES = { - "default": { - "ENGINE": "django.db.backends.postgresql", - **dj_database_url.parse(POSTGRES_CONN), - }, -} +POSTGRES_JDBC_URL = os.getenv("POSTGRES_JDBC_URL") + +if POSTGRES_CONN: + DATABASES = { + "default": { + "ENGINE": "django.db.backends.postgresql", + **dj_database_url.parse(POSTGRES_CONN), + }, + } +else: + DATABASES = { + "default": { + "ENGINE": "django.db.backends.postgresql", + "NAME": os.getenv("POSTGRES_DATABASE"), + "USER": os.getenv("POSTGRES_USERNAME"), + "PASSWORD": os.getenv("POSTGRES_PASSWORD"), + "HOST": os.getenv("POSTGRES_HOST"), + "PORT": os.getenv("POSTGRES_PORT"), + }, + } AUTH_PASSWORD_VALIDATORS = [ { @@ -104,6 +118,8 @@ USE_TZ = True STATIC_URL = "static/" +STATIC_ROOT = BASE_DIR / "static" + DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" REST_FRAMEWORK = { diff --git a/solution/template.env b/solution/template.env index 7170c0a..f999772 100644 --- a/solution/template.env +++ b/solution/template.env @@ -3,3 +3,9 @@ SECRET_KEY = secret_key DJANGO_ALLOWED_HOSTS = 127.0.0.1 INTERNAL_IPS = 127.0.0.1 POSTGRES_CONN = postgres://login:pass@localhost:5432/postgres +POSTGRES_JDBC_URL = jdbc:postgresql://host:port/dbname +POSTGRES_USERNAME = postgres +POSTGRES_PASSWORD = password +POSTGRES_HOST = localhost +POSTGRES_PORT = 5432 +POSTGRES_DATABASE = postgres