Make deploy.backup_app()
more generic
so e.g. can install borg but skip rattail
This commit is contained in:
parent
68088a6e71
commit
5a9035ffd3
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2018 Lance Edgar
|
# Copyright © 2010-2019 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,12 +24,10 @@
|
||||||
Fabric library for Backup app
|
Fabric library for Backup app
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals, absolute_import
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from rattail_fabric2 import python, exists, make_deploy, mkdir, UNSPECIFIED
|
from rattail_fabric2 import borg, python, exists, make_deploy, mkdir, UNSPECIFIED
|
||||||
|
|
||||||
|
|
||||||
deploy_generic = make_deploy(__file__)
|
deploy_generic = make_deploy(__file__)
|
||||||
|
@ -55,13 +53,18 @@ def deploy_backup_everything(c, **context):
|
||||||
|
|
||||||
|
|
||||||
def deploy_backup_app(c, deploy, envname, mkvirtualenv=True, user='rattail',
|
def deploy_backup_app(c, deploy, envname, mkvirtualenv=True, user='rattail',
|
||||||
config=None, context={}, everything=None,
|
install_borg=False,
|
||||||
|
install_rattail=True,
|
||||||
|
config=None,
|
||||||
rattail_backup_script=None,
|
rattail_backup_script=None,
|
||||||
crontab=None, runat=UNSPECIFIED):
|
everything=None,
|
||||||
|
crontab=None,
|
||||||
|
runat=UNSPECIFIED,
|
||||||
|
context={}):
|
||||||
"""
|
"""
|
||||||
Make an app which can run backups for the server.
|
Make an app which can run backups for the server.
|
||||||
"""
|
"""
|
||||||
if not config:
|
if install_rattail and not config:
|
||||||
path = '{}/rattail.conf.mako'.format(envname)
|
path = '{}/rattail.conf.mako'.format(envname)
|
||||||
if deploy.local_exists(path):
|
if deploy.local_exists(path):
|
||||||
config = path
|
config = path
|
||||||
|
@ -72,50 +75,72 @@ def deploy_backup_app(c, deploy, envname, mkvirtualenv=True, user='rattail',
|
||||||
else:
|
else:
|
||||||
raise ValueError("Must provide config path for backup app")
|
raise ValueError("Must provide config path for backup app")
|
||||||
|
|
||||||
if runat is UNSPECIFIED:
|
if install_borg:
|
||||||
runat = datetime.time(0) # defaults to midnight
|
borg.install_dependencies(c)
|
||||||
|
|
||||||
# virtualenv
|
# virtualenv
|
||||||
if mkvirtualenv:
|
if mkvirtualenv:
|
||||||
python.mkvirtualenv(c, envname, python='/usr/bin/python3')
|
python.mkvirtualenv(c, envname, python='/usr/bin/python3',
|
||||||
|
# TODO: need to determine if this is safe to add?
|
||||||
|
# runas_user=user
|
||||||
|
)
|
||||||
envpath = '/srv/envs/{}'.format(envname)
|
envpath = '/srv/envs/{}'.format(envname)
|
||||||
c.sudo('chown -R {}: {}'.format(user, envpath))
|
c.sudo('chown -R {}: {}'.format(user, envpath))
|
||||||
mkdir(c, os.path.join(envpath, 'src'), use_sudo=True, runas_user=user)
|
mkdir(c, os.path.join(envpath, 'src'), use_sudo=True, runas_user=user)
|
||||||
c.sudo("bash -l -c 'workon {} && pip install --upgrade pip'".format(envname), user=user)
|
c.sudo("bash -l -c 'workon {} && pip install --upgrade pip'".format(envname), user=user)
|
||||||
|
|
||||||
# rattail
|
if install_rattail:
|
||||||
if not exists(c, os.path.join(envpath, 'src/rattail')):
|
|
||||||
c.sudo('git clone https://rattailproject.org/git/rattail.git {}/src/rattail'.format(envpath), user=user)
|
|
||||||
c.sudo("bash -l -c 'cd {}/src/rattail && git pull'".format(envpath), user=user)
|
|
||||||
deploy_generic(c, 'backup/git-exclude', os.path.join(envpath, 'src/rattail/.git/info/exclude'), use_sudo=True, owner=user)
|
|
||||||
c.sudo("bash -l -c 'workon {} && cdvirtualenv && bin/pip install --upgrade --upgrade-strategy eager src/rattail'".format(envname), user=user)
|
|
||||||
|
|
||||||
# config
|
# rattail
|
||||||
c.sudo("bash -l -c 'workon {} && cdvirtualenv && rattail make-appdir'".format(envname), user=user)
|
if not exists(c, os.path.join(envpath, 'src/rattail')):
|
||||||
deploy(c, config, os.path.join(envpath, 'app/rattail.conf'), owner=user, mode='0600', use_sudo=True, context=context)
|
c.sudo('git clone https://rattailproject.org/git/rattail.git {}/src/rattail'.format(envpath), user=user)
|
||||||
c.sudo("bash -l -c 'workon {} && cdvirtualenv && bin/rattail -c app/rattail.conf make-config -T quiet -O app/'".format(envname), user=user)
|
c.sudo("bash -l -c 'workon {} && cdvirtualenv && bin/pip install --editable src/rattail'".format(envname), user=user)
|
||||||
c.sudo("bash -l -c 'workon {} && cdvirtualenv && bin/rattail -c app/rattail.conf make-config -T silent -O app/'".format(envname), user=user)
|
deploy_generic(c, 'backup/git-exclude', os.path.join(envpath, 'src/rattail/.git/info/exclude'), use_sudo=True, owner=user)
|
||||||
|
|
||||||
# rattail-backup script
|
# config
|
||||||
script_context = dict(context)
|
c.sudo("bash -l -c 'workon {} && cdvirtualenv && rattail make-appdir'".format(envname), user=user)
|
||||||
script_context['envname'] = envname
|
deploy(c, config, os.path.join(envpath, 'app/rattail.conf'), owner=user, mode='0600', use_sudo=True, context=context)
|
||||||
if rattail_backup_script:
|
c.sudo("bash -l -c 'workon {} && cdvirtualenv && bin/rattail -c app/rattail.conf make-config -T quiet -O app/'".format(envname), user=user)
|
||||||
deploy(c, rattail_backup_script, '/usr/local/bin/rattail-backup', mode='0700', use_sudo=True,
|
c.sudo("bash -l -c 'workon {} && cdvirtualenv && bin/rattail -c app/rattail.conf make-config -T silent -O app/'".format(envname), user=user)
|
||||||
context=script_context)
|
|
||||||
else:
|
# rattail-backup script
|
||||||
deploy_rattail_backup_script(c, **script_context)
|
script_context = dict(context)
|
||||||
|
script_context['envname'] = envname
|
||||||
|
if rattail_backup_script:
|
||||||
|
deploy(c, rattail_backup_script, '/usr/local/bin/rattail-backup', mode='0700', use_sudo=True,
|
||||||
|
context=script_context)
|
||||||
|
else:
|
||||||
|
deploy_rattail_backup_script(c, **script_context)
|
||||||
|
|
||||||
|
# borg
|
||||||
|
if install_borg:
|
||||||
|
if install_rattail:
|
||||||
|
packages = [
|
||||||
|
'rattail[backup]',
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
# these should be same as rattail[backup]
|
||||||
|
packages = [
|
||||||
|
'msgpack',
|
||||||
|
'borgbackup',
|
||||||
|
'llfuse==1.3.4',
|
||||||
|
]
|
||||||
|
c.sudo("bash -l -c 'workon {} && cdvirtualenv && bin/pip install {}'".format(envname, ' '.join(packages)), user=user)
|
||||||
|
|
||||||
# backup-everything script
|
# backup-everything script
|
||||||
everything_context = dict(context)
|
if install_rattail or everything:
|
||||||
everything_context['envname'] = envname
|
everything_context = dict(context)
|
||||||
everything_context['user'] = user
|
everything_context['envname'] = envname
|
||||||
if everything:
|
everything_context['user'] = user
|
||||||
deploy(c, everything, '/usr/local/bin/backup-everything', mode='0700', context=everything_context, use_sudo=True)
|
if everything:
|
||||||
else:
|
deploy(c, everything, '/usr/local/bin/backup-everything', mode='0700', context=everything_context, use_sudo=True)
|
||||||
deploy_backup_everything(c, **everything_context)
|
else:
|
||||||
|
deploy_backup_everything(c, **everything_context)
|
||||||
|
|
||||||
# crontab
|
# crontab
|
||||||
if runat:
|
if runat is UNSPECIFIED:
|
||||||
|
runat = datetime.time(0) # defaults to midnight
|
||||||
|
if runat is not None and (install_rattail or everything):
|
||||||
crontab_context = dict(context)
|
crontab_context = dict(context)
|
||||||
crontab_context['envname'] = envname
|
crontab_context['envname'] = envname
|
||||||
crontab_context['pretty_time'] = runat.strftime('%I:%M %p')
|
crontab_context['pretty_time'] = runat.strftime('%I:%M %p')
|
||||||
|
|
Loading…
Reference in a new issue