Skip to content

Commit bea154c

Browse files
committed
Fix to allow services to define their own env_files, without having to use services/servicename/envfile.env in their own docekr-compose.yml
Also some checks for existing paths and more informative error if no package was found with the install name.
1 parent 239c015 commit bea154c

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

layersbox

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ def generate_yml(dir):
328328
# open docker-compose.yml file for each service
329329
with open(join(dir, service_yml), 'r') as addon_file:
330330
addon = yaml.load(addon_file.read())
331+
# fix env_files definitions in addon to refer to path where service's files were copied
332+
for subservice_values in addon.values():
333+
if 'env_file' in subservice_values:
334+
new_envs = []
335+
for env in subservice_values['env_file']:
336+
# common.env shouldn't redirect to services' definition, it is *common*
337+
if env == 'common.env' or env.startswith('services'):
338+
new_envs.append(env)
339+
else:
340+
new_envs.append('services/%s/%s' % (service_name, env))
341+
subservice_values['env_file'] = new_envs
331342
# merged is the base one
332343
merged, more_databases = merge_ymls(merged, addon)
333344
# "extend" extends list by appending elements from the iterable
@@ -387,7 +398,11 @@ def box_install(args):
387398
os.makedirs(tmp_servicedir)
388399
if not os.path.exists(servicedir):
389400
os.makedirs(servicedir)
390-
response = urllib2.urlopen(url)
401+
try:
402+
response = urllib2.urlopen(url)
403+
except urllib2.HTTPError:
404+
print "Failed to download service package from %s" % url
405+
return 1
391406
with open(release_tar, 'w') as f:
392407
f.write(response.read())
393408
with tarfile.open(release_tar) as t:
@@ -629,8 +644,10 @@ def box_init(args):
629644
with open(page_zip, 'w') as f:
630645
f.write(response.read())
631646
with ZipFile(page_zip, 'r') as zip:
632-
os.makedirs(join(dir, 'html/'))
633-
zip.extractall(join(dir, 'html/'))
647+
html_dir = join(dir, 'html/')
648+
if not os.path.exists(html_dir):
649+
os.makedirs(html_dir)
650+
zip.extractall(html_dir)
634651
os.remove(page_zip)
635652

636653
config = {'services': {}}
@@ -640,8 +657,9 @@ def box_init(args):
640657
print("Make sure port 80 and 443 are not in use on this machine")
641658
print("You can start your LayersBox with 'layersbox start'")
642659
# Workaround for logs dir not being available in the adapterdata container
643-
os.makedirs(join(dir, 'logs/'))
644-
660+
log_dir = join(dir, 'logs/')
661+
if not os.path.exists(log_dir):
662+
os.makedirs(log_dir)
645663
return 0
646664

647665

0 commit comments

Comments
 (0)