-
Notifications
You must be signed in to change notification settings - Fork 2
Deploy
Raphaël edited this page Apr 1, 2019
·
2 revisions
We are using Capistrano deployment scripts.
cap production deploy # at the root of the code repository
The script does the following things :
- Clone the code repository on the server
- Create the virtual environement according to the requirements.txt file
- Create the static files
- Copy previous database (we are using sqlite3, it must be change for futher uses)
- Apply the migrations
- Set the debug variables to False
- Restart the application server (daphne), the loadbalancer (nginx), and the redis-server
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;
}
}
/etc/services/nginx/run
#!/bin/sh
set -xe
exec /usr/sbin/nginx
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.
/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 is used for channels (the django library for websockets)
/etc/services/redis-server/run
#!/bin/sh
set -xe
exec /usr/bin/redis-server
A crontab schedule run every day a 3 am to restart every services (daphne redis-server nginx), to avoid bugs.