6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-12-12 06:07:56 +00:00

Serve static assets with whitenoise instead of nginx

This drastically simplifies volume management, as it is no longer
necessary to manually copy static assets from the docker image to the
bind-mounted volume.

This deprecates the "k8s-deployments-nginx-init-containers" patch, as we
no longer need to init the nginx container. Plugins are encouraged to
start using whitenoise as well for serving static assets.

TODO:
- test media serving: DOES NOT WORK. Whitenoise was designed to serve a
fixed list of static files. Godammit.
- compare performances
This commit is contained in:
Régis Behmo 2020-01-21 16:30:16 +01:00
parent 70872dfa9b
commit 62d7fd00b9
8 changed files with 8 additions and 84 deletions

View File

@ -4,6 +4,7 @@ Note: Breaking changes between versions are indicated by "💥".
## Unreleased
- 💥[Improvement] Serve openedx static assets with [whitenoise](http://whitenoise.evans.io/en/stable/) instead of nginx. This removes the `k8s-deployments-nginx-init-containers` patch. Plugins are encouraged to implement static asset serving with Whitenoise as well.
- [Bugfix] Fix dependency on mysql service when mysql is not activated
- [Improvement] Improve openedx Docker image build time and size with multi-stage build
- [Feature] Get rid of outdated sysadmin dashboard in LMS at /sysadmin

View File

@ -47,29 +47,5 @@ server {
try_files /$file =404;
expires 31536000s;
}
location ~ ^/static/(?P<file>.*) {
root /var/www/openedx;
try_files /staticfiles/$file /course_static/$file =404;
# return a 403 for static files that shouldn't be
# in the staticfiles directory
location ~ ^/static/(?:.*)(?:\.xml|\.json|README.TXT) {
return 403;
}
# Set django-pipelined files to maximum cache time
location ~ "/static/(?P<collected>.*\.[0-9a-f]{12}\..*)" {
expires max;
try_files /staticfiles/$collected /course_static/$collected =404;
}
location ~ "/static/(?P<collected>[0-9a-f]{7}/.*)" {
expires max;
try_files /staticfiles/$collected /course_static/$collected =404;
}
# Expire other static files immediately (there should be very few / none of these)
expires epoch;
}
}
{% endif %}

View File

@ -64,29 +64,5 @@ server {
try_files /$file =404;
expires 31536000s;
}
location ~ ^/static/(?P<file>.*) {
root /var/www/openedx;
try_files /staticfiles/$file /course_static/$file =404;
# return a 403 for static files that shouldn't be
# in the staticfiles directory
location ~ ^/static/(?:.*)(?:\.xml|\.json|README.TXT) {
return 403;
}
# Set django-pipelined files to maximum cache time
location ~ "/static/(?P<collected>.*\.[0-9a-f]{12}\..*)" {
expires max;
try_files /staticfiles/$collected /course_static/$collected =404;
}
location ~ "/static/(?P<collected>[0-9a-f]{7}/.*)" {
expires max;
try_files /staticfiles/$collected /course_static/$collected =404;
}
# Expire other static files immediately (there should be very few / none of these)
expires epoch;
}
}
{% endif %}

View File

@ -9,4 +9,6 @@ ALLOWED_HOSTS = [
"cms",
]
MIDDLEWARE.insert(0, "whitenoise.middleware.WhiteNoiseMiddleware")
{{ patch("openedx-cms-production-settings") }}

View File

@ -10,6 +10,8 @@ ALLOWED_HOSTS = [
"lms",
]
MIDDLEWARE.insert(0, "whitenoise.middleware.WhiteNoiseMiddleware")
# Required to display all courses on start page
SEARCH_SKIP_ENROLLMENT_START_DATE_FILTERING = True

View File

@ -84,6 +84,9 @@ RUN pip install https://github.com/overhangio/edx-ora2/archive/overhangio/boto2t
# Install scorm xblock
RUN pip install "openedx-scorm-xblock<11.0.0,>=10.0.0"
# Install whitenoise, for serving static assets
RUN pip install "whitenoise==5.1.0"
# Install private requirements: this is useful for installing custom xblocks.
COPY ./requirements/ /openedx/requirements
RUN cd /openedx/requirements/ \

View File

@ -370,35 +370,12 @@ spec:
labels:
app.kubernetes.io/name: nginx
spec:
initContainers:
- name: clean-openedx-staticfiles
image: {{ DOCKER_IMAGE_OPENEDX }}
args: ['rm', '-rf', '/var/www/openedx/staticfiles']
volumeMounts:
- mountPath: /var/www/openedx/
name: openedx-staticfiles
- name: init-openedx-staticfiles
image: {{ DOCKER_IMAGE_OPENEDX }}
args: ['cp', '-r', '/openedx/staticfiles', '/var/www/openedx/']
volumeMounts:
- mountPath: /var/www/openedx/
name: openedx-staticfiles
{{ patch("k8s-deployments-nginx-init-containers")|indent(8) }}
containers:
- name: nginx
image: {{ DOCKER_IMAGE_NGINX }}
volumeMounts:
- mountPath: /etc/nginx/conf.d/
name: config
- mountPath: /var/www/openedx/
name: openedx-staticfiles
readOnly: true
- mountPath: /openedx/data/cms
name: data-cms
readOnly: true
- mountPath: /openedx/data/lms
name: data-lms
readOnly: true
{{ patch("k8s-deployments-nginx-volume-mounts")|indent(12) }}
ports:
- containerPort: 80
@ -407,12 +384,6 @@ spec:
- name: config
configMap:
name: nginx-config
- name: openedx-staticfiles
emptyDir: {}
- name: data-cms
emptyDir: {}
- name: data-lms
emptyDir: {}
{{ patch("k8s-deployments-nginx-volumes")|indent(8) }}
{% if ACTIVATE_RABBITMQ %}
---

View File

@ -1,11 +1,5 @@
version: "3.7"
services:
openedx-assets:
image: {{ DOCKER_IMAGE_OPENEDX }}
volumes:
- ../../data/openedx:/var/www/openedx
command: sh -c "rm -rf /var/www/openedx/staticfiles && cp -r /openedx/staticfiles/ /var/www/openedx/"
nginx:
image: {{ DOCKER_IMAGE_NGINX }}
restart: unless-stopped
@ -21,7 +15,6 @@ services:
{% endif %}
volumes:
- ../apps/nginx:/etc/nginx/conf.d/:ro
- ../../data/openedx:/var/www/openedx:ro
- ../../data/openedx-media:/var/www/openedx-media:ro
{% if ACTIVATE_HTTPS %}- ../../data/letsencrypt:/etc/letsencrypt/:ro{% endif %}
{{ patch("local-docker-compose-nginx-volumes")|indent(6) }}