Skip to content
Raphaël edited this page Apr 1, 2019 · 2 revisions

Deploy a release

We are using Capistrano deployment scripts.

cap production deploy # at the root of the code repository

The script does the following things :

  1. Clone the code repository on the server
  2. Create the virtual environement according to the requirements.txt file
  3. Create the static files
  4. Copy previous database (we are using sqlite3, it must be change for futher uses)
  5. Apply the migrations
  6. Set the debug variables to False
  7. Restart the application server (daphne), the loadbalancer (nginx), and the redis-server

Server configuration

Nginx

nginx virtual host configuration file

map $http_upgrade $connection_upgrade {
    default Upgrade;
    ''      close;
}

server {
    listen 80;
    server_name _;

    client_max_body_size 4G;

    root /var/www/app/public;

    access_log /var/www/logs/access.log;
    error_log /var/www/logs/error.log;

    index index.html index.htm;

    # WebSocket
    location / {
        # Note the 8001 port used for daphne server
        proxy_pass http://127.0.0.1:8001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_redirect     off;
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $server_name;
    }

    # special path for the static files
    location /static/ {
        root /var/www/OpenSauce;
    }
}

Supervisor

/etc/services/nginx/run

#!/bin/sh
set -xe
exec /usr/sbin/nginx

Daphne

We are using Daphne as the application server, it is located in the Python virtual environement. We dont use uwsgi, because it doesn't implement websockets.

Supervisor

/etc/services/daphne/run

#!/bin/sh
set -xe
cd /var/www/OpenSauce/current
exec /var/www/OpenSauce/shared/venv/bin/daphne -b 127.0.0.1 -p 8001 --access-log /var/www/logs/daphne.log opensauceproject.asgi:application

Redis-server

Redis is used for channels (the django library for websockets)

Supervisor

/etc/services/redis-server/run

#!/bin/sh
set -xe
exec /usr/bin/redis-server

Crontab

A crontab schedule run every day a 3 am to restart every services (daphne redis-server nginx), to avoid bugs.

Clone this wiki locally