Add fabric bundle for 'theo-server'

This commit is contained in:
Lance Edgar 2020-09-19 18:55:17 -05:00
parent 9e275a35f8
commit a26e3088c5
23 changed files with 1032 additions and 0 deletions

View file

@ -0,0 +1,26 @@
## -*- mode: conf; -*-
<%text>############################################################</%text>
#
# cron config for Theo
#
<%text>############################################################</%text>
<%text>####################</%text>
# rattail
<%text>####################</%text>
[rattail.config]
include = %(here)s/rattail.conf
<%text>####################</%text>
# logging
<%text>####################</%text>
[handler_console]
level = WARNING
[handler_file]
args = ('${envroot}/app/log/cron.log', 'a', 'utf_8')

View file

@ -0,0 +1,11 @@
## -*- mode: conf; -*-
<%text>############################################################</%text>
#
# cron schedule for ${envname}
#
<%text>############################################################</%text>
# overnight automation starts at ${pretty_time}
${'' if env.machine_is_live else '# '}${cron_time} * * * rattail ${envroot}/app/overnight.sh

View file

@ -0,0 +1,17 @@
#!/bin/sh -e
# sanity check
if [ "$USER" != 'rattail' ]; then
echo ''
echo "Please run this script as 'rattail' user:"
echo ''
echo " sudo -u rattail $0"
exit 1
fi
cd ${envroot}
RATTAIL='bin/rattail -c app/quiet.conf -P'
$RATTAIL import-catapult --no-versioning --warnings
$RATTAIL import-versions --runas catapult --warnings -m "initial data from Catapult"

View file

@ -0,0 +1,17 @@
#!/bin/sh -e
# sanity check
if [ "$USER" != 'rattail' ]; then
echo ''
echo "Please run this script as 'rattail' user:"
echo ''
echo " sudo -u rattail $0"
exit 1
fi
cd ${envroot}
RATTAIL='bin/rattail -c app/quiet.conf -P'
$RATTAIL import-corepos-api --no-versioning --warnings
$RATTAIL import-versions --runas corepos --warnings -m "initial data from CORE-POS"

View file

@ -0,0 +1,21 @@
## -*- mode: conf; -*-
${envroot}/pip.log {
compress
create 600 rattail rattail
delaycompress
missingok
notifempty
rotate 10
size 10M
}
${envroot}/app/log/*.log {
daily
missingok
rotate 30
compress
delaycompress
notifempty
create 600 rattail rattail
}

View file

@ -0,0 +1,34 @@
#!/bin/sh -e
<%text>############################################################</%text>
#
# overnight automation for Theo
#
<%text>############################################################</%text>
if [ "$1" = "--verbose" ]; then
VERBOSE='--verbose'
PROGRESS='--progress'
else
VERBOSE=
PROGRESS=
fi
cd ${envroot}
RATTAIL="bin/rattail --config=app/cron.conf $PROGRESS"
<%text>##############################</%text>
# sync data
<%text>##############################</%text>
% if env.theo_integrates_with == 'corepos':
# CORE-POS -> Theo
$RATTAIL --runas corepos import-corepos-api --delete
% elif env.theo_integrates_with == 'catapult':
# Catapult -> Theo
$RATTAIL --runas catapult import-catapult --delete
% endif
# make sure version data is correct
$RATTAIL --runas theo import-versions --delete --dry-run --warnings

View file

@ -0,0 +1,10 @@
## -*- mode: conf; -*-
[global]
extra-index-url =
https://pypi.rattailproject.org/simple/
% if env.theo_integrates_with == 'catapult':
https://${env.restricted_pypi_username}:${env.restricted_pypi_password}@pypi-restricted.rattailproject.org/catapult/
% endif
log-file = ${envroot}/pip.log
exists-action = i

View file

@ -0,0 +1,106 @@
## -*- mode: conf; -*-
<%text>############################################################</%text>
#
# core config for Theo
#
<%text>############################################################</%text>
[theo]
% if env.theo_integrates_with == 'corepos':
integrate_corepos = true
% elif env.theo_integrates_with == 'catapult':
integrate_catapult = true
% endif
## begin corepos
% if env.theo_integrates_with == 'corepos':
<%text>##############################</%text>
# CORE-POS
<%text>##############################</%text>
[corepos]
office.url = ${env.corepos_office_url}
[corepos.api]
url = ${env.corepos_api_url}
[corepos.db.office_op]
default.url = mysql+mysqlconnector://${env.corepos_db_username}:${env.corepos_db_password}@${env.corepos_db_host}/${env.corepos_db_name_office_op}
default.pool_recycle = 3600
## end corepos
% endif
## begin catapult
% if env.theo_integrates_with == 'catapult':
<%text>##############################</%text>
# Catapult
<%text>##############################</%text>
[catapult.db]
default.url = catapult://${env.catapult_odbc_username}:${env.catapult_odbc_password}@catapult-default
## end catapult
% endif
<%text>##############################</%text>
# rattail
<%text>##############################</%text>
[rattail]
production = ${'true' if production else 'false'}
appdir = ${envroot}/app
datadir = ${envroot}/app/data
batch.files = ${envroot}/app/batch
workdir = ${envroot}/app/work
runas.default = theo
[rattail.config]
include = /etc/rattail/rattail.conf
usedb = true
preferdb = true
[rattail.db]
default.url = postgresql://rattail:${env.password_postgresql_rattail}@localhost/${dbname}
versioning.enabled = true
[rattail.mail]
send_emails = true
default.prefix = [Theo]
[rattail.upgrades]
command = sudo ${envroot}/app/upgrade-wrapper.sh --verbose
files = ${envroot}/app/data/upgrades
<%text>##############################</%text>
# alembic
<%text>##############################</%text>
[alembic]
script_location = rattail.db:alembic
% if env.theo_integrates_with == 'corepos':
version_locations = rattail_corepos.db:alembic/versions rattail.db:alembic/versions
% elif env.theo_integrates_with == 'catapult':
version_locations = rattail_onager.db:alembic/versions rattail.db:alembic/versions
% else:
version_locations = rattail.db:alembic/versions
% endif
<%text>##############################</%text>
# logging
<%text>##############################</%text>
[handler_file]
args = ('${envroot}/app/log/rattail.log', 'a', 'utf_8')
[handler_email]
args = ('localhost', '${env.email_default_sender}', ${env.email_default_recipients}, "[Theo${'' if production else ' (stage)'}] Logging")

View file

@ -0,0 +1,4 @@
## -*- mode: conf; -*-
# let rattail upgrade ${envname} app
rattail ALL = NOPASSWD: ${envroot}/app/upgrade-wrapper.sh --verbose

View file

@ -0,0 +1,9 @@
## -*- mode: conf; -*-
[group:${safename}]
programs=${safename}_webmain
[program:${safename}_webmain]
command=${envroot}/bin/pserve pastedeploy+ini:${envroot}/app/web.conf
directory=${envroot}/app/work
user=rattail

View file

@ -0,0 +1,9 @@
## -*- coding: utf-8; mode: python; -*-
# -*- coding: utf-8; -*-
from invoke import task
@task
def upgrade(ctx):
ctx.run('${envroot}/app/upgrade.sh --verbose')

View file

@ -0,0 +1,19 @@
#!/bin/sh -e
if [ "$1" = "--verbose" ]; then
VERBOSE='--verbose'
INVOKE_ARGS='--echo'
else
VERBOSE=
INVOKE_ARGS=
fi
cd ${envroot}
INVOKE="sudo -H -u rattail bin/invoke --collection=app/tasks $INVOKE_ARGS"
# run upgrade task, as rattail user
$INVOKE upgrade
# restart web app
sh -c 'sleep 10; supervisorctl restart ${safename}:${safename}_webmain' &

View file

@ -0,0 +1,105 @@
#!/bin/sh -e
# NOTE: this script is meant to be ran by the 'rattail' user!
if [ "$1" = "--verbose" ]; then
VERBOSE='--verbose'
QUIET=
else
VERBOSE=
QUIET='--quiet'
fi
% if not production:
SRC=${envroot}/src
% endif
PIP=${envroot}/bin/pip
export PIP_CONFIG_FILE=${envroot}/pip.conf
# upgrade pip
$PIP install $QUIET --disable-pip-version-check --upgrade pip wheel
% if not production:
# now we fetch latest source code and install any "new" dependencies...
# rattail
cd $SRC/rattail
git pull $QUIET
find . -name '*.pyc' -delete
$PIP install $QUIET --editable .
# tailbone
cd $SRC/tailbone
git pull $QUIET
find . -name '*.pyc' -delete
$PIP install $QUIET --editable .
## begin corepos
% if env.theo_integrates_with == 'corepos':
# pycorepos
cd $SRC/pycorepos
git pull $QUIET
find . -name '*.pyc' -delete
$PIP install $QUIET --editable .
# rattail-corepos
cd $SRC/rattail-corepos
git pull $QUIET
find . -name '*.pyc' -delete
$PIP install $QUIET --editable .
# tailbone-corepos
cd $SRC/tailbone-corepos
git pull $QUIET
find . -name '*.pyc' -delete
$PIP install $QUIET --editable .
## end corepos
% endif
## begin catapult
% if env.theo_integrates_with == 'catapult':
# onager
cd $SRC/onager
git pull $QUIET
find . -name '*.pyc' -delete
$PIP install $QUIET --editable .
# rattail-onager
cd $SRC/rattail-onager
git pull $QUIET
find . -name '*.pyc' -delete
$PIP install $QUIET --editable .
# tailbone-onager
cd $SRC/tailbone-onager
git pull $QUIET
find . -name '*.pyc' -delete
$PIP install $QUIET --editable .
## end catapult
% endif
# theo
cd $SRC/theo
git pull $QUIET
find . -name '*.pyc' -delete
$PIP install $QUIET --editable .
## end !production
% endif
# now upgrade *all* dependencies
% if env.theo_integrates_with == 'corepos':
$PIP install $QUIET --upgrade --upgrade-strategy eager tailbone-theo[app,corepos]
% elif env.theo_integrates_with == 'catapult':
$PIP install $QUIET --upgrade --upgrade-strategy eager tailbone-theo[app,catapult]
% else:
$PIP install $QUIET --upgrade --upgrade-strategy eager tailbone-theo[app]
% endif
# migrate database schema
cd ${envroot}
bin/alembic --config app/rattail.conf upgrade heads

View file

@ -0,0 +1,66 @@
## -*- mode: conf; -*-
<%text>############################################################</%text>
#
# config for Theo web app
#
<%text>############################################################</%text>
<%text>###############################</%text>
# rattail
<%text>###############################</%text>
[rattail.config]
include = %(here)s/rattail.conf
<%text>###############################</%text>
# pyramid
<%text>###############################</%text>
[app:main]
use = egg:Tailbone_Theo
pyramid.reload_templates = false
pyramid.debug_all = false
pyramid.default_locale_name = en
pyramid.includes = pyramid_exclog
beaker.session.type = file
beaker.session.data_dir = %(here)s/sessions/data
beaker.session.lock_dir = %(here)s/sessions/lock
beaker.session.secret = ${env.theo_beaker_secret}
beaker.session.key = ${dbname}
exclog.extra_info = true
# required for tailbone
rattail.config = %(__file__)s
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = ${port}
# NOTE: this is needed for local reverse proxy stuff to work with HTTPS
# https://docs.pylonsproject.org/projects/waitress/en/latest/reverse-proxy.html
# https://docs.pylonsproject.org/projects/waitress/en/latest/arguments.html
trusted_proxy = 127.0.0.1
# TODO: leave this empty if proxy serves as root site, e.g. http://rattail.example.com/
url_prefix =
# TODO: or, if proxy serves as subpath of root site, e.g. http://rattail.example.com/backend/
# url_prefix = /backend
<%text>###############################</%text>
# logging
<%text>###############################</%text>
[handler_console]
level = INFO
[handler_file]
args = ('${envroot}/app/log/web.log', 'a', 'utf_8')