added docker image

This commit is contained in:
Alexander Karpov 2022-08-27 19:20:20 +03:00
parent 522a733c35
commit 8beb76fa77
32 changed files with 72 additions and 44 deletions

17
Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM python:3.10-alpine
# Set environment variables
ENV PYTHONUNBUFFERED 1
COPY ./requirements/base.txt .
COPY ./requirements/production.txt .
RUN apk add --update --no-cache postgresql-client jpeg-dev
RUN apk add --update --no-cache --virtual .tmp-build-deps \
gcc libc-dev linux-headers postgresql-dev musl-dev zlib zlib-dev
RUN pip install -r /production.txt
RUN apk del .tmp-build-deps
RUN mkdir /app
COPY ./app /app
WORKDIR /app

View File

@ -1 +1,3 @@
# backend
### backend for

View File

@ -31,14 +31,18 @@ LOCALE_PATHS = [str(APPS_DIR / "locale")]
# DATABASES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
import dj_database_url
DATABASES = {
"default": dj_database_url.config(
conn_max_age=600, default="postgres://postgres:debug@127.0.0.1:5432/db"
)
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'db',
'PORT': 5432,
}
}
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
@ -199,11 +203,11 @@ CORS_ALLOW_ALL_ORIGINS = True
# Celery
CELERY_BROKER_URL = "redis://localhost:6379/0"
CELERY_BROKER_URL = "redis://redis:6379"
CELERY_RESULT_BACKEND = "redis://redis:6379"
CELERY_TIMEZONE = "Europe/Moscow"
CELERY_TASK_TRACK_STARTED = True
CELERY_TASK_TIME_LIMIT = 30 * 60
CELERY_ACCEPT_CONTENT = ["json"]
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
CELERY_RESULT_BACKEND = "django-db"

View File

@ -25,18 +25,6 @@ CACHES = {
}
}
# django-debug-toolbar
# ------------------------------------------------------------------------------
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#prerequisites
INSTALLED_APPS += ["debug_toolbar"]
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#middleware
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"] # noqa F405
# https://django-debug-toolbar.readthedocs.io/en/latest/configuration.html#debug-toolbar-config
DEBUG_TOOLBAR_CONFIG = {
"DISABLE_PANELS": ["debug_toolbar.panels.redirects.RedirectsPanel"],
"SHOW_TEMPLATE_CONTEXT": True,
}
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#internal-ips
INTERNAL_IPS = ["127.0.0.1"]

View File

@ -39,8 +39,3 @@ urlpatterns = [
name="schema-redoc",
),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if settings.DEBUG:
import debug_toolbar
urlpatterns = [path("__debug__/", include(debug_toolbar.urls))] + urlpatterns

View File

@ -1,20 +1,42 @@
version: "3"
version: "3.9"
services:
postgres:
image: "postgres"
container_name: "postgres"
environment:
- POSTGRES_HOST=postgres
- POSTGRES_PORT=5432
- POSTGRES_DB=db
- POSTGRES_USER=debug
- POSTGRES_PASSWORD=debug
web:
build: .
ports:
- "8000:8000"
volumes:
- .:/code
command: >
sh -c "python3 manage.py makemigrations &&
python3 manage.py migrate --noinput &&
python3 manage.py loaddata paragraphtypes.json &&
python3 manage.py runserver 0.0.0.0:8000"
depends_on:
- db
db:
image: postgres:14-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
ports:
- "5432:5432"
network_mode: "host"
environment:
- "POSTGRES_HOST_AUTH_METHOD=trust"
- "POSTGRES_DB=db"
- "POSTGRES_USER=postgres"
- "POSTGRES_PASSWORD=postgres"
redis:
image: "redis:alpine"
ports:
- "6379:6379"
image: redis:alpine
celery:
restart: always
build:
context: .
command: celery -A conf worker --loglevel=INFO
volumes:
- ./app:/app
depends_on:
- db
- redis
- web
volumes:
postgres_data:

View File

@ -6,7 +6,6 @@ djangorestframework==3.13.1
djangorestframework-simplejwt==5.2.0
django-health-check==3.16.5
django-cors-headers==3.13.0
drf-yasg==1.21.3
celery==5.2.7
Redis==4.3.4
django_celery_results==2.4.0
@ -17,3 +16,4 @@ uuid
docx2txt
python-docx
requests-async
drf-yasg[validation]

View File

@ -1,4 +1,4 @@
-r base.txt
gunicorn==20.1.0
psycopg2==2.9.3
psycopg2-binary==2.9.3