Dockerfile 3.5 KB
Newer Older
1
# Pull base image
2
FROM python:3.7-slim-buster
3 4 5
LABEL maintainer="Enrique Matías Sánchez <quique@unizar.es>"

# Set environment variables
6
# Don't write .pyc files
7
# All output to stdout will be flushed immediately
8 9
ENV PYTHONDONTWRITEBYTECODE 1 \
    PYTHONUNBUFFERED 1
10 11 12 13 14 15 16 17

# Install packages needed to run your application (not build deps):
#   libmariadbclient-client -- for running database commands
#   libpcre3 -- for uWSGI internal routing support
#   xmlsec1 -- required for SAML auth
#   mime-support -- for mime types when serving static files
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
18
      libmariadb3 \
19 20
      libpcre3 \
      libxmlsec1-openssl \
21
      mime-support \
22
      pandoc \
23 24
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*
25 26 27 28 29 30 31 32 33 34 35

# Copy the requirements file to the container image
COPY requirements.txt ./

# - Install the build dependencies needed
# - Run `pip install` to install the requirements
# - Then remove unneeded build deps (C compiler, etc)
# All in a single step, so that Docker cache it as a single layer.
RUN set -ex \
  && BUILD_DEPS=" \
    gcc \
36 37
    libmariadb-dev \
    libmariadb-dev-compat \
38
    libpcre3-dev \
39 40
    libxmlsec1-dev \
    pkg-config" \
41
  && apt-get update \
42 43 44 45 46 47 48 49
  && apt-get install -y --no-install-recommends $BUILD_DEPS \
  && pip install --no-cache-dir -r requirements.txt \
  # && pip install gunicorn \
  && pip install uwsgi \
  && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*

50 51 52 53
# Provisional hasta que se publique una nueva versión de python-social-auth/social-core
ADD https://raw.githubusercontent.com/python-social-auth/social-core/master/social_core/backends/saml.py /usr/local/lib/python3.7/site-packages/social_core/backends/
RUN chmod a+r /usr/local/lib/python3.7/site-packages/social_core/backends/saml.py

54 55 56 57 58 59 60 61 62 63 64 65
# Copy your application code to the container image
# (make sure you create a .dockerignore file if any large files or directories should be excluded)
WORKDIR /code
COPY . /code

# The WSGI server will listen on this port
EXPOSE 8000

# Add any static environment variables needed by Django or your settings file here:
# ENV DJANGO_SETTINGS_MODULE=my_project.settings.deploy

# Call collectstatic
66
RUN python3 manage.py collectstatic --no-input
67 68 69 70 71 72 73 74 75 76 77 78

## GUNICORN
# CMD exec gunicorn manhattan_project.wsgi:application --bind 0.0.0.0:8000 --workers 3

## uWSGI
# Tell uWSGI where to find your wsgi file:
ENV UWSGI_WSGI_FILE=manhattan_project/wsgi.py

# Base uWSGI configuration (you shouldn't need to change these):
ENV UWSGI_HTTP=:8000 UWSGI_MASTER=1 UWSGI_HTTP_AUTO_CHUNKED=1 UWSGI_HTTP_KEEPALIVE=1 UWSGI_UID=1000 UWSGI_GID=2000 UWSGI_LAZY_APPS=1 UWSGI_WSGI_ENV_BEHAVIOR=holy

# Number of uWSGI workers and threads per worker (customize as needed):
79
ENV UWSGI_WORKERS=4 UWSGI_THREADS=1
80 81

# uWSGI static file serving configuration (customize, or comment out if using Whitenoise or S3):
82
ENV UWSGI_STATIC_MAP="/static/=/code/staticfiles/" UWSGI_STATIC_EXPIRES_URI="/static/.*\.[a-f0-9]{12,}\.(css|js|png|jpg|jpeg|gif|ico|woff|ttf|otf|svg|scss|pdf|map|txt) 86400"
83
ENV UWSGI_STATIC_MAP2="/media/=/code/media/" UWSGI_STATIC_EXPIRES_URI="/media/.*/.*/.*\.[a-f0-9]{12,}\.(png|jpg|jpeg|gif|svg) 3600"
84

85 86 87 88 89 90 91 92 93

# Deny invalid hosts before they get to Django (uncomment and change to your hostname(s)):
# ENV UWSGI_ROUTE_HOST="^(?!localhost:8000$) break:400"

# Uncomment after creating your docker-entrypoint.sh
ENTRYPOINT ["/code/docker-entrypoint.sh"]

# Start uWSGI
CMD ["uwsgi", "--show-config"]