From 25aed60ce7f7c9c46650959eb92db904e5bedbf6 Mon Sep 17 00:00:00 2001 From: Dmitriy Shesterkin Date: Tue, 23 May 2017 09:14:16 +0300 Subject: [PATCH] start docker-composer --- .editorconfig | 2 +- .gitignore | 2 +- Dockerfile | 38 +++++-------------- ...oint_production.sh => entrypoint_stage.sh} | 7 +++- conf/env | 22 +++++++++++ conf/env.local | 22 +++++++++++ conf/env.stage | 8 ++-- conf/nginx.conf | 2 +- conf/supervisor.conf | 6 ++- docker-compose.yml | 9 ++--- requirements/base.txt | 1 + src/dokumentor/settings/base.py | 32 ---------------- src/dokumentor/settings/production.py | 6 --- src/dokumentor/wsgi.py | 10 +---- 14 files changed, 78 insertions(+), 89 deletions(-) rename conf/docker/{entrypoint_production.sh => entrypoint_stage.sh} (83%) create mode 100644 conf/env create mode 100644 conf/env.local diff --git a/.editorconfig b/.editorconfig index b36fd13..eff6ea1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -49,7 +49,7 @@ indent_style = tab [**.yml] trim_trailing_whitespace = true indent_style = space -indent_size = 2 +indent_size = 4 # The indentation in package.json will always need to be 2 spaces # https://github.com/npm/npm/issues/4718 diff --git a/.gitignore b/.gitignore index e11ad0f..d78b703 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ yandex_money.log /static/ /src/dokumentor/media/ /tmp/ -/conf/env +/conf/env.local /data/ /public/ diff --git a/Dockerfile b/Dockerfile index 2cf2565..ff29005 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,37 +1,19 @@ -FROM alpine:3.6 - +FROM python:3.6 ENV PYTHONUNBUFFERED 1 COPY requirements /opt/app/requirements +RUN apt-get update && \ + apt-get -y install ghostscript libfreetype6-dev nginx supervisor make && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ -RUN apk update && apk add --update --no-cache --progress \ - make \ - libpq \ - nginx \ - libmagic \ - supervisor \ - ghostscript \ - zlib jpeg libpng freetype \ - bash bash-completion && \ - - apk add --no-cache --virtual=.build-dependencies \ - musl-dev \ - build-base \ - postgresql-dev \ - ca-certificates \ - openssl \ - zlib-dev jpeg-dev libpng-dev freetype-dev \ - python-dev && \ - - python -m ensurepip && \ - rm -r /usr/lib/python*/ensurepip && \ - pip install --upgrade pip setuptools && \ - pip install --no-cache-dir -r /opt/app/requirements/production.txt && \ + pip install --upgrade pip && \ + pip install --no-cache-dir -r /opt/app/requirements/production.txt && \ # Nginx - chown -R nginx:www-data /var/lib/nginx && \ + + chown -R www-data:www-data /var/lib/nginx && \ # Delete build dependencies after use - apk del .build-dependencies && \ rm -r /root/.cache COPY . /opt/app @@ -42,4 +24,4 @@ RUN rm -v /etc/nginx/nginx.conf ADD /conf/nginx.conf /etc/nginx/ EXPOSE 80 -CMD ["conf/docker/entrypoint_production.sh"] +CMD ["conf/docker/entrypoint_stage.sh"] diff --git a/conf/docker/entrypoint_production.sh b/conf/docker/entrypoint_stage.sh similarity index 83% rename from conf/docker/entrypoint_production.sh rename to conf/docker/entrypoint_stage.sh index 806d8a5..c187e88 100755 --- a/conf/docker/entrypoint_production.sh +++ b/conf/docker/entrypoint_stage.sh @@ -1,12 +1,17 @@ #!/usr/bin/env bash +set -e +set -u + +export ENV=stage + # Collect static files echo "Collect static files" python src/manage.py collectstatic --noinput # Make database migrations echo "Make database migrations" -python src/manage.py migrate makemigrations +python src/manage.py makemigrations # Apply database migrations echo "Apply database migrations" diff --git a/conf/env b/conf/env new file mode 100644 index 0000000..ffb6ae2 --- /dev/null +++ b/conf/env @@ -0,0 +1,22 @@ +DJANGO_SETTINGS_MODULE='dokumentor.settings.local' + +DJANGO_SECRET='CHANGE_ME_IN_PRODUCTION' + +DJANGO_DB='postgres://dokumentor:dokumentor@localhost:5432/dokumentor' +DJANGO_DB_sqlite3='sqlite:////Users/mitri4/Projects/dokumentor/db.sqlite3' + +DJANGO_FROM_EMAIL='root@localhost' +DJANGO_EMAIL_HOST='' +DJANGO_EMAIL_PORT='' +DJANGO_EMAIL_USER='' +DJANGO_EMAIL_PASSWORD='' +DJANGO_EMAIL_USE_TLS=False +DJANGO_EMAIL_USE_SSL=False + +REDIS_URL='redis://localhost:6379/1' + +CELERY_BROKER_URL ='amqp://guest:guest@localhost:5672//' +CELERY_RESULT_BACKEND ='amqp://guest:guest@localhost:5672//' + +CALLBACK_EMAIL_SENDER='root@localhost' +CALLBACK_MANAGERS_EMAILS=('mitri4@bk.ru', 'dmitriy.shesterkin@gmail.com') diff --git a/conf/env.local b/conf/env.local new file mode 100644 index 0000000..ffb6ae2 --- /dev/null +++ b/conf/env.local @@ -0,0 +1,22 @@ +DJANGO_SETTINGS_MODULE='dokumentor.settings.local' + +DJANGO_SECRET='CHANGE_ME_IN_PRODUCTION' + +DJANGO_DB='postgres://dokumentor:dokumentor@localhost:5432/dokumentor' +DJANGO_DB_sqlite3='sqlite:////Users/mitri4/Projects/dokumentor/db.sqlite3' + +DJANGO_FROM_EMAIL='root@localhost' +DJANGO_EMAIL_HOST='' +DJANGO_EMAIL_PORT='' +DJANGO_EMAIL_USER='' +DJANGO_EMAIL_PASSWORD='' +DJANGO_EMAIL_USE_TLS=False +DJANGO_EMAIL_USE_SSL=False + +REDIS_URL='redis://localhost:6379/1' + +CELERY_BROKER_URL ='amqp://guest:guest@localhost:5672//' +CELERY_RESULT_BACKEND ='amqp://guest:guest@localhost:5672//' + +CALLBACK_EMAIL_SENDER='root@localhost' +CALLBACK_MANAGERS_EMAILS=('mitri4@bk.ru', 'dmitriy.shesterkin@gmail.com') diff --git a/conf/env.stage b/conf/env.stage index 8fd18cb..afdfd12 100644 --- a/conf/env.stage +++ b/conf/env.stage @@ -2,7 +2,7 @@ DJANGO_SETTINGS_MODULE=dokumentor.settings.stage DJANGO_SECRET='CHANGE_ME_IN_PRODUCTION' -DJANGO_DB='postgres://USER:PASSWORD@HOST:PORT/NAME' +DJANGO_DB='postgres://dokumentor:dokumentor@db:5432/dokumentor' DJANGO_FROM_EMAIL='Открытые технологии ' DJANGO_EMAIL_HOST='smtp.yandex.ru' @@ -12,8 +12,10 @@ DJANGO_EMAIL_PASSWORD='BA4BnshqVz3Hae' DJANGO_EMAIL_USE_TLS=False DJANGO_EMAIL_USE_SSL=True -CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672//' -CELERY_RESULT_BACKEND = 'amqp://guest:guest@localhost:5672//' +REDIS_URL='redis://redis:6379/1' + +CELERY_BROKER_URL = 'amqp://dokumentor:dokumentor@rabbitmq:5672//' +CELERY_RESULT_BACKEND = 'amqp://dokumentor:dokumentor@rabbitmq:5672//' CALLBACK_EMAIL_SENDER='Документор ' CALLBACK_MANAGERS_EMAILS=('mitri4@bk.ru', 'alexander.time@gmail.com','dmitriy.shesterkin@gmail.com') diff --git a/conf/nginx.conf b/conf/nginx.conf index dab0d29..d8cca73 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,6 +1,6 @@ worker_processes 1; -user nginx; +user www-data; pid /var/run/nginx.pid; error_log /var/log/nginx/error.log; diff --git a/conf/supervisor.conf b/conf/supervisor.conf index c3cb686..4edc850 100644 --- a/conf/supervisor.conf +++ b/conf/supervisor.conf @@ -17,7 +17,8 @@ stdout_events_enabled=true stderr_events_enabled=true [program:gunicorn] -command=gunicorn src.wsgi:application -c /opt/app/conf/gunicorn_prod.py +command=gunicorn dokumentor.wsgi:application -c /opt/app/conf/gunicorn_prod.py +directory=/opt/app/src priority=2 stdout_logfile=/var/log/gunicorn.log redirect_stderr=true @@ -26,7 +27,8 @@ stderr_events_enabled=true autorestart=true [program:celeryd] -command=/opt/app/src/celery -A dokumentor worker -l info -E +command=celery -A dokumentor worker -l info -E +directory=/opt/app/src stdout_logfile=/var/log/celery-worker.log stderr_logfile=/var/log/celery-worker.log autostart=true diff --git a/docker-compose.yml b/docker-compose.yml index e743486..22315f6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,5 @@ version: '2' + services: web: build: . @@ -6,13 +7,11 @@ services: - ./:/opt/app ports: - "80:80" - env_file: conf/env + env_file: conf/env.stage environment: - - DJANGO_DB=postgres://dokumentor:dokumentor@db:5432/dokumentor - REDIS_URL=redis://redis:6379/1 - CELERY_BROKER_URL=amqp://dokumentor:dokumentor@rabbitmq:5672// - CELERY_RESULT_BACKEND=amqp://dokumentor:dokumentor@rabbitmq:5672// - depends_on: depends_on: - db - redis @@ -39,5 +38,5 @@ services: - RABBITMQ_DEFAULT_USER=dokumentor - RABBITMQ_DEFAULT_PASS=dokumentor expose: - - "5672" - - "5671" + - "5672" + - "5671" diff --git a/requirements/base.txt b/requirements/base.txt index 8f2aed3..be233bc 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -70,3 +70,4 @@ psycopg2==2.6 django-redis==4.8.0 redis==2.10.5 trans==2.1.0 +python-decouple==3.0 diff --git a/src/dokumentor/settings/base.py b/src/dokumentor/settings/base.py index bc21b2d..904aad9 100644 --- a/src/dokumentor/settings/base.py +++ b/src/dokumentor/settings/base.py @@ -88,38 +88,6 @@ MIDDLEWARE_CLASSES = [ 'src.customer.middleware.ProfileMiddleware', ] -# TEMPLATES = [ -# { -# 'BACKEND': 'django.template.backends.django.DjangoTemplates', -# 'DIRS': [ -# os.path.join(PROJECT_DIR, 'templates'), -# -# ], -# 'APP_DIRS': True, -# 'OPTIONS': { -# 'context_processors': [ -# 'django.contrib.auth.context_processors.auth', -# 'django.template.context_processors.debug', -# 'django.template.context_processors.i18n', -# 'django.template.context_processors.media', -# 'django.template.context_processors.static', -# 'django.template.context_processors.tz', -# 'django.contrib.messages.context_processors.messages', -# 'django.template.context_processors.request', -# 'django.template.context_processors.csrf', -# 'sekizai.context_processors.sekizai', -# 'cms.context_processors.cms_settings', -# 'callback.context_processors.add_forms' -# ], -# }, -# 'loaders': [ -# 'django.template.loaders.filesystem.Loader', -# 'django.template.loaders.app_directories.Loader', -# ] -# }, -# ] - - TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', diff --git a/src/dokumentor/settings/production.py b/src/dokumentor/settings/production.py index 5933629..e291bfd 100644 --- a/src/dokumentor/settings/production.py +++ b/src/dokumentor/settings/production.py @@ -16,12 +16,6 @@ DATABASES = { 'default': dj_database_url.parse(e.get('DJANGO_DB')), } - -# Wrap loaders in cached loader # TODO: check, not start in stage -# TEMPLATES[0]['OPTIONS']['loaders'] = [ -# ('django.template.loaders.cached.Loader', TEMPLATES[0]['OPTIONS']['loaders']), -# ] - DEFAULT_FROM_EMAIL = e.get('DJANGO_FROM_EMAIL') SERVER_EMAIL = DEFAULT_FROM_EMAIL EMAIL_HOST = e.get('DJANGO_EMAIL_HOST') diff --git a/src/dokumentor/wsgi.py b/src/dokumentor/wsgi.py index f3e5c22..88f5bbd 100644 --- a/src/dokumentor/wsgi.py +++ b/src/dokumentor/wsgi.py @@ -1,14 +1,6 @@ -""" -WSGI config for garpun project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ -""" - import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dokumentor.settings") from django.core.wsgi import get_wsgi_application + application = get_wsgi_application()