From 6b2d929261b1414e4efa2ee2639b851720b70e2e Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Wed, 12 Jun 2019 14:45:28 +1200 Subject: [PATCH] dockersetup: obtain and use the real project name instead of hardcoding We need the real project name here otherwise we are mounting something nonexistent instead of the real volume we want to populate. This fixes a bug where the static assets were not available (thus the web interface looks awful) if the directory you installed the application from was not called "layerindex-web". Signed-off-by: Paul Eggleton --- dockersetup.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/dockersetup.py b/dockersetup.py index 45c1832..e709e74 100755 --- a/dockersetup.py +++ b/dockersetup.py @@ -586,6 +586,25 @@ if return_code != 0: print("docker-compose up failed") sys.exit(1) +# Get real project name (if only there were a reasonable way to do this... ugh) +real_project_name = '' +output = subprocess.check_output(['docker-compose', 'ps', '-q'], shell=False) +if output: + output = output.decode('utf-8') + for contid in output.splitlines(): + output = subprocess.check_output(['docker', 'inspect', '-f', '{{ .Mounts }}', contid], shell=False) + if output: + output = output.decode('utf-8') + for volume in re.findall('volume ([^ ]+)', output): + if '_' in volume: + real_project_name = volume.rsplit('_', 1)[0] + break + if real_project_name: + break +if not real_project_name: + print('Failed to detect docker-compose project name') + sys.exit(1) + # Database might not be ready yet; have to wait then poll. time.sleep(8) while True: @@ -654,13 +673,14 @@ if not updatemode: volumes.append('srcvolume') break for volume in volumes: - return_code = subprocess.call(['docker', 'run', '--rm', '-v', 'layerindexweb_%s:/opt/mount' % volume, 'debian:stretch', 'chown', '500', '/opt/mount'], shell=False) + volname = '%s_%s' % (real_project_name, volume) + return_code = subprocess.call(['docker', 'run', '--rm', '-v', '%s:/opt/mount' % volname, 'debian:stretch', 'chown', '500', '/opt/mount'], shell=False) if return_code != 0: print("Setting volume permissions for volume %s failed" % volume) sys.exit(1) ## Generate static assets. Run this command again to regenerate at any time (when static assets in the code are updated) -return_code = subprocess.call("docker-compose run --rm -e STATIC_ROOT=/usr/share/nginx/html -v layerindexweb_layersstatic:/usr/share/nginx/html layersapp /opt/layerindex/manage.py collectstatic --noinput", shell = True) +return_code = subprocess.call("docker-compose run --rm -e STATIC_ROOT=/usr/share/nginx/html -v %s_layersstatic:/usr/share/nginx/html layersapp /opt/layerindex/manage.py collectstatic --noinput" % quote(real_project_name), shell = True) if return_code != 0: print("Collecting static files failed") sys.exit(1)