Parse the Fannie config file to get lane definitions for rattail.conf

when deploying Corporal via fabric
This commit is contained in:
Lance Edgar 2021-07-22 10:20:38 -05:00
parent 07857bf77c
commit ca3a9e5ea5
3 changed files with 68 additions and 2 deletions

View file

@ -3,13 +3,17 @@
Fabric library for Corporal systems Fabric library for Corporal systems
""" """
import os
import json
from rattail_fabric2 import apache, postgresql, python, exists, mkdir from rattail_fabric2 import apache, postgresql, python, exists, mkdir
from corporal.fablib import deploy_common from corporal.fablib import deploy_common
def bootstrap_corporal_app(c, env, envname='corporal', user='rattail', def bootstrap_corporal_app(c, env, envname='corporal', user='rattail',
port=7900, sitename=None, stage=False): port=7900, sitename=None, stage=False,
coredir=None, lanes=None):
""" """
Create a virtual environment for use with a Corporal app. Create a virtual environment for use with a Corporal app.
""" """
@ -93,10 +97,14 @@ def bootstrap_corporal_app(c, env, envname='corporal', user='rattail',
mkdir(c, '{}/data'.format(appdir), use_sudo=True, owner=user) mkdir(c, '{}/data'.format(appdir), use_sudo=True, owner=user)
# config / scripts # config / scripts
deploy_common(c, 'corporal/parse-fannie-config.php', '{}/parse-fannie-config.php'.format(appdir),
use_sudo=True, owner=user)
if lanes is None:
lanes = parse_fannie_lanes(c, '{}/parse-fannie-config.php'.format(appdir), coredir)
deploy_common(c, 'corporal/rattail.conf.mako', '{}/rattail.conf'.format(appdir), deploy_common(c, 'corporal/rattail.conf.mako', '{}/rattail.conf'.format(appdir),
use_sudo=True, owner=user, mode='0600', use_sudo=True, owner=user, mode='0600',
context={'env': env, 'envdir': envdir, 'dbname': dbname, context={'env': env, 'envdir': envdir, 'dbname': dbname,
'production': production}) 'production': production, 'lanes': lanes})
if not exists(c, '{}/quiet.conf'.format(appdir)): if not exists(c, '{}/quiet.conf'.format(appdir)):
c.sudo("bash -lc 'workon {} && cdvirtualenv app && rattail make-config -T quiet'".format(envname), c.sudo("bash -lc 'workon {} && cdvirtualenv app && rattail make-config -T quiet'".format(envname),
user=user) user=user)
@ -144,3 +152,20 @@ def bootstrap_corporal_app(c, env, envname='corporal', user='rattail',
enable=True, enable=True,
context={'sitename': sitename, 'port': port}) context={'sitename': sitename, 'port': port})
apache.restart(c) apache.restart(c)
def parse_fannie_lanes(c, script, coredir):
"""
Parse and return the CORE lane definitions from Fannie config file.
"""
lanes = []
if coredir:
config = os.path.join(coredir, 'fannie', 'config.php')
if exists(c, config):
result = c.run('php {} --path {} --setting FANNIE_LANES'.format(script, config),
hide=True)
lanes = json.loads(result.stdout)
for number, lane in enumerate(lanes, 1):
lane['number'] = number
lane['dbkey'] = 'lane{:02d}'.format(number)
return lanes

View file

@ -0,0 +1,34 @@
<?php
$options = getopt('h', array(
'help',
'path:',
'setting:',
));
$help = isset($options['h']) or isset($options['help']);
$path = isset($options['path']) ? $options['path'] : null;
$setting = isset($options['setting']) ? $options['setting'] : null;
if ($help or !$path or !$setting) {
$script = basename($argv[0]);
echo "Usage: $script --path FANNIE_CONFIG_PATH --setting NAME_OF_SETTING\n";
exit($help ? 0 : 1);
}
if (!is_file(realpath($path))) {
echo "Config file does not exist: $path\n";
exit(2);
}
$path = realpath($path);
include($path);
if (!isset($$setting)) {
echo "Config file does not contain setting: $setting\n";
exit(3);
}
$value = $$setting;
echo json_encode($value);
?>

View file

@ -11,6 +11,13 @@
default.url = mysql+mysqlconnector://${env.username_mysql_coreserver}:${env.password_mysql_coreserver}@localhost/core_op default.url = mysql+mysqlconnector://${env.username_mysql_coreserver}:${env.password_mysql_coreserver}@localhost/core_op
default.pool_recycle = 3600 default.pool_recycle = 3600
[corepos.db.lane_op]
keys = ${', '.join([lane['dbkey'] for lane in lanes])}
% for lane in lanes:
${lane['dbkey']}.url = mysql+mysqlconnector://${lane['user']}:${lane['pw']}@${lane['host']}/${lane['op']}
% endfor
<%text>##############################</%text> <%text>##############################</%text>
# rattail # rattail