diff --git a/Dockerfile b/Dockerfile index 672f8df..9a65ec5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ -FROM python:3.6 -ENV PYTHONUNBUFFERED 1 +FROM alpine:latest ENV NGINX_VERSION="1.13.2" \ NGINX_OPTS="--with-http_ssl_module \ @@ -10,50 +9,93 @@ ENV NGINX_VERSION="1.13.2" \ --pid-path=/var/run/nginx.pid \ --http-log-path=/var/log/nginx/access.log \ --error-log-path=/var/log/nginx/error.log \ - --user=www-data \ - --group=www-data \ + --user=nginx \ + --group=nginx \ --add-module=/tmp/modules/nginx_requestid-master" - COPY requirements /opt/app/requirements -RUN apt-get update -y && \ - apt-get upgrade -y && \ - apt-get -y install ghostscript \ - libfreetype6-dev \ - python3-dev \ + +RUN apk update && apk add --update --no-cache --progress \ + make \ + pcre \ + zlib \ + libpq \ + openssl \ + ca-certificates \ + python3 \ + libxml2-dev \ + py-libxml2 \ + libxml2-utils \ + libxslt-dev \ + libmagic \ + ghostscript \ + postgresql-dev \ supervisor \ - git-core \ - make && \ - apt-get clean && \ + libmemcached-dev \ + cyrus-sasl-dev \ + jpeg libpng freetype \ + bash bash-completion \ + gettext-dev \ + freetype-dev \ + libtool \ + mailcap \ + libgomp \ + jpeg-dev \ + expat \ + tcl-dev \ + tk-dev \ + + && apk add --no-cache --virtual=.build-dependencies \ + musl-dev \ + curl \ + build-base \ + ncurses-dev \ + pcre-dev \ + zlib-dev \ + libpng-dev \ + tiff-dev \ + lcms2-dev \ + libwebp-dev \ + libffi-dev \ + ttf-freefont \ + font-bh-ttf \ + python3-dev \ + && python3 -m ensurepip \ + && rm -r /usr/lib/python*/ensurepip \ + && pip3 install --upgrade pip setuptools \ + && pip3 install --no-cache-dir -r /opt/app/requirements/production.txt \ + + # Add nginx group and user + && addgroup -S nginx \ + && adduser -S nginx -G nginx \ # Download additional nginx modules - mkdir -p /tmp/modules && \ - cd /tmp/modules && \ - wget -O nginx-requestid.tar.gz https://github.com/hhru/nginx_requestid/archive/master.tar.gz && \ - tar xvzf nginx-requestid.tar.gz && \ + && mkdir -p /tmp/modules \ + && cd /tmp/modules \ + && wget -O nginx-requestid.tar.gz https://github.com/hhru/nginx_requestid/archive/master.tar.gz \ + && tar xvzf nginx-requestid.tar.gz \ # Download and compile nginx - cd /tmp && \ - wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \ - tar xzvf nginx-${NGINX_VERSION}.tar.gz && \ - cd nginx-${NGINX_VERSION} && \ - ./configure ${NGINX_OPTS} && \ - make && \ - make install && \ - - pip install --upgrade pip && \ - pip install --no-cache-dir -r /opt/app/requirements/production.txt && \ + && cd /tmp \ + && curl -fSL http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz -o nginx-${NGINX_VERSION}.tar.gz \ + && tar xzvf nginx-${NGINX_VERSION}.tar.gz \ + && cd nginx-${NGINX_VERSION} \ + && ./configure ${NGINX_OPTS} \ + && make \ + && make install \ # Delete build dependencies after use - cd /tmp \ - + && cd /tmp \ + && apk del .build-dependencies \ && rm -rf \ modules \ nginx-${NGINX_VERSION} \ nginx-${NGINX_VERSION}.tar.gz \ - /var/cache/apt/* \ + /var/cache/apk/* \ /root/.cache \ - /var/lib/apt/lists/* -# for gitlab cli + # Security precautions + && openssl rand -base64 32 > /opt/app/secret_key.txt \ + && echo "root:$(openssl passwd -apr1 uztOsdwP)" >> /etc/nginx/.htpasswd + #COPY . /opt/app #VOLUME ["/opt/app/public/media"] WORKDIR /opt/app @@ -62,4 +104,6 @@ RUN rm -v /etc/nginx/nginx.conf ADD /conf/nginx.conf /etc/nginx/ EXPOSE 80 + + CMD ["conf/docker/entrypoint_stage.sh"] diff --git a/Dockerfile.debian b/Dockerfile.debian new file mode 100644 index 0000000..672f8df --- /dev/null +++ b/Dockerfile.debian @@ -0,0 +1,65 @@ +FROM python:3.6 +ENV PYTHONUNBUFFERED 1 + +ENV NGINX_VERSION="1.13.2" \ + NGINX_OPTS="--with-http_ssl_module \ + --with-http_gzip_static_module \ + --prefix=/usr/share/nginx \ + --sbin-path=/usr/sbin/nginx \ + --conf-path=/etc/nginx/nginx.conf \ + --pid-path=/var/run/nginx.pid \ + --http-log-path=/var/log/nginx/access.log \ + --error-log-path=/var/log/nginx/error.log \ + --user=www-data \ + --group=www-data \ + --add-module=/tmp/modules/nginx_requestid-master" + +COPY requirements /opt/app/requirements +RUN apt-get update -y && \ + apt-get upgrade -y && \ + apt-get -y install ghostscript \ + libfreetype6-dev \ + python3-dev \ + supervisor \ + git-core \ + make && \ + apt-get clean && \ + + # Download additional nginx modules + mkdir -p /tmp/modules && \ + cd /tmp/modules && \ + wget -O nginx-requestid.tar.gz https://github.com/hhru/nginx_requestid/archive/master.tar.gz && \ + tar xvzf nginx-requestid.tar.gz && \ + # Download and compile nginx + cd /tmp && \ + wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \ + tar xzvf nginx-${NGINX_VERSION}.tar.gz && \ + cd nginx-${NGINX_VERSION} && \ + ./configure ${NGINX_OPTS} && \ + make && \ + make install && \ + + pip install --upgrade pip && \ + pip install --no-cache-dir -r /opt/app/requirements/production.txt && \ + + # Delete build dependencies after use + cd /tmp \ + + && rm -rf \ + modules \ + nginx-${NGINX_VERSION} \ + nginx-${NGINX_VERSION}.tar.gz \ + /var/cache/apt/* \ + /root/.cache \ + /var/lib/apt/lists/* + +# for gitlab cli +#COPY . /opt/app +#VOLUME ["/opt/app/public/media"] +WORKDIR /opt/app + +RUN rm -v /etc/nginx/nginx.conf +ADD /conf/nginx.conf /etc/nginx/ + +EXPOSE 80 +CMD ["conf/docker/entrypoint_stage.sh"] diff --git a/conf/nginx.conf b/conf/nginx.conf index c421108..0bcaa64 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,6 +1,6 @@ worker_processes 1; -user www-data; +user nginx; pid /var/run/nginx.pid; error_log /var/log/nginx/error.log; diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..4056afe --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,56 @@ +version: '2' + +services: + web: + restart: always + container_name: dokumentor-web + build: . + volumes: + - ./:/opt/app + ports: + - "32768:80" + - "33768:5555" + env_file: conf/env + depends_on: + - db + - redis + - rabbitmq + + db: + restart: always + container_name: dokumentor-db + image: kiasaki/alpine-postgres:9.5 + expose: + - "5432" + volumes: + - ./data/postgresql:/var/lib/postgresql/data + environment: + - POSTGRES_USER=dokumentor + - POSTGRES_PASSWORD=dokumentor + + redis: + restart: always + container_name: dokumentor-redis + image: redis:alpine + expose: + - "6379" + + rabbitmq: + restart: always + container_name: dokumentor-rabbitmq + image: rabbitmq:alpine + environment: + - RABBITMQ_DEFAULT_USER=dokumentor + - RABBITMQ_DEFAULT_PASS=dokumentor + expose: + - "5672" + - "5671" + + bower: + container_name: dokumentor-bower + build: + context: . + dockerfile: ./conf/compose/Dockerfile + command: /bin/sh -c "cd /opt/app && bower i" + volumes: + - ./:/opt/app diff --git a/src/docs/views/base_views.py b/src/docs/views/base_views.py index aa47ca4..07a138c 100644 --- a/src/docs/views/base_views.py +++ b/src/docs/views/base_views.py @@ -868,7 +868,7 @@ class BaseItemsViews(BaseViews): def get_xls(self, *args, **kwargs): """Создать документ в Excel и вернуть как строку.""" - obj = self.get_obj(kwargs['id']) + obj = self.get_obj(kwargs[' id']) obj_items = self.get_obj_items_qs(obj) profile = get_profile(obj.user) main_account = BankAccount.objects.get_main(profile) diff --git a/src/dokumentor/settings/common.py b/src/dokumentor/settings/common.py index 4a4c91c..dd016dd 100644 --- a/src/dokumentor/settings/common.py +++ b/src/dokumentor/settings/common.py @@ -279,13 +279,13 @@ THUMBNAIL_PROCESSORS = ( 'filer.thumbnail_processors.scale_and_crop_with_subject_location', 'easy_thumbnails.processors.filters' ) -if not DEBUG: - RAVEN_CONFIG = { - 'dsn': 'http://02d524ef0d044bdfae0b39546b752cb2:1e025305594d4532ae93125372dcde50@sentry.mitri4.pro/1', - # If you are using git, you can also automatically configure the - # release based on the git info. - 'release': raven.fetch_git_sha(ROOT_DIR), - } + +RAVEN_CONFIG = { + 'dsn': 'http://02d524ef0d044bdfae0b39546b752cb2:1e025305594d4532ae93125372dcde50@sentry.mitri4.pro/1', + # If you are using git, you can also automatically configure the + # release based on the git info. + 'release': raven.fetch_git_sha(ROOT_DIR), +} # cache settings COMMON_CACHE_PREFIX = 'dokumentor_'