From 6dbac7b15c3f4e9a33fa1a14f1703376b891d44c Mon Sep 17 00:00:00 2001 From: Megh Parikh Date: Wed, 17 Jan 2018 03:16:05 +0530 Subject: [PATCH] Add environment variables from config file --- gen.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gen.py b/gen.py index c8e3599..8894c09 100644 --- a/gen.py +++ b/gen.py @@ -21,6 +21,16 @@ def getPassword(portal): os.chdir('../portals') portals = [ portal for portal in os.listdir('./') if os.path.isdir(portal) ] +portalconfig = {} + +print("\n=============== Reading config ===============\n") +for portal in portals: + print("\n##### " + portal + "\n") + try: + portalconfig[portal] = yaml.load(open(portal + '/config.yml')) + except Exception: + portalconfig[portal] = {} + print("\n=============== Building frontend ===============\n") for portal in portals: @@ -41,6 +51,10 @@ def getPassword(portal): print("\n=============== Making docker compose file ===============\n") services = {} for portal in portals: + extraenv = [] + for key, value in portalconfig[portal].iteritems(): + extraenv.append("%s=\"%s\"" % (key, value)) + services[portal + '_backend'] = { "image": "node:8", "working_dir": "/home/node/app", @@ -49,7 +63,7 @@ def getPassword(portal): "DBURI=mysql://%s:%s@portaldb/%s" % (portal, getPassword(portal), portal), "PUBLIC_API_URL=https://felicity.iiit.ac.in/k/%s/api" % portal, "PUBLIC_FRONTEND_URL=https://felicity.iiit.ac.in/k/%s" % portal, - ], + ] + extraenv, "volumes": [ "../portals/%s/backend:/home/node/app" % portal ], "command": "bash -c 'yarn install && yarn start'" }