Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds test case to ensure safe deploy of compressed assets (js/scss) #8406

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
# Application definition
INSTALLED_APPS = [
'csp',
'compressor',
'corsheaders',
'django.contrib.admin',
'taskapp.celery.CeleryConfig',
Expand Down Expand Up @@ -196,6 +197,29 @@
},
}]

# Sass precompiler settings
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'django_libsass.SassCompiler'),
)
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder'
]
# number of demicals allowed in sass numbers
LIBSASS_PRECISION = 8
# minify sass output in production (offline)
if ENV not in ['local', 'test', 'staging', 'preview']:
# compress offline (use './manage.py compress' to build manifest.json)
COMPRESS_OFFLINE = True
# drop line comments
LIBSASS_SOURCE_COMMENTS = False
# minification of sass output
COMPRESS_CSS_FILTERS = [
'compressor.filters.css_default.CssAbsoluteFilter',
'compressor.filters.cssmin.rCSSMinFilter'
]

SITE_ID = env.int('SITE_ID', default=1)
WSGI_APPLICATION = env('WSGI_APPLICATION', default='app.wsgi.application')

Expand Down
1 change: 1 addition & 0 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@
re_path(r'^modal/extend_issue_deadline/?', dashboard.views.extend_issue_deadline, name='extend_issue_deadline'),

# brochureware views
re_path(r'^sass_experiment/?', retail.views.sass_experiment, name='sass_experiment'),
re_path(r'^homeold/?$', retail.views.index_old, name='homeold'),
re_path(r'^home/?$', retail.views.index, name='home'),
re_path(r'^landing/?$', retail.views.index, name='landing'),
Expand Down
3 changes: 3 additions & 0 deletions app/assets/v2/scss/test1.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$bg-color: green;

@import './test2.scss';
6 changes: 6 additions & 0 deletions app/assets/v2/scss/test2.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body {
background: $bg-color;
& > div:after {
content: "working"
}
}
30 changes: 30 additions & 0 deletions app/retail/templates/home/sass_experiment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% load i18n static compress %}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Deploy Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
body {
background: red;
}
</style>
{% compress css file testing %}
<link rel="stylesheet" type="text/x-scss" href={% static "v2/scss/test1.scss" %} />
<style>
body > div {
border-bottom: 1px solid;
}
</style>
{% endcompress %}
</head>
<body>
<div></div>
{% compress js file testing %}
<script>
alert('testing');
</script>
{% endcompress %}
</body>
</html>

4 changes: 4 additions & 0 deletions app/retail/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def index(request):
}
return TemplateResponse(request, 'home/index2020.html', context)

def sass_experiment(request):
context = {
}
return TemplateResponse(request, 'home/sass_experiment.html', context)

def index_old(request):
products = [
Expand Down
2 changes: 2 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ django-cors-headers==2.4.0
django-filter==2.0.0
django-haystack
django-ratelimit==1.1.0
django_compressor==2.4
django-libsass==0.8
djangorestframework==3.9.1
gitterpy
gunicorn
Expand Down
1 change: 1 addition & 0 deletions scripts/deploy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ cd app || echo "Cannot find app directory!"
echo "- collect static"
if [ "$ISFRONTENDPUSH" ] && [ "$JOBS_NODE" ]; then
python3 manage.py collectstatic --noinput -i other;
python3 manage.py compress;
fi

rm -Rf ~/gitcoin/coin/app/static/other
Expand Down