Skip to content

Commit

Permalink
Fixed docker-compose.yml and changed ports
Browse files Browse the repository at this point in the history
  • Loading branch information
Shumer-1 committed Mar 9, 2025
1 parent 565a7ab commit 0263e53
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 124 deletions.
4 changes: 0 additions & 4 deletions .env.example

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/nosql1h25-gdwrapper.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

92 changes: 29 additions & 63 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,49 @@
Django settings for backend project.
Generated by 'django-admin startproject' using Django 3.2.12.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
import urllib.parse
from pathlib import Path
from os.path import join as path_join
from dotenv import dotenv_values

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
# Загружаем переменные окружения из файла .env (на уровне выше BASE_DIR)
config = dotenv_values(path_join(BASE_DIR.parent, ".env"))
SECRET_KEY = config["DJANGO_SECRET_KEY"]
ALLOWED_HOSTS = ['localhost', '0.0.0.0']

# SECURITY WARNING: don't run with debug turned on in production!
SECRET_KEY = config.get("DJANGO_SECRET_KEY")
ALLOWED_HOSTS = ['localhost', '0.0.0.0']
DEBUG = True

# Получаем переменные подключения к MongoDB
DB_NAME = config.get("DB_NAME")
DB_USER = config.get("DB_USER")
DB_PASSWORD = config.get("DB_PASSWORD")
DATABASE_HOST = config.get("DATABASE_HOST", "mongodb")
DATABASE_PORT = config.get("DATABASE_PORT", "27017")

# Application definition
# Экранируем пароль для корректного формирования URI
DB_PASSWORD_ENCODED = urllib.parse.quote_plus(DB_PASSWORD)

# Формируем строку подключения к MongoDB с указанием authSource=admin
MONGO_URI = f"mongodb://{DB_USER}:{DB_PASSWORD_ENCODED}@{DATABASE_HOST}:{DATABASE_PORT}/{DB_NAME}?authSource=admin"

DATABASES = {
'default': {
'ENGINE': 'djongo',
'CLIENT': {
'host': MONGO_URI,
}
}
}

# Остальные настройки (INSTALLED_APPS, MIDDLEWARE, TEMPLATES, WSGI_APPLICATION и т.д.)
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
Expand Down Expand Up @@ -71,65 +84,18 @@

WSGI_APPLICATION = 'backend.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': config.get("DB_NAME"),
'USER': config.get("DB_USER"),
'PASSWORD': config.get("DB_PASSWORD"),
'HOST': config.get("DATABASE_HOST", "db"),
'PORT': config.get("DATABASE_PORT", "5432"),
'CLIENT': {
'host': os.environ.get('MONGO_URI', 'mongodb://mongodb:27017/mydatabase'),
}
}
}



# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',},
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',},
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',},
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',},
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Empty file removed backend/db.sqlite3
Empty file.
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ services:
restart: always
env_file: .env
environment:
DB_NAME: ${DB_NAME}
DB_USER: ${DB_USER}
DATABASE_PORT: ${DB_PASSWORD}
MONGO_INITDB_ROOT_USERNAME: ${DB_USER}
MONGO_INITDB_ROOT_PASSWORD: ${DB_PASSWORD}
MONGO_INITDB_DATABASE: ${DB_NAME}
ports:
- "5432:5432"
- "27017:27017"
volumes:
- mongo-data:/data/db

Expand Down
6 changes: 6 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DB_NAME=...
DB_USER=...
DB_PASSWORD=...
DJANGO_SECRET_KEY=...
DATABASE_HOST=...
DATABASE_PORT=...

0 comments on commit 0263e53

Please sign in to comment.