From 8beb76fa775dcf1dc7438a6f93805b3d34046e96 Mon Sep 17 00:00:00 2001 From: Alexander-D-Karpov Date: Sat, 27 Aug 2022 19:20:20 +0300 Subject: [PATCH] added docker image --- Dockerfile | 17 ++++++ README.md | 4 +- {checker => app/checker}/__init__.py | 0 {checker => app/checker}/admin.py | 0 {checker => app/checker}/api/__init__.py | 0 {checker => app/checker}/api/serializers.py | 0 {checker => app/checker}/api/views.py | 0 {checker => app/checker}/apps.py | 0 .../checker}/migrations/0001_initial.py | 0 .../checker}/migrations/__init__.py | 0 {checker => app/checker}/models.py | 0 {checker => app/checker}/services/__init__.py | 0 {checker => app/checker}/services/file.py | 0 .../checker}/services/generators.py | 0 .../checker}/services/validators.py | 0 {checker => app/checker}/signals.py | 0 {checker => app/checker}/tasks.py | 0 {conf => app/conf}/__init__.py | 0 {conf => app/conf}/api_router.py | 0 {conf => app/conf}/asgi.py | 0 {conf => app/conf}/celery.py | 0 {conf => app/conf}/settings/__init__.py | 0 {conf => app/conf}/settings/base.py | 18 ++++--- {conf => app/conf}/settings/local.py | 12 ----- {conf => app/conf}/settings/production.py | 0 {conf => app/conf}/urls.py | 5 -- {conf => app/conf}/wsgi.py | 0 .../fixtures}/paragraphtypes.json | 0 manage.py => app/manage.py | 0 docker-compose.yml | 54 +++++++++++++------ requirements/base.txt | 4 +- requirements/production.txt | 2 +- 32 files changed, 72 insertions(+), 44 deletions(-) create mode 100644 Dockerfile rename {checker => app/checker}/__init__.py (100%) rename {checker => app/checker}/admin.py (100%) rename {checker => app/checker}/api/__init__.py (100%) rename {checker => app/checker}/api/serializers.py (100%) rename {checker => app/checker}/api/views.py (100%) rename {checker => app/checker}/apps.py (100%) rename {checker => app/checker}/migrations/0001_initial.py (100%) rename {checker => app/checker}/migrations/__init__.py (100%) rename {checker => app/checker}/models.py (100%) rename {checker => app/checker}/services/__init__.py (100%) rename {checker => app/checker}/services/file.py (100%) rename {checker => app/checker}/services/generators.py (100%) rename {checker => app/checker}/services/validators.py (100%) rename {checker => app/checker}/signals.py (100%) rename {checker => app/checker}/tasks.py (100%) rename {conf => app/conf}/__init__.py (100%) rename {conf => app/conf}/api_router.py (100%) rename {conf => app/conf}/asgi.py (100%) rename {conf => app/conf}/celery.py (100%) rename {conf => app/conf}/settings/__init__.py (100%) rename {conf => app/conf}/settings/base.py (95%) rename {conf => app/conf}/settings/local.py (76%) rename {conf => app/conf}/settings/production.py (100%) rename {conf => app/conf}/urls.py (90%) rename {conf => app/conf}/wsgi.py (100%) rename {fixtures => app/fixtures}/paragraphtypes.json (100%) rename manage.py => app/manage.py (100%) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3ecce77 --- /dev/null +++ b/Dockerfile @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 1650d7c..6673695 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# backend \ No newline at end of file +# backend + +### backend for \ No newline at end of file diff --git a/checker/__init__.py b/app/checker/__init__.py similarity index 100% rename from checker/__init__.py rename to app/checker/__init__.py diff --git a/checker/admin.py b/app/checker/admin.py similarity index 100% rename from checker/admin.py rename to app/checker/admin.py diff --git a/checker/api/__init__.py b/app/checker/api/__init__.py similarity index 100% rename from checker/api/__init__.py rename to app/checker/api/__init__.py diff --git a/checker/api/serializers.py b/app/checker/api/serializers.py similarity index 100% rename from checker/api/serializers.py rename to app/checker/api/serializers.py diff --git a/checker/api/views.py b/app/checker/api/views.py similarity index 100% rename from checker/api/views.py rename to app/checker/api/views.py diff --git a/checker/apps.py b/app/checker/apps.py similarity index 100% rename from checker/apps.py rename to app/checker/apps.py diff --git a/checker/migrations/0001_initial.py b/app/checker/migrations/0001_initial.py similarity index 100% rename from checker/migrations/0001_initial.py rename to app/checker/migrations/0001_initial.py diff --git a/checker/migrations/__init__.py b/app/checker/migrations/__init__.py similarity index 100% rename from checker/migrations/__init__.py rename to app/checker/migrations/__init__.py diff --git a/checker/models.py b/app/checker/models.py similarity index 100% rename from checker/models.py rename to app/checker/models.py diff --git a/checker/services/__init__.py b/app/checker/services/__init__.py similarity index 100% rename from checker/services/__init__.py rename to app/checker/services/__init__.py diff --git a/checker/services/file.py b/app/checker/services/file.py similarity index 100% rename from checker/services/file.py rename to app/checker/services/file.py diff --git a/checker/services/generators.py b/app/checker/services/generators.py similarity index 100% rename from checker/services/generators.py rename to app/checker/services/generators.py diff --git a/checker/services/validators.py b/app/checker/services/validators.py similarity index 100% rename from checker/services/validators.py rename to app/checker/services/validators.py diff --git a/checker/signals.py b/app/checker/signals.py similarity index 100% rename from checker/signals.py rename to app/checker/signals.py diff --git a/checker/tasks.py b/app/checker/tasks.py similarity index 100% rename from checker/tasks.py rename to app/checker/tasks.py diff --git a/conf/__init__.py b/app/conf/__init__.py similarity index 100% rename from conf/__init__.py rename to app/conf/__init__.py diff --git a/conf/api_router.py b/app/conf/api_router.py similarity index 100% rename from conf/api_router.py rename to app/conf/api_router.py diff --git a/conf/asgi.py b/app/conf/asgi.py similarity index 100% rename from conf/asgi.py rename to app/conf/asgi.py diff --git a/conf/celery.py b/app/conf/celery.py similarity index 100% rename from conf/celery.py rename to app/conf/celery.py diff --git a/conf/settings/__init__.py b/app/conf/settings/__init__.py similarity index 100% rename from conf/settings/__init__.py rename to app/conf/settings/__init__.py diff --git a/conf/settings/base.py b/app/conf/settings/base.py similarity index 95% rename from conf/settings/base.py rename to app/conf/settings/base.py index 7b87556..15ff902 100644 --- a/conf/settings/base.py +++ b/app/conf/settings/base.py @@ -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" diff --git a/conf/settings/local.py b/app/conf/settings/local.py similarity index 76% rename from conf/settings/local.py rename to app/conf/settings/local.py index ef8738b..a5a6c14 100644 --- a/conf/settings/local.py +++ b/app/conf/settings/local.py @@ -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"] diff --git a/conf/settings/production.py b/app/conf/settings/production.py similarity index 100% rename from conf/settings/production.py rename to app/conf/settings/production.py diff --git a/conf/urls.py b/app/conf/urls.py similarity index 90% rename from conf/urls.py rename to app/conf/urls.py index 4429ec8..ed79676 100644 --- a/conf/urls.py +++ b/app/conf/urls.py @@ -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 diff --git a/conf/wsgi.py b/app/conf/wsgi.py similarity index 100% rename from conf/wsgi.py rename to app/conf/wsgi.py diff --git a/fixtures/paragraphtypes.json b/app/fixtures/paragraphtypes.json similarity index 100% rename from fixtures/paragraphtypes.json rename to app/fixtures/paragraphtypes.json diff --git a/manage.py b/app/manage.py similarity index 100% rename from manage.py rename to app/manage.py diff --git a/docker-compose.yml b/docker-compose.yml index 902dc26..6b6dfeb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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" \ No newline at end of file + 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: \ No newline at end of file diff --git a/requirements/base.txt b/requirements/base.txt index 3fea1e2..645cf8f 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -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 @@ -16,4 +15,5 @@ dj-database-url uuid docx2txt python-docx -requests-async \ No newline at end of file +requests-async +drf-yasg[validation] diff --git a/requirements/production.txt b/requirements/production.txt index cd9258f..0ac2fe3 100644 --- a/requirements/production.txt +++ b/requirements/production.txt @@ -1,4 +1,4 @@ -r base.txt gunicorn==20.1.0 -psycopg2==2.9.3 +psycopg2-binary==2.9.3