diff --git a/.dockerfile b/.dockerfile index 04a1336..0ae45e6 100644 --- a/.dockerfile +++ b/.dockerfile @@ -3,12 +3,6 @@ FROM python:3.6 RUN mkdir -p /usr/src/app WORKDIR /usr/src/app -COPY package.json /usr/src/app/ -RUN npm install -RUN npm install -g bower -COPY bower.json /usr/src/app/ -RUN bower install - COPY requirements.txt /usr/src/app/ RUN pip install --no-cache-dir -r requirements.txt @@ -16,3 +10,4 @@ ENV PYTHONUNBUFFERED 1 ENV PYTHONDONTWRITEBYTECODE 1 ENV LANG en_US.UTF-8 ENV PYTHONIOENCODING utf_8 + diff --git a/.gitignore b/.gitignore index d739332..950615b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.env *.pyc .sass-cache .DS_Store diff --git a/readme.md b/README.md similarity index 84% rename from readme.md rename to README.md index 4540ea0..630ac8e 100644 --- a/readme.md +++ b/README.md @@ -60,9 +60,14 @@ Now access the admin panel with the user account you created earlier: http://loc ## Production notes -We are using [Dokku](http://dokku.viewdocs.io/) for automated deployment. +We suggest using Docker or [Dokku](http://dokku.viewdocs.io/) for automated deployment. ``` -sudo dokku apps:create phase-alpha -sudo dokku config:set phase-alpha BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-python +docker-compose run web python manage.py migrate +... createsuperuser +... compress +... collectstatic + +docker-compose build web +docker-compose up -d ``` diff --git a/docker-compose.yml b/docker-compose.yml index bcbac8a..7040ba5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,31 @@ web: build: . dockerfile: .dockerfile - command: python manage.py runserver 0.0.0.0:5000 + command: gunicorn publichealth.wsgi:application -b 0.0.0.0:5000 -w 5 --log-file=- volumes: - - ./:/usr/src/app + - ./:/usr/src/app + - /var/log/publichealth:/var/log/publichealth links: + - redis - postgres - elasticsearch ports: - "5000:5000" environment: - - DEBUG=True - - DEV=True - - DATABASE_URL=postgres://postgres:@postgres:5432/postgres - - ELASTICSEARCH_URL=http://elasticsearch:9200 - - SECRET_KEY=notasecretreplaceme + - SECRET_KEY=${SECRET_KEY} + - ALLOWED_HOSTS=${ALLOWED_HOSTS} + - DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE} + - MAILGUN_KEY=${MAILGUN_KEY} + - MAILGUN_FROM=${MAILGUN_FROM} + - MAILGUN_DOMAIN=${MAILGUN_DOMAIN} + - DATABASE_URL=postgres://postgres:@postgres:5432/postgres + - ELASTICSEARCH_URL=http://elasticsearch:9200 + - REDIS_URL=redis://redis:6379 + - LOG_DIR=/var/log/publichealth +redis: + image: redis + ports: + - "6379:6379" postgres: image: postgres ports: @@ -22,4 +33,4 @@ postgres: elasticsearch: image: orchardup/elasticsearch ports: - - "9200:9200" + - "9200:9200" diff --git a/docs/public-health.conf b/docs/public-health.conf new file mode 100644 index 0000000..790dcac --- /dev/null +++ b/docs/public-health.conf @@ -0,0 +1,57 @@ +# Public Health CMS stage +upstream wagtail-stage { + server localhost:5000; +} +server { + listen 80; + server_name ph-alpha.nebula1.public-health.ch; + client_max_body_size 64M; + + gzip on; + gzip_types text/plain text/css application/x-javascript image/svg+xml; + gzip_comp_level 1; + gzip_disable msie6; + gzip_http_version 1.0; + gzip_proxied any; + gzip_vary on; + + location /static/ { + access_log off; + expires 3600; + alias /opt/public-health-ch/static/; + } + + # Set a longer expiry for CACHE/, because the filenames are unique. + location /static/CACHE/ { + access_log off; + expires 864000; + alias /opt/public-health-ch/static/CACHE/; + } + + # Only server /media/images by default, not e.g. original_images/. + location /media/images { + expires 864000; + alias /opt/public-health-ch/media/images; + } + + location / { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://wagtail-stage; + } +} + +server { + listen 80; listen 443 ssl; + server_name conference.public-health.ch; + location /fr { + return 301 $scheme://sph17.organizers-congress.org/frontend/index.php?sub=89; + } + location / { + return 301 $scheme://sph17.organizers-congress.org; + } +} + + diff --git a/publichealth/settings/base.py b/publichealth/settings/base.py index 505b4ba..980592f 100644 --- a/publichealth/settings/base.py +++ b/publichealth/settings/base.py @@ -44,6 +44,7 @@ INSTALLED_APPS = [ 'compressor', 'taggit', 'puput', + 'anymail', 'django.contrib.admin', 'django.contrib.auth', @@ -187,7 +188,6 @@ WAGTAILSEARCH_BACKENDS = { }, } - # Wagtail settings WAGTAIL_SITE_NAME = "Public Health Schweiz" diff --git a/publichealth/settings/production.py b/publichealth/settings/production.py index e0d4f38..94c0867 100644 --- a/publichealth/settings/production.py +++ b/publichealth/settings/production.py @@ -7,8 +7,8 @@ from .base import * # Instead, use environment variables or create a local.py file on the server. # Disable debug mode -DEBUG = True -TEMPLATES[0]['OPTIONS']['debug'] = True +DEBUG = False +TEMPLATES[0]['OPTIONS']['debug'] = False # Compress static files offline and minify CSS # http://django-compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE @@ -87,6 +87,16 @@ else: } +# Email via ESP + +if 'MAILGUN_KEY' in os.environ: + EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend" + ANYMAIL = { + "MAILGUN_API_KEY": env['MAILGUN_KEY'], + "MAILGUN_SENDER_DOMAIN": env['MAILGUN_DOMAIN'] + } + DEFAULT_FROM_EMAIL = env['MAILGUN_FROM'] + # Redis # Redis location can either be passed through with REDIS_HOST or REDIS_SOCKET @@ -124,7 +134,7 @@ if REDIS_LOCATION is not None: if 'ELASTICSEARCH_URL' in env: WAGTAILSEARCH_BACKENDS = { 'default': { - 'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch.ElasticSearch', + 'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch5', 'URLS': [env['ELASTICSEARCH_URL']], 'INDEX': APP_NAME, 'ATOMIC_REBUILD': True, diff --git a/requirements.txt b/requirements.txt index c48d1f1..f8bf590 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -# Updated: 27.3.2017 +# Updated: 5.4.2017 # Core wagtail==1.9 @@ -12,7 +12,7 @@ dj-database-url==0.4.2 puput==0.8 # Search -elasticsearch==5.2.0 +elasticsearch>=5.0.0,<6.0.0 # Caching django-redis==4.7.0 @@ -29,3 +29,4 @@ stellar==0.4.3 gunicorn==19.7.1 whitenoise==3.3.0 ConcurrentLogHandler==0.9.1 +django-anymail==0.9