From 4d2c0bbcbaf22f465a2bd89916a1eddb6df14343 Mon Sep 17 00:00:00 2001 From: Marco Ceppi Date: Tue, 23 Mar 2021 15:13:02 -0400 Subject: [PATCH] implement skipping startup scripts, but not required ones --- docker/docker-entrypoint.sh | 5 +++-- docker/startup_scripts/__main__.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 21b6bfe45..b4479040b 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -53,10 +53,11 @@ fi # Run the startup scripts (and initializers) if [ "$SKIP_STARTUP_SCRIPTS" == "true" ]; then echo "↩️ Skipping startup scripts" -else - echo "import runpy; runpy.run_path('../startup_scripts')" | ./manage.py shell --interface python fi +echo "import runpy; runpy.run_path('../startup_scripts')" | ./manage.py shell --interface python + + # copy static files ./manage.py collectstatic --no-input diff --git a/docker/startup_scripts/__main__.py b/docker/startup_scripts/__main__.py index dc4cdc9f9..d7990b1a4 100644 --- a/docker/startup_scripts/__main__.py +++ b/docker/startup_scripts/__main__.py @@ -1,15 +1,18 @@ #!/usr/bin/env python3 import runpy -from os import scandir +import os + +from distutils.util import strtobool from os.path import dirname, abspath this_dir = dirname(abspath(__file__)) +skip_startup_scripts = bool(strtobool(os.environ.get('SKIP_STARTUP_SCRIPTS', "false"))) def filename(f): return f.name -with scandir(this_dir) as it: +with os.scandir(this_dir) as it: for f in sorted(it, key = filename): if not f.is_file(): continue @@ -20,6 +23,9 @@ with scandir(this_dir) as it: if not f.name.endswith('.py'): continue + if skip_startup_scripts and "required" not in f.name: + continue + print(f"▶️ Running the startup script {f.path}") try: runpy.run_path(f.path)