Skip to content

Commit

Permalink
fix(release): Offline compression fixes #1521 (#1524)
Browse files Browse the repository at this point in the history
  • Loading branch information
elmessary authored Feb 1, 2024
2 parents 9d5e67f + d121031 commit 8aace3f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 27 deletions.
32 changes: 25 additions & 7 deletions CodeListLibrary_project/cll/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
"""
Expand All @@ -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


# ==============================================================================#
Expand Down Expand Up @@ -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 = '<i class="glyphicon glyphicon-cog" aria-hidden="true">&#9881; </i> DEMO SITE <i class="glyphicon glyphicon-cog" aria-hidden="true">&#9881;</i>'

SHOW_COOKIE_ALERT = get_env_value('SHOW_COOKIE_ALERT', cast='bool')
SHOW_COOKIE_ALERT = get_env_value('SHOW_COOKIE_ALERT', cast='bool', default=False)

# ==============================================================================#

Expand All @@ -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)'), )


Expand Down
11 changes: 6 additions & 5 deletions CodeListLibrary_project/cll/templates/drf-yasg/swagger-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
{% load sass_tags %}

{% block head %}
<meta charset="utf-8"/>
<link href="{% sass_src 'scss/pages/select.scss' %}" rel="stylesheet" type="text/css" />
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="{% static 'drf-yasg/style.css' %}"/>
<link rel="stylesheet" type="text/css" href="{% static 'drf-yasg/swagger-ui-dist/swagger-ui.css' %}">
{% compress css %}
<link href="{% sass_src 'scss/pages/swagger.scss' %}" rel="stylesheet" type="text/css" />
{% endcompress %}
{% endblock %}

{% block title %}| API Documentation {% endblock title %}

{% block container %}
{% compress css %}
<link href="{% sass_src 'scss/pages/select.scss' %}" rel="stylesheet" type="text/css" />
<link href="{% sass_src 'scss/pages/swagger.scss' %}" rel="stylesheet" type="text/css" />
{% endcompress %}

<div class="api-about">
<div class="api-about__section">
<p>
Expand Down
2 changes: 1 addition & 1 deletion docker/development/app.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim
FROM python:3.9-slim

ENV PYTHONUNBUFFERED 1
ENV LC_ALL=C.UTF-8
Expand Down
27 changes: 13 additions & 14 deletions docker/production/scripts/init-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 =============="
Expand All @@ -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 "==========================================="
Expand Down
1 change: 1 addition & 0 deletions docker/test/env/app.compose.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8aace3f

Please sign in to comment.