diff --git a/Dockerfile b/Dockerfile index 6551f656b..b5edd9bf9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,31 +4,37 @@ ENV BUILD_PACKAGES postgresql-dev graphviz-dev graphviz build-base git pkgconfig python3-dev libxml2-dev jpeg-dev libressl-dev libffi-dev libxslt-dev nodejs py3-lxml \ py3-magic postgresql-client vim -RUN apk add --no-cache python3 && \ +RUN apk add --no-cache python3 nginx && \ python3 -m ensurepip && \ rm -r /usr/lib/python*/ensurepip && \ pip3 install --upgrade pip setuptools && \ - rm -r /root/.cache + rm -r /root/.cache && \ + rm -f /etc/nginx/conf.d/* -RUN mkdir -p /var/interlegis/sapl &&\ +RUN mkdir -p /var/interlegis/sapl && \ apk add --update --no-cache $BUILD_PACKAGES && \ - npm install -g bower - -# Bower aceitar root -RUN touch /root/.bowerrc \ -&& chmod 751 /root/.bowerrc \ -&& echo "{ \"allow_root\": true }" >> /root/.bowerrc \ -&& npm cache clean + npm install -g bower && \ + npm cache clean WORKDIR /var/interlegis/sapl/ ADD . /var/interlegis/sapl/ COPY start.sh /var/interlegis/sapl/ +COPY config/nginx/sapl.conf /etc/nginx/conf.d +COPY config/nginx/nginx.conf /etc/nginx/nginx.conf + +RUN pip install -r /var/interlegis/sapl/requirements/requirements.txt --upgrade setuptools && \ + rm -r /root/.cache && \ + rm -r /tmp/* -RUN chmod +x /var/interlegis/sapl/start.sh +RUN python3 manage.py bower install -- --allow-root && \ + python3 manage.py collectstatic --no-input -RUN pip install -r /var/interlegis/sapl/requirements/requirements.txt --upgrade setuptools +RUN chmod +x /var/interlegis/sapl/start.sh && \ + ln -sf /dev/stdout /var/log/nginx/access.log && \ + ln -sf /dev/stderr /var/log/nginx/error.log VOLUME ["/var/interlegis/sapl/data", "/var/interlegis/sapl/media", "/var/interlegis/sapl/collected_static"] -ENTRYPOINT ["/var/interlegis/sapl/start.sh"] + +CMD ["/var/interlegis/sapl/start.sh"] diff --git a/config/nginx/nginx.conf b/config/nginx/nginx.conf new file mode 100644 index 000000000..cfea596f1 --- /dev/null +++ b/config/nginx/nginx.conf @@ -0,0 +1,31 @@ +user nginx; +worker_processes 1; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile off; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + include /etc/nginx/conf.d/*.conf; +} diff --git a/start.sh b/start.sh index 250be13ea..5ee1d7d79 100755 --- a/start.sh +++ b/start.sh @@ -40,12 +40,12 @@ create_env() { create_env -python3 manage.py bower install +#python3 manage.py bower install /bin/sh busy-wait.sh $DATABASE_URL python3 manage.py migrate -python3 manage.py collectstatic --no-input +#python3 manage.py collectstatic --no-input python3 manage.py rebuild_index --noinput user_created=$(python3 create_admin.py 2>&1) @@ -66,4 +66,5 @@ if [ $lack_pwd -eq 0 ]; then fi -/bin/sh gunicorn_start.sh no-venv +/bin/sh gunicorn_start.sh no-venv & +/usr/sbin/nginx -g "daemon off;"