summaryrefslogtreecommitdiffstats
path: root/testapi/opts/deploy.py
blob: f58690c5d7812c64c8c3f0fb79c704b8bde4175b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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())