mirror of
https://github.com/status-im/cabot.git
synced 2025-02-24 18:38:07 +00:00
a few improvements for deployment code in fabfile
This commit is contained in:
parent
caa4bb5c3c
commit
ad9f7394a2
31
fabfile.py
vendored
31
fabfile.py
vendored
@ -29,8 +29,10 @@ def _ensure_dirs():
|
|||||||
|
|
||||||
def _setup_venv():
|
def _setup_venv():
|
||||||
with settings(warn_only=True):
|
with settings(warn_only=True):
|
||||||
if sudo('test -d %s' % VENV_DIR).failed:
|
venv_doesnt_exist = sudo('test -d %s' % VENV_DIR).failed
|
||||||
sudo('virtualenv %s' % VENV_DIR)
|
if venv_doesnt_exist:
|
||||||
|
# without --setuptools, you get `pkg_resources not found` error
|
||||||
|
sudo('virtualenv --setuptools %s' % VENV_DIR, user='ubuntu')
|
||||||
|
|
||||||
|
|
||||||
def install_requirements(deploy_path=DEPLOY_PATH):
|
def install_requirements(deploy_path=DEPLOY_PATH):
|
||||||
@ -42,7 +44,7 @@ def run_migrations(deploy_path=DEPLOY_PATH):
|
|||||||
with cd(deploy_path):
|
with cd(deploy_path):
|
||||||
with prefix("source {venv}/bin/activate".format(venv=VENV_DIR)):
|
with prefix("source {venv}/bin/activate".format(venv=VENV_DIR)):
|
||||||
sudo(
|
sudo(
|
||||||
"foreman run -e conf/{env}.env python manage.py syncdb".format(env=env.deploy_version))
|
"foreman run -e conf/{env}.env python manage.py syncdb --noinput".format(env=env.deploy_version))
|
||||||
sudo(
|
sudo(
|
||||||
"foreman run -e conf/{env}.env python manage.py migrate cabotapp --noinput".format(env=env.deploy_version))
|
"foreman run -e conf/{env}.env python manage.py migrate cabotapp --noinput".format(env=env.deploy_version))
|
||||||
# Wrap in failure for legacy reasons
|
# Wrap in failure for legacy reasons
|
||||||
@ -53,6 +55,25 @@ def run_migrations(deploy_path=DEPLOY_PATH):
|
|||||||
"foreman run -e conf/{env}.env python manage.py migrate djcelery --noinput".format(env=env.deploy_version))
|
"foreman run -e conf/{env}.env python manage.py migrate djcelery --noinput".format(env=env.deploy_version))
|
||||||
|
|
||||||
|
|
||||||
|
def create_user(username, password, email):
|
||||||
|
""" creates a django user on the cabot server. existing users
|
||||||
|
are clobbered so this also functions as a crude password reset.
|
||||||
|
"""
|
||||||
|
code = (
|
||||||
|
"""username='{username}';"""
|
||||||
|
"""password='{password}';"""
|
||||||
|
"""email='{email}';"""
|
||||||
|
"""from django.contrib.auth.models import User;"""
|
||||||
|
"""User.objects.filter(username=username).delete();"""
|
||||||
|
"""User.objects.create_superuser(username, email, password);""")
|
||||||
|
code = code.format(username=username, password=password, email=email)
|
||||||
|
shell_cmd = "foreman run -e conf/production.env python manage.py shell"
|
||||||
|
with prefix("source ~ubuntu/venv/bin/activate"):
|
||||||
|
with cd("~ubuntu/cabot"):
|
||||||
|
sudo('printf "{0}"|{1}'.format(code, shell_cmd))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def collect_static(deploy_path=DEPLOY_PATH):
|
def collect_static(deploy_path=DEPLOY_PATH):
|
||||||
with cd(deploy_path):
|
with cd(deploy_path):
|
||||||
with prefix("source {venv}/bin/activate".format(venv=VENV_DIR)):
|
with prefix("source {venv}/bin/activate".format(venv=VENV_DIR)):
|
||||||
@ -82,7 +103,8 @@ def production():
|
|||||||
|
|
||||||
def restart():
|
def restart():
|
||||||
with settings(warn_only=True):
|
with settings(warn_only=True):
|
||||||
if sudo('restart cabot').failed:
|
restart_failed = sudo('restart cabot').failed
|
||||||
|
if restart_failed:
|
||||||
sudo('start cabot')
|
sudo('start cabot')
|
||||||
|
|
||||||
|
|
||||||
@ -123,6 +145,7 @@ def deploy(deploy_version=None):
|
|||||||
rsync_project(
|
rsync_project(
|
||||||
remote_dir=deploy_path,
|
remote_dir=deploy_path,
|
||||||
local_dir='./',
|
local_dir='./',
|
||||||
|
ssh_opts='-o StrictHostKeyChecking=no',
|
||||||
exclude=['.git', 'backups', 'venv',
|
exclude=['.git', 'backups', 'venv',
|
||||||
'static/CACHE', '.vagrant', '*.pyc', 'dev.db'],
|
'static/CACHE', '.vagrant', '*.pyc', 'dev.db'],
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user