Adds fabfile for deployment
This commit is contained in:
1 parent
ad52fb14f0
commit
c0415b955c
3 files changed
+80
-1
No files matched your search
@@ -1,10 +1,25 @@
|
||||
# Install
|
||||
apt install python-dev libmysqlclient-dev python-virtualenv
|
||||
virtualenv venv
|
||||
. venv/bin/activate
|
||||
pip install -r requirements
|
||||
|
||||
# Deploy
|
||||
First you need to have your public key in /home/gitdeploy/.ssh/authorized_keys on the server.
|
||||
|
||||
Then, to deploy via login.neuf.no, add the following to your personal ~/.ssh/config
|
||||
|
||||
Host lynx.neuf.no
|
||||
User gitdeploy
|
||||
ForwardAgent yes
|
||||
ProxyCommand ssh -W %h:%p login.neuf.no -l USERNAME
|
||||
|
||||
Then you can do
|
||||
|
||||
fab deploy
|
||||
|
||||
|
||||
# TODO
|
||||
- Fabfile with deploy task
|
||||
- Alias should only allow unique (source,destination) tuples
|
||||
|
||||
# TODO later
|
||||
|
||||
Vendored
+63
@@ -0,0 +1,63 @@
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from contextlib import contextmanager as _contextmanager
|
||||
from fabric.api import run, sudo, env, cd, prefix, lcd
|
||||
from fabric.api import local as lrun
|
||||
|
||||
env.use_ssh_config = True
|
||||
env.hosts = ['lynx.neuf.no']
|
||||
env.project_path = '/var/www/neuf.no/django-postfix-dovecot-api'
|
||||
env.user = 'gitdeploy'
|
||||
env.activate = 'source {}/venv/bin/activate'.format(env.project_path)
|
||||
|
||||
|
||||
@_contextmanager
|
||||
def virtualenv():
|
||||
with cd(env.project_path):
|
||||
with prefix(env.activate):
|
||||
yield
|
||||
|
||||
|
||||
def __git_validate_clean():
|
||||
with lcd(env.project_path):
|
||||
if lrun('git diff-files', capture=True) != '':
|
||||
logging.error("Your git-tree isn't clean! Commit your changes before deploying.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def test():
|
||||
lrun("python manage.py test dpdapi")
|
||||
|
||||
|
||||
def commit():
|
||||
lrun("git add -p && git commit")
|
||||
|
||||
|
||||
def push():
|
||||
lrun("git push")
|
||||
|
||||
|
||||
def prepare_deploy():
|
||||
test()
|
||||
commit()
|
||||
push()
|
||||
|
||||
|
||||
def gitstatus():
|
||||
# __git_validate_clean()
|
||||
with virtualenv():
|
||||
# Get source
|
||||
run('git branch -v')
|
||||
|
||||
|
||||
def deploy():
|
||||
# __git_validate_clean()
|
||||
with virtualenv():
|
||||
run('git pull') # Get source
|
||||
run('pip install -r requirements.txt') # install deps in virtualenv
|
||||
run('python manage.py collectstatic --noinput') # Collect static
|
||||
run('python manage.py migrate') # Run DB migrations
|
||||
|
||||
# Reload gunicorn
|
||||
sudo('/etc/init.d/gunicorn reload', shell=False)
|
||||
@@ -4,3 +4,4 @@ django-filter==0.9.1
|
||||
djangorestframework>=3.0,<3.1
|
||||
passlib==1.6.2
|
||||
mysqlclient==1.3.4
|
||||
Fabric==1.10.1
|
||||
Reference in new issue
Block a user