From 209358e9bde7c5aa1e12f78bb885bed9839b66cb Mon Sep 17 00:00:00 2001 From: JackScanlon Date: Thu, 1 Feb 2024 14:29:34 +0000 Subject: [PATCH 1/2] Impl. init app changes to fix issue surrounding offline generation errors --- CodeListLibrary_project/cll/settings.py | 32 +++++++++++++++---- .../cll/templates/drf-yasg/swagger-ui.html | 11 ++++--- docker/production/scripts/init-app.sh | 27 ++++++++-------- docker/test/env/app.compose.env | 1 + 4 files changed, 45 insertions(+), 26 deletions(-) diff --git a/CodeListLibrary_project/cll/settings.py b/CodeListLibrary_project/cll/settings.py index ab3a7c5f5..0b701a1bb 100644 --- a/CodeListLibrary_project/cll/settings.py +++ b/CodeListLibrary_project/cll/settings.py @@ -20,7 +20,18 @@ import numbers ''' Utilities ''' +class Symbol: + """ + Used as a primitive to describe an optional argument. + + In this case, it's just a basic impl. of JS symbol. + See ref @ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol + """ + def __init__(self, name='Symbol'): + self.name = f'Symbol({name})' + def __repr__(self): + return self.name def strtobool(val): """ @@ -63,7 +74,7 @@ def GET_SERVER_IP(TARGET_IP='10.255.255.255', PORT=1): return IP -def get_env_value(env_variable, cast=None): +def get_env_value(env_variable, cast=None, default=Symbol('None')): """ Attempts to get env variable from OS """ @@ -77,8 +88,13 @@ def get_env_value(env_variable, cast=None): else: return os.environ[env_variable] except KeyError: - error_msg = 'Set the {} environment variable'.format(env_variable) - raise ImproperlyConfigured(error_msg) + if isinstance(default, Symbol): + error_msg = 'Expected environment variable "{}" of type<{}>, please set a valid "{}" environment variable' \ + .format(env_variable, cast or 'string', env_variable) + + raise ImproperlyConfigured(error_msg) + + return default # ==============================================================================# @@ -187,14 +203,16 @@ def get_env_value(env_variable, cast=None): } ## Message template settings -MESSAGE_TAGS = {messages.ERROR: 'danger'} +MESSAGE_TAGS = { messages.ERROR: 'danger' } ### Icon settings for demo sites, incl. cookie alert(s) DEV_PRODUCTION = '' -if IS_DEMO: # Demo server + +# Demo server +if IS_DEMO: DEV_PRODUCTION = ' DEMO SITE ' -SHOW_COOKIE_ALERT = get_env_value('SHOW_COOKIE_ALERT', cast='bool') +SHOW_COOKIE_ALERT = get_env_value('SHOW_COOKIE_ALERT', cast='bool', default=False) # ==============================================================================# @@ -204,11 +222,11 @@ def get_env_value(env_variable, cast=None): ENABLE_LDAP_AUTH = get_env_value('ENABLE_LDAP_AUTH', cast='bool') AUTH_LDAP_SERVER_URI = get_env_value('AUTH_LDAP_SERVER_URI') + AUTH_LDAP_BIND_DN = get_env_value('AUTH_LDAP_BIND_DN') AUTH_LDAP_BIND_PASSWORD = get_env_value('AUTH_LDAP_BIND_PASSWORD') - AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(LDAPSearch(get_env_value('AUTH_LDAP_USER_SEARCH'), ldap.SCOPE_SUBTREE, '(sAMAccountName=%(user)s)'), ) diff --git a/CodeListLibrary_project/cll/templates/drf-yasg/swagger-ui.html b/CodeListLibrary_project/cll/templates/drf-yasg/swagger-ui.html index e1c9e1d46..c1ed7b367 100644 --- a/CodeListLibrary_project/cll/templates/drf-yasg/swagger-ui.html +++ b/CodeListLibrary_project/cll/templates/drf-yasg/swagger-ui.html @@ -5,18 +5,19 @@ {% load sass_tags %} {% block head %} - - + - {% compress css %} - - {% endcompress %} {% endblock %} {% block title %}| API Documentation {% endblock title %} {% block container %} + {% compress css %} + + + {% endcompress %} +

diff --git a/docker/production/scripts/init-app.sh b/docker/production/scripts/init-app.sh index 6df2ebf12..2769f48b2 100644 --- a/docker/production/scripts/init-app.sh +++ b/docker/production/scripts/init-app.sh @@ -10,6 +10,14 @@ if [ ! -z $AWAIT_POSTGRES ] && [ $AWAIT_POSTGRES = "True" ]; then /bin/wait-for-it.sh -t 0 $DB_HOST:5432 -- echo "Postgres is live" fi +echo "===========================================" +echo "=========== Clear static files ============" +echo "===========================================" + +if [ ! -d "staticroot" ]; then + rm -rf staticroot +fi + if [ ! -z $CLL_READ_ONLY ] && [ $CLL_READ_ONLY = "False" ]; then echo "===========================================" echo "============== Migrating app ==============" @@ -22,26 +30,17 @@ fi echo "===========================================" echo "============== Compiling app ==============" echo "===========================================" + +chown -R www-data:www-data /var/www/concept_lib_sites + if [ ! -z $DEBUG ] && [ $DEBUG = "False" ]; then python manage.py compilescss - python manage.py collectstatic --noinput --clear --ignore=*.scss -v 0 + python manage.py collectstatic --noinput --clear -v 0 python manage.py compress - python manage.py collectstatic --noinput --ignore=*.scss -v 0 - - chown -R www-data:www-data /var/www/concept_lib_sites - - # test if re-run avoid compress issues - python manage.py compilescss - python manage.py collectstatic --noinput --clear --ignore=*.scss -v 0 - python manage.py compress - python manage.py collectstatic --noinput --ignore=*.scss -v 0 - - chown -R www-data:www-data /var/www/concept_lib_sites + python manage.py collectstatic --noinput -v 0 else python manage.py compilescss --delete-files python manage.py collectstatic --clear --noinput -v 0 - - chown -R www-data:www-data /var/www/concept_lib_sites fi echo "===========================================" diff --git a/docker/test/env/app.compose.env b/docker/test/env/app.compose.env index 2d49f37d9..a03b00479 100644 --- a/docker/test/env/app.compose.env +++ b/docker/test/env/app.compose.env @@ -8,6 +8,7 @@ IS_DEVELOPMENT_PC=False CLL_READ_ONLY=False ENABLE_PUBLISH=True SHOWADMIN=True +SHOW_COOKIE_ALERT=True BROWSABLEAPI=False SECRET_KEY=abc ALLOWED_HOSTS=localhost, 127.0.0.1 From ca6fafb265a4ad95f9089b778134f8403661ce78 Mon Sep 17 00:00:00 2001 From: Arthur zinnurov Date: Thu, 1 Feb 2024 16:38:39 +0000 Subject: [PATCH 2/2] back to slim 3.9 --- docker/development/app.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/development/app.Dockerfile b/docker/development/app.Dockerfile index 3a66728ca..95ac899c5 100644 --- a/docker/development/app.Dockerfile +++ b/docker/development/app.Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10-slim +FROM python:3.9-slim ENV PYTHONUNBUFFERED 1 ENV LC_ALL=C.UTF-8