Skip to content

Master #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion 01_docker_compose/simple_project/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM python:3.10
#pull oficial image
FROM python:latest

# set work directory
RUN mkdir /opt/app
WORKDIR /opt/app

ENV PYTHONDONTWRITEBYTECODE 1
Expand All @@ -13,6 +16,10 @@ COPY run_uwsgi.sh run_uwsgi.sh
COPY requirements.txt requirements.txt
COPY uwsgi/uwsgi.ini uwsgi.ini

# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev

RUN mkdir -p /var/www/static/ \
&& mkdir -p /var/www/media/ \
&& mkdir -p /opt/app/static/ \
Expand Down
7 changes: 7 additions & 0 deletions 01_docker_compose/simple_project/app/example/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DB_NAME=movies_database
DB_USER=app
DB_PASSWORD=123qwe

SECRET_KEY = 'django-insecure-@k04vsjy@qv3m573&94kgq_kjj@lad^^d%hr_o2sk!a6+c3ne9'

DEBUG = True
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get('DB_NAME'),
'USER': os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('DB_PASSWORD'),
'HOST': os.environ.get('DB_HOST', '127.0.0.1'),
'PORT': os.environ.get('DB_PORT', 5432),
'OPTIONS': {
# Нужно явно указать схемы, с которыми будет работать приложение.
'options': '-c search_path=public,content'
}
}
}
34 changes: 12 additions & 22 deletions 01_docker_compose/simple_project/app/example/settings.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
"""
Django settings for example project.

Generated by 'django-admin startproject' using Django 4.0.4.

For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
import os

from pathlib import Path
from dotenv import load_dotenv
from split_settings.tools import include

load_dotenv()

# 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/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-@k04vsjy@qv3m573&94kgq_kjj@lad^^d%hr_o2sk!a6+c3ne9'
SECRET_KEY = os.environ.get('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = os.environ.get('DEBUG', False) == 'True'

ALLOWED_HOSTS = ['localhost', '127.0.0.1', '[::1]']

Expand Down Expand Up @@ -74,12 +67,10 @@
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
include(
'components/database.py',
)



# Password validation
Expand All @@ -100,11 +91,10 @@
},
]


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

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'ru-RU'

TIME_ZONE = 'UTC'

Expand Down
6 changes: 5 additions & 1 deletion 01_docker_compose/simple_project/app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
django==4.0.4
uwsgi==2.0.20
uwsgi==2.0.20
flake8==4.0
python-dotenv==0.20
psycopg2==2.9.3
django_split_settings==1.1
18 changes: 17 additions & 1 deletion 01_docker_compose/simple_project/configs/site.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
upstream djangodocker {
server django:8000;
}

server {
listen 80 default_server;
listen [::]:80 default_server;
Expand All @@ -6,14 +10,26 @@ server {
root /data;

location @backend {
proxy_pass http://service:8000;
proxy_pass http://django:8000;
}

location ~* \.(?:jpg|jpeg|gif|png|ico|css|js)$ {
log_not_found off;
expires 90d;
}

location /static/ {
alias /app/static/;
}

location /media/ {
alias /app/media/;
}

location /admin/ {

}

location / {
try_files $uri @backend;
}
Expand Down
45 changes: 34 additions & 11 deletions 01_docker_compose/simple_project/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
version: '3'
services:
service:
db:
image: postgres:13.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
-./example/.env
volumes:
postgres_data:

django:
build: ./app
command: python manage.py runserver localhost:8000
depends_on:
- db
ports:
- 8000:8000
env_file:
-./example/.env
volumes:
- static:/app/static
- media:/app/media
- nginx_conf:/app/configs/
expose:
- "8000"

nginx:
image: nginx:latest
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./configs:/etc/nginx/conf.d:ro
- ./data:/data/:ro
depends_on:
- service
ports:
- "80:80"
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- static:/app/static
- media:/app/media
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./configs:/etc/nginx/conf.d:ro
- ./data:/data/:ro
depends_on:
- django
restart: always
Empty file.
16 changes: 16 additions & 0 deletions 02_django_api/config/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for config project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

application = get_asgi_application()
168 changes: 168 additions & 0 deletions 02_django_api/config/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
"""
Django settings for config project.

Generated by 'django-admin startproject' using Django 3.2.

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

from pathlib import Path
from dotenv import load_dotenv
from split_settings.tools import include

load_dotenv()

# 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!
SECRET_KEY = os.environ.get('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG', False) == 'True'

ALLOWED_HOSTS = ['127.0.0.1']

# for debug tool bar
INTERNAL_IPS = [
'127.0.0.1',
]

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.staticfiles',
'django.contrib.sessions',
'django.contrib.messages',
'debug_toolbar',
'django_extensions',
'corsheaders',
'movies.apps.MoviesConfig', # приложение
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
]

CORS_ALLOWED_ORIGINS = ["http://127.0.0.1:8080",]

ROOT_URLCONF = 'config.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'config.wsgi.application'

SWAGGER_YAML_FILE = '/home/ivan/yandex/sprint_2/new_admin_panel_sprint2/02_django_api/openapi.yaml'

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

include(
'components/database.py',
)

LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'filters': {
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
}
},
'formatters': {
'default': {
'format': '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]',
},
},
'handlers': {
'debug-console': {
'class': 'logging.StreamHandler',
'formatter': 'default',
'filters': ['require_debug_true'],
},
},
'loggers': {
'django.db.backends': {
'level': 'DEBUG',
'handlers': ['debug-console'],
'propagate': False,
}
},
}
# 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',
},
]


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

LANGUAGE_CODE = 'ru-RU'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

LOCALE_PATHS = ['movies/locale']

# 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'
Loading