diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-09-21 13:41:59 +0800 |
---|---|---|
committer | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-09-21 13:41:59 +0800 |
commit | 33a78118868411eb5671b213ff2f90df8de3ca9c (patch) | |
tree | f50ed872ebb2d14823ba491187716621a12a82ea /utils/test/testapi/opts | |
parent | d4eb739d80d5afe79f1d81e5a88b60bb337e7b69 (diff) |
refactor one click deployment in testapi
substitue docker-compose.template with string description,
so that user can wget deploy.py and execute directly.
Change-Id: I9703a1c8dfbdc46470561d54c6663e3728540162
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test/testapi/opts')
-rw-r--r-- | utils/test/testapi/opts/deploy.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/utils/test/testapi/opts/deploy.py b/utils/test/testapi/opts/deploy.py new file mode 100644 index 000000000..f58690c5d --- /dev/null +++ b/utils/test/testapi/opts/deploy.py @@ -0,0 +1,55 @@ +import argparse +import os + +from jinja2 import Environment + +DOCKER_COMPOSE_FILE = './docker-compose.yml' +DOCKER_COMPOSE_TEMPLATE = """ +version: '2' +services: + mongo: + image: mongo:3.2.1 + container_name: opnfv-mongo + testapi: + image: opnfv/testapi:latest + container_name: opnfv-testapi + environment: + - mongodb_url=mongodb://mongo:27017/ + - base_url={{ vars.testapi_base_url }} + ports: + - "{{ vars.testapi_port }}:8000" + links: + - mongo +""" + + +def render_docker_compose(testapi_port, testapi_base_url): + vars = { + "testapi_port": testapi_port, + "testapi_base_url": testapi_base_url, + } + + yml = Environment().from_string(DOCKER_COMPOSE_TEMPLATE).render(vars=vars) + + with open(DOCKER_COMPOSE_FILE, 'w') as f: + f.write(yml) + f.close() + + +def main(args): + render_docker_compose(args.testapi_port, args.testapi_base_url) + os.system('docker-compose -f {} up -d'.format(DOCKER_COMPOSE_FILE)) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Backup MongoDBs') + parser.add_argument('-tp', '--testapi-port', + type=int, + required=False, + default=8000, + help='testapi exposed port') + parser.add_argument('-tl', '--testapi-base-url', + type=str, + required=True, + help='testapi exposed base-url') + main(parser.parse_args()) |