Skip to content

Commit

Permalink
Add missing env vars and enhance expand vars to use set env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
triole committed Feb 12, 2021
1 parent b218ef7 commit 9a9a244
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
21 changes: 18 additions & 3 deletions py/dcompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ def __init__(self, conf, prof):
self.names = {}
self.volumes = []

def expand_vars_arr(self, arr):
def expand_vars_arr(self, arr, container_name=None):
for i, el in enumerate(arr):
arr[i] = self.expand_vars(arr[i])
arr[i] = self.expand_vars(arr[i], container_name)
return arr

def expand_vars(self, str, container_name=None):
if '<' not in str and '>' not in str:
return str
# expand variables set in config
str = str\
.replace('<HOME>', os.environ['HOME'])\
.replace('<CONTAINER_PGAPP>', self.nam_con('pgapp'))\
Expand All @@ -33,6 +36,18 @@ def expand_vars(self, str, container_name=None):
.replace('<CONTAINER_RABBITMQ>', self.nam_con('rabbitmq'))\
.replace('<UID>', self.conf['user']['idstr'])\
.replace('<GID>', self.conf['user']['groupstr'])
# expand env var placeholders set in other env vars
if container_name is not None:
try:
env_vars = self.profconf['conf']['env'][container_name]
except KeyError:
pass
else:
for env_var in env_vars:
key, val = env_var.split('=')
if key != "" and val != "":
str = str.replace('<' + key.upper() + '>', val)
# add additional packages
if container_name is not None:
try:
p = ' '.join(self.profconf['conf']['additional_packages'][container_name])
Expand Down Expand Up @@ -116,7 +131,7 @@ def add_depends_on(self):
def add_env(self):
for service in self.profconf['conf']['env']:
try:
env = self.expand_vars_arr(self.profconf['conf']['env'][service])
env = self.expand_vars_arr(self.profconf['conf']['env'][service], service)
except KeyError:
pass
else:
Expand Down
7 changes: 7 additions & 0 deletions tpl/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ exposed_ports:
env:
daiquiri:
- URL_BASE=http://localhost:9280
- SITE_URL=<URL_BASE>
- SERVER_HTTPS=on
- WORDPRESS_TITLE=dqdev
- WORDPRESS_URL=/cms/
Expand All @@ -66,8 +67,14 @@ env:
- ARCHIVE_BASE_PATH=/tmp/files
- ARCHIVE_DOWNLOAD_DIR=/tmp/download
- FILES_BASE_PATH=/tmp/files
- FILES_BASE_URL=<URL_BASE>/files
- QUERY_DOWNLOAD_DIR=/tmp/download
- QUERY_UPLOAD_DIR=/tmp/upload
- LOG_DIR=/dev/stdout
- LOG_LEVEL=INFO
- TAP_SCHEMA=tap_schema
- OAI_SCHEMA=oai_schema
- TAP_UPLOAD=tap_upload
- ASYNC=False
- CELERY_BROKER_URL=amqp://gaia:password@<CONTAINER_RABBITMQ>:5672/gaia

Expand Down

0 comments on commit 9a9a244

Please sign in to comment.