Skip to content

Commit

Permalink
add configure script, to setup probe from docker env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
dantheta committed Feb 16, 2017
1 parent 6432b40 commit 3493b44
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 28 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ RUN mkdir /usr/local/probe
COPY *.py /usr/local/probe/
COPY docker/run-probe.sh /usr/local/probe/run-probe.sh
COPY docker/config.ini.tmpl /usr/local/probe/config.ini.tmpl
COPY docker/configure.py /usr/local/probe/configure.py

RUN chmod a+x /usr/local/probe/run-probe.sh

Expand Down
58 changes: 58 additions & 0 deletions docker/configure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

import os
import sys
import argparse
import ConfigParser

REQUIRED = [
"PROBE_UUID","PROBE_SECRET","AMQP_USER","AMQP_PASSWD"
]

DEFAULTS = {
'API_HOST': 'api.blocked.org.uk',
'API_PORT': '443',
'API_HTTPS': 'True'
}

env = os.environ

parser = argparse.ArgumentParser(description="Script to write OrgProbe config file")
parser.add_argument('--output','-o', help="Path to output file")
parser.add_argument('--template','-t', help="Path to template file",
default=os.path.join(os.path.dirname(sys.argv[0]), 'config.ini.tmpl'),
)
args = parser.parse_args()

missing = []
for req in REQUIRED:
if req not in env:
missing.append(req)

if missing:
print "Missing environment: " + ",".join(missing)
sys.exit(1)

cfg = ConfigParser.ConfigParser()
cfg.read([args.template])

cfg.set('api','host', env.get('API_HOST', DEFAULTS['API_HOST']))
cfg.set('api','port', env.get('API_PORT', DEFAULTS['API_PORT']))
cfg.set('api','https', env.get('API_HTTPS', DEFAULTS['API_HTTPS']))

cfg.set('amqp','host', env.get('API_HOST', DEFAULTS['API_HOST']))

cfg.set('amqp','userid', env['AMQP_USER'])
cfg.set('amqp','passwd', env['AMQP_PASSWD'])

cfg.set('public','uuid', env['PROBE_UUID'])
cfg.set('public','secret', env['PROBE_SECRET'])

if 'PROBE_QUEUE' in env:
cfg.set('public','queue',env['PROBE_QUEUE'])
if 'PROBE_NETWORK' in env:
cfg.set('public','network', env['PROBE_NETWORK'])

with open(args.output,'w') as fp:
cfg.write(fp)


29 changes: 1 addition & 28 deletions docker/run-probe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,7 @@ CONFIG=$PRBDIR/config.ini

if [ ! -f $CONFIG ]
then
[ -z "$PROBE_UUID" -o -z "$PROBE_SECRET" -o -z "$AMQP_USER" -o -z "$AMQP_PASSWD" ] && \
echo "Required envvars: PROBE_UUID, PROBE_SECRET, AMQP_USER, AMQP_PASSWD." && \
exit 1

# use API_HOST if defined
API_HOST=${API_HOST:-api.blocked.org.uk}
API_PORT=${API_PORT:-443}
API_HTTPS=${API_HTTPS:-True}

# create config file from template
cp $PRBDIR/config.ini.tmpl $CONFIG
sed -i $CONFIG \
-e "s/API_HOST/$API_HOST/" \
-e "s/API_PORT/$API_PORT/" \
-e "s/API_HTTPS/$API_HTTPS/" \
-e "s/PROBE_UUID/$PROBE_UUID/" \
-e "s/PROBE_SECRET/$PROBE_SECRET/" \
-e "s/AMQP_USER/$AMQP_USER/" \
-e "s/AMQP_PASSWD/$AMQP_PASSWD/"

if [ ! -z "$REDIS" ]
then
PROBE_LIMIT=${PROBE_LIMIT:-200000000}
echo "limit = $PROBE_LIMIT" >> $CONFIG
echo "" >> $CONFIG
echo "[accounting]" >> $CONFIG
echo "redis_server = $REDIS" >> $CONFIG
fi
python $PRBDIR/configure.py -o $CONFIG
fi

exec /usr/bin/python $PRBDIR/__main__.py -c $PRBDIR/config.ini
Expand Down

0 comments on commit 3493b44

Please sign in to comment.