Last active
July 15, 2016 08:16
-
-
Save pomahtuk/ceac0510200bbea16ea73230531c3880 to your computer and use it in GitHub Desktop.
django deploy setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# server | |
# git repo itself | |
mkdir -p /var/git/yourapp.git | |
# where project will be | |
mkdir -p /var/www/yourapp | |
# make git server | |
cd /var/git/yourapp.git | |
git init --bare . | |
# put contents of post-receive hook into peropper file | |
chmod +x /var/git/yourapp.git/hooks/post-receive | |
# on developer machine run following | |
git remote add production ssh://user@server:/var/git/yourapp.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream folio { | |
server 127.0.0.1:8000; | |
keepalive 8; | |
} | |
....... | |
# main location | |
location / { | |
# let django know all request headers | |
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_set_header X-NginX-Proxy true; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
# enable websockets, just in case | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
# set up forwarding of request to actual django app | |
proxy_read_timeout 5m; | |
proxy_connect_timeout 5m; | |
proxy_pass http://folio/; | |
proxy_redirect off; | |
} | |
# serve static via nginx | |
location /static { | |
root /var/www/folio/portfolio; | |
try_files $uri $uri/ =404; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
error_exit () | |
{ | |
echo "$1" 1>&2 | |
exit 1 | |
} | |
git --work-tree=/var/www/folio --git-dir=/var/git/folio.git checkout -f | |
cd /var/www/folio || error_exit "error changing directory!. now exiting..." | |
echo "Switching to correct virtualenv..." | |
source /var/www/folioenv/bin/activate | |
echo "Installing dependencies..." | |
pip install -r requirements.txt || error_exit "error running pip install! now exiting ..." | |
echo "Applying migrations dependencies..." | |
./manage.py migrate || error_exit "error rmigrating modelsl! now exiting ..." | |
echo "Collecting static files dependencies..." | |
./manage.py collectstatic --noinput || error_exit "error collecting static! now exiting ..." | |
echo "Installing bower components" | |
bower install || error_exit "wrror installing dependencies for frontend" | |
echo "Restarting server..." | |
sudo /usr/bin/supervisorctl restart portfolio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[program:portfolio] | |
directory=/var/www/folio | |
command=/var/www/folioenv/bin/python /usr/local/bin/gunicorn portfolio.wsgi | |
user=git | |
autostart=true | |
autorestart=false | |
#stdout_logfile=/tmp/folio.log | |
redirect_stderr=true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment