Created
July 13, 2014 18:26
-
-
Save timfreund/0af9c49141d0409350bf to your computer and use it in GitHub Desktop.
fig config and glue for kallithea ci
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -x | |
here=`dirname $0` | |
env | |
python ${here}/fig-config-glue.py ${here}/../test.ini | |
sleep 10 | |
nosetests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os | |
import re | |
env = os.environ | |
def get_sqlalchemy_url_from_env(env): | |
var_regexps = {'port': re.compile('DB_1_PORT_[0-9]*_TCP_PORT'), | |
'addr': re.compile('DB_1_PORT_[0-9]*_TCP_ADDR')} | |
vars = {'type': env.get('DB_TYPE', 'sqlite'), | |
'port': None, | |
'addr': None, | |
'username': 'docker', | |
'password': 'docker', | |
'dbname': 'docker'} | |
url_templates = { | |
'default': "%(type)s://%(username)s:%(password)s@%(addr)s:%(port)s/%(dbname)s", | |
'sqlite': "sqlite:///%%(here)s/%(dbname)s.sqlite" | |
} | |
for key, value in env.items(): | |
for varname, varregex in var_regexps.items(): | |
if varregex.match(key): | |
vars[varname] = value | |
url_template = url_templates.get(vars['type'], url_templates['default']) | |
url = url_template % vars | |
return url | |
def update_ini_with_sqlalchemy_url(sqlalchemy_url, ini_path, new_ini_path=None): | |
cmd = "sed -e 's|^sqlalchemy.db1.url.*|sqlalchemy.db1.url = %s|'" | |
if not new_ini_path: | |
print "Updating %s with database URL %s" % (ini_path, sqlalchemy_url) | |
cmd = cmd + " -i %s" % ini_path | |
else: | |
print "Copying %s to %s and updating database URL to %s" % (ini_path, | |
new_ini_path, | |
sqlalchemy_url) | |
cmd = cmd + " %s > %s" % (ini_path, new_ini_path) | |
cmd = cmd % sqlalchemy_url | |
print cmd | |
os.system(cmd) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("source_configuration", | |
help="The original config file, it will be updated inline if no new configuration path is provided") | |
parser.add_argument("--new", | |
help="A copy of source_configuration with the sqlalchemy.db1.url value set correctly.") | |
args = parser.parse_args() | |
print args.source_configuration | |
print args.new | |
sqlalchemy_url = get_sqlalchemy_url_from_env(env) | |
update_ini_with_sqlalchemy_url(sqlalchemy_url, | |
args.source_configuration, | |
args.new) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db: | |
image: orchardup/postgresql | |
kallithea: | |
build: . | |
command: /code/integration-configs/execute_tests.sh | |
volumes: | |
- .:/code/ | |
ports: | |
- "5000:5000" | |
links: | |
- db | |
environment: | |
DB_TYPE: postgresql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment