Add fabric bundle for 'theo-server'
This commit is contained in:
parent
9e275a35f8
commit
a26e3088c5
23 changed files with 1032 additions and 0 deletions
13
machines/theo-server/deploy/rattail/freetds.conf.mako
Normal file
13
machines/theo-server/deploy/rattail/freetds.conf.mako
Normal file
|
@ -0,0 +1,13 @@
|
|||
## -*- mode: conf; -*-
|
||||
|
||||
[catapult-default]
|
||||
host = ${env.catapult_host}
|
||||
port = 2638
|
||||
tds version = 5.0
|
||||
# this is to allow for product images up to 8MB
|
||||
text size = 8388608
|
||||
|
||||
# [catapult-tj-default]
|
||||
# host = ${env.catapult_host}
|
||||
# port = 2641
|
||||
# tds version = 5.0
|
12
machines/theo-server/deploy/rattail/odbc.ini
Normal file
12
machines/theo-server/deploy/rattail/odbc.ini
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
[catapult-default]
|
||||
Description = ECRS Catapult
|
||||
Driver = /usr/local/lib/libtdsodbc.so
|
||||
ServerName = catapult-default
|
||||
ServerDSN = prototype
|
||||
|
||||
# [catapult-tj-default]
|
||||
# Description = ECRS Catapult Transaction Journal
|
||||
# Driver = /usr/local/lib/libtdsodbc.so
|
||||
# ServerName = catapult-tj-default
|
||||
# ServerDSN = tj
|
103
machines/theo-server/deploy/rattail/rattail.conf.mako
Normal file
103
machines/theo-server/deploy/rattail/rattail.conf.mako
Normal file
|
@ -0,0 +1,103 @@
|
|||
## -*- mode: conf; -*-
|
||||
|
||||
######################################################################
|
||||
#
|
||||
# machine-wide rattail config
|
||||
#
|
||||
######################################################################
|
||||
|
||||
|
||||
##############################
|
||||
# rattail
|
||||
##############################
|
||||
|
||||
[rattail]
|
||||
timezone.default = ${env.timezone}
|
||||
|
||||
[rattail.config]
|
||||
configure_logging = true
|
||||
|
||||
[rattail.mail]
|
||||
smtp.server = localhost
|
||||
templates = rattail:templates/mail
|
||||
default.from = ${env.email_default_sender}
|
||||
default.to = ${', '.join(env.email_default_recipients)}
|
||||
|
||||
[rattail.pod]
|
||||
pictures.gtin.root_url = https://rattailproject.org/pod/pictures/gtin
|
||||
|
||||
|
||||
##############################
|
||||
# logging
|
||||
##############################
|
||||
|
||||
[loggers]
|
||||
keys = root, exc_logger, beaker, txn, sqlalchemy, django_db, flufl_bounce, requests
|
||||
|
||||
[handlers]
|
||||
keys = file, console, email
|
||||
|
||||
[formatters]
|
||||
keys = generic, console
|
||||
|
||||
[logger_root]
|
||||
handlers = file, console
|
||||
level = DEBUG
|
||||
|
||||
[logger_exc_logger]
|
||||
qualname = exc_logger
|
||||
handlers = email
|
||||
level = ERROR
|
||||
|
||||
[logger_beaker]
|
||||
qualname = beaker
|
||||
handlers =
|
||||
level = INFO
|
||||
|
||||
[logger_txn]
|
||||
qualname = txn
|
||||
handlers =
|
||||
level = INFO
|
||||
|
||||
[logger_sqlalchemy]
|
||||
qualname = sqlalchemy.engine
|
||||
handlers =
|
||||
# level = INFO
|
||||
|
||||
[logger_django_db]
|
||||
qualname = django.db.backends
|
||||
handlers =
|
||||
level = INFO
|
||||
|
||||
[logger_flufl_bounce]
|
||||
qualname = flufl.bounce
|
||||
handlers =
|
||||
level = WARNING
|
||||
|
||||
[logger_requests]
|
||||
qualname = requests
|
||||
handlers =
|
||||
# level = WARNING
|
||||
|
||||
[handler_file]
|
||||
class = handlers.WatchedFileHandler
|
||||
args = ('rattail.log', 'a', 'utf_8')
|
||||
formatter = generic
|
||||
|
||||
[handler_console]
|
||||
class = StreamHandler
|
||||
args = (sys.stderr,)
|
||||
formatter = console
|
||||
|
||||
[handler_email]
|
||||
class = handlers.SMTPHandler
|
||||
args = ('localhost', '${env.email_default_sender}', ${env.email_default_recipients}, "[Rattail] Logging")
|
||||
formatter = generic
|
||||
level = ERROR
|
||||
|
||||
[formatter_generic]
|
||||
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(funcName)s: %(message)s
|
||||
datefmt = %Y-%m-%d %H:%M:%S
|
||||
|
||||
[formatter_console]
|
||||
format = %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
|
26
machines/theo-server/deploy/theo-common/cron.conf.mako
Normal file
26
machines/theo-server/deploy/theo-common/cron.conf.mako
Normal 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')
|
11
machines/theo-server/deploy/theo-common/crontab.mako
Normal file
11
machines/theo-server/deploy/theo-common/crontab.mako
Normal 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
|
17
machines/theo-server/deploy/theo-common/import-catapult-first.sh.mako
Executable file
17
machines/theo-server/deploy/theo-common/import-catapult-first.sh.mako
Executable 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"
|
17
machines/theo-server/deploy/theo-common/import-corepos-first.sh.mako
Executable file
17
machines/theo-server/deploy/theo-common/import-corepos-first.sh.mako
Executable 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"
|
21
machines/theo-server/deploy/theo-common/logrotate.conf.mako
Normal file
21
machines/theo-server/deploy/theo-common/logrotate.conf.mako
Normal 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
|
||||
}
|
34
machines/theo-server/deploy/theo-common/overnight.sh.mako
Executable file
34
machines/theo-server/deploy/theo-common/overnight.sh.mako
Executable 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
|
10
machines/theo-server/deploy/theo-common/pip.conf.mako
Normal file
10
machines/theo-server/deploy/theo-common/pip.conf.mako
Normal 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
|
106
machines/theo-server/deploy/theo-common/rattail.conf.mako
Normal file
106
machines/theo-server/deploy/theo-common/rattail.conf.mako
Normal 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")
|
4
machines/theo-server/deploy/theo-common/sudoers.mako
Normal file
4
machines/theo-server/deploy/theo-common/sudoers.mako
Normal file
|
@ -0,0 +1,4 @@
|
|||
## -*- mode: conf; -*-
|
||||
|
||||
# let rattail upgrade ${envname} app
|
||||
rattail ALL = NOPASSWD: ${envroot}/app/upgrade-wrapper.sh --verbose
|
|
@ -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
|
9
machines/theo-server/deploy/theo-common/tasks.py.mako
Normal file
9
machines/theo-server/deploy/theo-common/tasks.py.mako
Normal 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')
|
19
machines/theo-server/deploy/theo-common/upgrade-wrapper.sh.mako
Executable file
19
machines/theo-server/deploy/theo-common/upgrade-wrapper.sh.mako
Executable 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' &
|
105
machines/theo-server/deploy/theo-common/upgrade.sh.mako
Executable file
105
machines/theo-server/deploy/theo-common/upgrade.sh.mako
Executable 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
|
66
machines/theo-server/deploy/theo-common/web.conf.mako
Normal file
66
machines/theo-server/deploy/theo-common/web.conf.mako
Normal 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')
|
Loading…
Add table
Add a link
Reference in a new issue