mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-15 23:32:17 +00:00
Remove unneeded scripts, updated fabric file
This commit is contained in:
@@ -3,7 +3,7 @@ import sys
|
|||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
pwd = os.path.dirname(os.path.abspath(__file__))
|
pwd = os.path.dirname(os.path.abspath(__file__))
|
||||||
activate_this = os.path.join(pwd,'..', 'env','bin','activate_this.py')
|
activate_this = os.path.join(pwd,'..', '.env','bin','activate_this.py')
|
||||||
try:
|
try:
|
||||||
execfile(activate_this, dict(__file__=activate_this))
|
execfile(activate_this, dict(__file__=activate_this))
|
||||||
except IOError:
|
except IOError:
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
rm -rf ./env
|
|
||||||
virtualenv --distribute --no-site-packages env
|
|
||||||
. ./env/bin/activate
|
|
||||||
pip install -r requirements.txt
|
|
||||||
273
fabfile.py
vendored
273
fabfile.py
vendored
@@ -2,229 +2,168 @@ from __future__ import with_statement
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
from fabric.api import *
|
from fabric.api import cd, run, require, prefix, env, task, local
|
||||||
from fabric.contrib.files import *
|
from fabric.contrib.files import exists
|
||||||
from fabric.utils import warn
|
from fabric.utils import warn
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
|
|
||||||
|
env.shell = '/bin/bash -l -c'
|
||||||
|
env.workers = []
|
||||||
env.repo = 'git://dev.pleaseignore.com/dreddit-auth.git'
|
env.repo = 'git://dev.pleaseignore.com/dreddit-auth.git'
|
||||||
|
|
||||||
|
@task(alias='prod')
|
||||||
def production():
|
def production():
|
||||||
"Use the production enviroment on Web1"
|
"""Use the production enviroment on Web1"""
|
||||||
env.hosts = ['dreddit@web1.pleaseignore.com']
|
env.hosts = ['dreddit@web1.pleaseignore.com']
|
||||||
env.path = '/home/dreddit/apps'
|
env.path = '/home/dreddit/apps/dreddit-auth'
|
||||||
env.user = 'auth'
|
|
||||||
env.vhost = '/auth'
|
|
||||||
env.config = 'conf.production'
|
env.config = 'conf.production'
|
||||||
env.uwsgiconfig = os.path.join(env.path, '..', 'etc', 'uwsgi', 'dreddit-auth.ini')
|
env.uwsgiconfig = os.path.join(env.path, '..', '..', 'etc', 'uwsgi', 'dreddit-auth.ini')
|
||||||
env.password = sha1('%s-%s' % (env.user, env.vhost)).hexdigest()
|
|
||||||
|
|
||||||
env.celeryconf = '-l INFO --settings=%(config)s --pidfile=logs/%%n.pid --logfile=logs/%%n.log -n auth.pleaseignore.com bulk default fastresponse -Q:bulk bulk -Q:fastresponse fastresponse -c 5 -c:bulk 3 -c:fastresponse 3 -B:default --scheduler=djcelery.schedulers.DatabaseScheduler' % env
|
env.celeryconf = '-l INFO --settings=%(config)s --pidfile=logs/%%n.pid --logfile=logs/%%n.log -n auth.pleaseignore.com bulk default fastresponse -Q:bulk bulk -Q:fastresponse fastresponse -c 5 -c:bulk 3 -c:fastresponse 3 -B:default --scheduler=djcelery.schedulers.DatabaseScheduler' % env
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
def test():
|
def test():
|
||||||
"Use the test enviroment on Web2"
|
"""Use the test enviroment on Web2"""
|
||||||
env.hosts = ['dreddit@web2.pleaseignore.com']
|
env.hosts = ['dreddit@web2.pleaseignore.com']
|
||||||
env.path = '/home/dreddit/apps'
|
env.path = '/home/dreddit/apps/dreddit-auth'
|
||||||
env.user = 'auth'
|
|
||||||
env.vhost = '/auth'
|
|
||||||
env.config = 'conf.test'
|
env.config = 'conf.test'
|
||||||
env.uwsgiconfig = os.path.join(env.path, '..', 'etc', 'uwsgi', 'dreddit-auth.ini')
|
env.uwsgiconfig = os.path.join(env.path, '..', 'etc', 'uwsgi', 'dreddit-auth.ini')
|
||||||
env.password = sha1('%s-%s' % (env.user, env.vhost)).hexdigest()
|
|
||||||
|
|
||||||
def deploy():
|
|
||||||
"""
|
|
||||||
Do a fresh deployment to a new or clean server
|
|
||||||
"""
|
|
||||||
setup()
|
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
@task
|
||||||
"""
|
def deploy(tag=None):
|
||||||
Deploy the files to the server and setup virtualenv and a simple
|
"""Deploy current HEAD in "master", or a tag is provided"""
|
||||||
SQlite DB setup
|
|
||||||
"""
|
|
||||||
require('hosts')
|
require('hosts')
|
||||||
require('path')
|
require('path')
|
||||||
|
|
||||||
deploy_repo()
|
git_update_repo(tag)
|
||||||
|
|
||||||
setup_virtualenv()
|
setup_virtualenv()
|
||||||
|
sync_db()
|
||||||
|
|
||||||
def push():
|
|
||||||
"""
|
|
||||||
Push the latest revision to the server and update the enviroment
|
|
||||||
"""
|
|
||||||
require('hosts')
|
|
||||||
require('path')
|
|
||||||
|
|
||||||
stop()
|
|
||||||
update_repo()
|
|
||||||
setup_virtualenv()
|
|
||||||
migrate()
|
|
||||||
start()
|
|
||||||
|
|
||||||
|
|
||||||
def setup_virtualenv():
|
|
||||||
"""
|
|
||||||
Generate the virtualenv enviroment
|
|
||||||
"""
|
|
||||||
require('path')
|
|
||||||
|
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
|
||||||
run('./bin/setup-env.sh' % env)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_db():
|
|
||||||
"""
|
|
||||||
Setup a simple SQlite DB using the default settings
|
|
||||||
"""
|
|
||||||
require('path')
|
|
||||||
|
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
|
||||||
run('env/bin/python app/manage.py syncdb --settings=%(config)s --noinput --migrate' % env)
|
|
||||||
|
|
||||||
|
|
||||||
def deploy_repo():
|
|
||||||
"""
|
|
||||||
Do the initial repository checkout
|
|
||||||
"""
|
|
||||||
require('hosts')
|
|
||||||
require('path')
|
|
||||||
|
|
||||||
run('mkdir -p %(path)s' % env)
|
|
||||||
with cd(env.path):
|
|
||||||
run('git clone %(repo)s' % env)
|
|
||||||
|
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
|
||||||
run('mkdir logs')
|
|
||||||
|
|
||||||
|
|
||||||
def update_repo():
|
|
||||||
"""
|
|
||||||
Pulls the latest commits to the repository
|
|
||||||
"""
|
|
||||||
require('hosts')
|
|
||||||
require('path')
|
|
||||||
|
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
|
||||||
run('git pull')
|
|
||||||
|
|
||||||
deploy_static()
|
deploy_static()
|
||||||
|
|
||||||
|
|
||||||
def reset_repo():
|
@task
|
||||||
"""
|
def restart():
|
||||||
Does a hard reset on the remote repo
|
"""Restart UWSGI and Celeryd"""
|
||||||
"""
|
restart_uwsgi()
|
||||||
require('hosts')
|
clear_logs()
|
||||||
require('path')
|
restart_celeryd()
|
||||||
|
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
|
||||||
|
@task(alias='update')
|
||||||
|
def git_update_repo(tag):
|
||||||
|
"""Update the server's repo from master"""
|
||||||
|
with cd('%(path)s' % env):
|
||||||
run('git reset --hard')
|
run('git reset --hard')
|
||||||
|
run('git fetch --all')
|
||||||
|
if tag:
|
||||||
|
run('git checkout %s' % tag)
|
||||||
|
else:
|
||||||
|
run('git checkout master')
|
||||||
|
|
||||||
|
|
||||||
def migrate():
|
@task(alias='virtualenv')
|
||||||
"""
|
def setup_virtualenv():
|
||||||
Do any South database migrations
|
"""Sets up and updates the virtualenv install"""
|
||||||
"""
|
require('path')
|
||||||
|
with cd('%(path)s' % env):
|
||||||
|
if not exists('.env'):
|
||||||
|
run('virtualenv --no-site-packages .env')
|
||||||
|
with prefix('source %(path)s/.env/bin/activate' % env):
|
||||||
|
run('pip install -r requirements.txt')
|
||||||
|
|
||||||
|
|
||||||
|
@task(alias='dbsync')
|
||||||
|
def sync_db():
|
||||||
|
"""Syncs the DB and completes any migrations"""
|
||||||
require('hosts')
|
require('hosts')
|
||||||
require('path')
|
require('path')
|
||||||
|
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
with cd('%(path)s' % env):
|
||||||
run('env/bin/python app/manage.py migrate --settings=%(config)s' % env)
|
with prefix('source %(path)s/.env/bin/activate' % env):
|
||||||
|
#run('app/manage.py syncdb --settings=%(config)s' % env)
|
||||||
|
update_permissions()
|
||||||
|
run('app/manage.py migrate --settings=%(config)s' % env)
|
||||||
|
|
||||||
|
|
||||||
|
@task(alias='static')
|
||||||
|
def deploy_static():
|
||||||
|
"""Deploys the static files to the defined location"""
|
||||||
|
with cd('%(path)s' % env):
|
||||||
|
with prefix('source %(path)s/.env/bin/activate' % env):
|
||||||
|
run('app/manage.py collectstatic --settings=%(config)s -v0 --noinput' % env)
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
def clear_logs():
|
||||||
|
"""Clears any old celeryd logs"""
|
||||||
|
with cd('%(path)s' % env):
|
||||||
|
run('rm ./logs/*.log')
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
|
def update_permissions():
|
||||||
|
"""Updates permissions that syncdb would of missed"""
|
||||||
|
with cd('%(path)s' % env):
|
||||||
|
with prefix('source %(path)s/.env/bin/activate' % env):
|
||||||
|
run('app/manage.py updatepermissions --settings=%(config)s' % env)
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
def start_celeryd():
|
def start_celeryd():
|
||||||
"""
|
"""Start the celeryd server"""
|
||||||
Start the celeryd server
|
|
||||||
"""
|
|
||||||
require('hosts')
|
require('hosts')
|
||||||
require('path')
|
require('path')
|
||||||
|
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
clear_logs()
|
||||||
run('. env/bin/activate; app/manage.py celeryd_multi start %(celeryconf)s' % env)
|
with cd('%(path)s' % env):
|
||||||
|
with prefix('source %(path)s/.env/bin/activate' % env):
|
||||||
|
run('app/manage.py celeryd_multi start %(celeryconf)s' % env)
|
||||||
|
|
||||||
|
@task
|
||||||
def stop_celeryd():
|
def stop_celeryd():
|
||||||
"""
|
"""Stop the celeryd server"""
|
||||||
Stop any running FCGI instance
|
|
||||||
"""
|
|
||||||
require('hosts')
|
require('hosts')
|
||||||
require('path')
|
require('path')
|
||||||
require('config')
|
require('config')
|
||||||
|
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
with cd('%(path)s' % env):
|
||||||
run('. env/bin/activate; app/manage.py celeryd_multi stop %(celeryconf)s' % env)
|
with prefix('source %(path)s/.env/bin/activate' % env):
|
||||||
|
run('app/manage.py celeryd_multi stop %(celeryconf)s' % env)
|
||||||
|
|
||||||
|
|
||||||
def kill_celeryd():
|
@task
|
||||||
"""
|
|
||||||
Kills all Celeryd instances
|
|
||||||
"""
|
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
|
||||||
run("ps auxww | grep celeryd | awk '{print $2}' | xargs kill -9")
|
|
||||||
|
|
||||||
def restart_celeryd():
|
def restart_celeryd():
|
||||||
"""
|
"""Restart the celery daemon"""
|
||||||
Restart the celery daemon
|
with cd('%(path)s' % env):
|
||||||
"""
|
with prefix('source %(path)s/.env/bin/activate' % env):
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
run('app/manage.py celeryd_multi restart %(celeryconf)s' % env)
|
||||||
run('. env/bin/activate; app/manage.py celeryd_multi restart %(celeryconf)s' % env)
|
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
def show_celeryd():
|
def show_celeryd():
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
with cd('%(path)s' % env):
|
||||||
run('. env/bin/activate; app/manage.py celeryd_multi show %(celeryconf)s' % env)
|
with prefix('source %(path)s/.env/bin/activate' % env):
|
||||||
|
run('app/manage.py celeryd_multi show %(celeryconf)s' % env)
|
||||||
|
|
||||||
def start_uwsgi():
|
|
||||||
"""
|
|
||||||
Start uWSGI
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
@task
|
||||||
def restart_uwsgi():
|
def restart_uwsgi():
|
||||||
"""
|
"""
|
||||||
Restart the uWSGI daemon
|
Restart the uWSGI daemon
|
||||||
"""
|
"""
|
||||||
run('touch %(uwsgiconfig)s' % env)
|
run('touch %(uwsgiconfig)s' % env)
|
||||||
|
|
||||||
|
###### Local Tasks
|
||||||
|
|
||||||
def start():
|
@task
|
||||||
"""
|
def runserver(port=3333):
|
||||||
Start uWSGI and Celery
|
with prefix('. .env/bin/activate'):
|
||||||
"""
|
local('app/manage.py runserver %s' % port, capture=False)
|
||||||
start_uwsgi()
|
|
||||||
start_celeryd()
|
@task
|
||||||
|
def test():
|
||||||
|
with prefix('. .env/bin/activate'):
|
||||||
|
local('app/manage.py test --noinput --failfast')
|
||||||
|
|
||||||
|
|
||||||
def stop():
|
|
||||||
"""
|
|
||||||
Stop Celery
|
|
||||||
"""
|
|
||||||
stop_celeryd()
|
|
||||||
info('Can\'t stop uWSGI')
|
|
||||||
|
|
||||||
def restart():
|
|
||||||
"""
|
|
||||||
Restart uWSGI and Celery
|
|
||||||
"""
|
|
||||||
stop_celeryd()
|
|
||||||
time.sleep(5)
|
|
||||||
restart_uwsgi()
|
|
||||||
start_celeryd()
|
|
||||||
|
|
||||||
def clear_logs():
|
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
|
||||||
run('rm ./logs/*.log')
|
|
||||||
|
|
||||||
def deploy_static():
|
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
|
||||||
run('./app/manage.py collectstatic --settings=%(config)s -v0 --noinput' % env)
|
|
||||||
|
|
||||||
def update_permissions():
|
|
||||||
with cd('%(path)s/dreddit-auth/' % env):
|
|
||||||
run('./app/manage.py updatepermissions --settings=%(config)s' % env)
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user