Skip to content

Commit

Permalink
feat: support richie site factory
Browse files Browse the repository at this point in the history
  • Loading branch information
BbrSofiane committed Sep 30, 2022
1 parent d01358a commit 5ea228a
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -18,7 +18,8 @@ Every user-facing change should have an entry in this changelog. Please respect

## [Unrealeased]

- [Feature] Upgrade richie to v2.15.1
- [Feature] Upgrade richie to v2.15.1 (by @BbrSofiane)
- [Feature] Support deployment of richie site factory (by @BbrSofiane)

Upgrade node to 16

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -45,7 +45,7 @@ Configuration

This Tutor plugin comes with a few configuration settings:

- ``RICHIE_RELEASE_VERSION`` (default: ``"v2.8.2"``)
- ``RICHIE_RELEASE_VERSION`` (default: ``"v2.16.0"``)
- ``RICHIE_HOST`` (default: ``"courses.{{ LMS_HOST }}"``)
- ``RICHIE_MYSQL_DATABASE`` (default: ``"richie"``)
- ``RICHIE_MYSQL_USERNAME`` (default: ``"richie"``)
Expand Down
9 changes: 8 additions & 1 deletion tutorrichie/patches/local-docker-compose-dev-services
@@ -1,6 +1,13 @@
richie:
{% if RICHIE_FACTORY_REPOSITORY %}
command: ./manage.py runserver 0.0.0.0:8003
{% else %}
command: ./sandbox/manage.py runserver 0.0.0.0:8003
{% endif %}
env_file:
- ../plugins/richie/apps/env.d/development
ports:
- "8003:8003"
- "8003:8003"



13 changes: 13 additions & 0 deletions tutorrichie/patches/local-docker-compose-jobs-services
@@ -1,3 +1,15 @@
{% if RICHIE_FACTORY_REPOSITORY %}
richie-job:
image: {{ RICHIE_FACTORY_DOCKER_IMAGE }}
depends_on: {{ [("elasticsearch", RUN_ELASTICSEARCH), ("mysql", RUN_MYSQL)]|list_if }}
# Run as root to fix media permissions
user: root
env_file:
- ../plugins/richie/apps/env.d/production
volumes:
- ../plugins/richie/apps/settings/tutor.py:/app/richie/sites/{{ RICHIE_FACTORY_SITE }}/src/backend/{{ RICHIE_FACTORY_SITE }}/tutor.py:ro
- ../../data/richie/media:/data/media
{% else %}
richie-job:
image: {{ RICHIE_DOCKER_IMAGE }}
depends_on: {{ [("elasticsearch", RUN_ELASTICSEARCH), ("mysql", RUN_MYSQL)]|list_if }}
Expand All @@ -8,6 +20,7 @@ richie-job:
volumes:
- ../plugins/richie/apps/settings/tutor.py:/app/richie/sandbox/tutor.py:ro
- ../../data/richie/media:/data/media
{% endif %}
richie-openedx-job:
image: {{ DOCKER_IMAGE_OPENEDX }}
environment:
Expand Down
18 changes: 18 additions & 0 deletions tutorrichie/patches/local-docker-compose-services
@@ -1,3 +1,19 @@
{% if RICHIE_FACTORY_REPOSITORY %}
richie:
image: {{ RICHIE_FACTORY_DOCKER_IMAGE }}
restart: unless-stopped
user: "1000:1000"
env_file:
- ../plugins/richie/apps/env.d/production
volumes:
- ../plugins/richie/apps/settings/tutor.py:/app/richie/sites/{{ RICHIE_FACTORY_SITE }}/src/backend/{{ RICHIE_FACTORY_SITE }}/tutor.py:ro
- ../../data/richie/media:/data/media
depends_on:
- richie-permissions
{% if RUN_ELASTICSEARCH %}- elasticsearch{% endif %}
{% if RUN_LMS %}- lms{% endif %}
{% if RUN_MYSQL %}- mysql{% endif %}
{% else %}
richie:
image: {{ RICHIE_DOCKER_IMAGE }}
restart: unless-stopped
Expand All @@ -12,6 +28,8 @@ richie:
{% if RUN_ELASTICSEARCH %}- elasticsearch{% endif %}
{% if RUN_LMS %}- lms{% endif %}
{% if RUN_MYSQL %}- mysql{% endif %}
{% endif %}


richie-permissions:
image: {{ DOCKER_IMAGE_PERMISSIONS }}
Expand Down
5 changes: 5 additions & 0 deletions tutorrichie/patches/openedx-common-settings
@@ -1,2 +1,7 @@
# Richie settings (common)
FEATURES["ENABLE_MKTG_SITE"] = True

FEATURES["ENABLE_CROSS_DOMAIN_CSRF_COOKIE"] = True
CROSS_DOMAIN_CSRF_COOKIE_DOMAIN = ".{{ LMS_HOST }}"
CROSS_DOMAIN_CSRF_COOKIE_NAME = "edx_csrf_token"
SESSION_COOKIE_NAME = "edx_session"
5 changes: 5 additions & 0 deletions tutorrichie/patches/openedx-lms-production-settings
Expand Up @@ -5,3 +5,8 @@ MKTG_URLS = {
"ROOT": RICHIE_ROOT_URL
}
CORS_ORIGIN_WHITELIST.append("{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ RICHIE_HOST }}")
RICHIE_COURSE_HOOK = {
"secret": "{{ RICHIE_HOOK_SECRET }}",
"url": "http://richie:8000/api/v1.0/course-runs-sync/",
"timeout": 3,
}
9 changes: 7 additions & 2 deletions tutorrichie/plugin.py
Expand Up @@ -15,16 +15,21 @@
"defaults": {
"VERSION": __version__,
"DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-richie:{{ RICHIE_VERSION }}",
"RELEASE_VERSION": "v2.15.1",
"FACTORY_DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-richie-factory:{{ RICHIE_VERSION }}",
"RELEASE_VERSION": "v2.16.0",
"HOST": "courses.{{ LMS_HOST }}",
"MYSQL_DATABASE": "richie",
"MYSQL_USERNAME": "richie",
"ELASTICSEARCH_INDICES_PREFIX": "richie",
"FACTORY_REPOSITORY": "",
},
}

hooks = {
"build-image": {"richie": "{{ RICHIE_DOCKER_IMAGE }}"},
"build-image": {
"richie": "{{ RICHIE_DOCKER_IMAGE }}",
"richie-factory": "{{ RICHIE_FACTORY_DOCKER_IMAGE }}",
},
"remote-image": {"richie": "{{ RICHIE_DOCKER_IMAGE }}"},
"init": ["mysql", "richie", "richie-openedx"],
}
Expand Down
9 changes: 9 additions & 0 deletions tutorrichie/templates/richie/apps/env.d/production
@@ -1,4 +1,13 @@
{% if RICHIE_FACTORY_REPOSITORY %}
# Caches settings - makes debugging faster
# TODO Configure to use the redis service
CACHE_DEFAULT_BACKEND=django.core.cache.backends.locmem.LocMemCache
CACHE_DEFAULT_LOCATION=""
CACHE_DEFAULT_OPTIONS={}
DJANGO_SETTINGS_MODULE={{ RICHIE_FACTORY_SITE }}.tutor
{% else %}
DJANGO_SETTINGS_MODULE=tutor
{% endif %}
DJANGO_CONFIGURATION=TutorProduction
DJANGO_SECRET_KEY={{ RICHIE_SECRET_KEY}}
DJANGO_ALLOWED_HOSTS=richie,{{ RICHIE_HOST }}
Expand Down
7 changes: 7 additions & 0 deletions tutorrichie/templates/richie/apps/settings/tutor.py
Expand Up @@ -2,7 +2,11 @@
from django.utils.translation import gettext_lazy as _

from configurations import values
{% if RICHIE_FACTORY_REPOSITORY %}
from {{ RICHIE_FACTORY_SITE }}.settings import Development, Production
{% else %}
from settings import Development, Production
{% endif %}

supported_languages = [("en", _("English")),]
extra_language_code = "{{ LANGUAGE_CODE }}"
Expand Down Expand Up @@ -55,6 +59,8 @@ class TutorSettingsMixin:
}
PARLER_LANGUAGES = CMS_LANGUAGES

SESSION_ENGINE = "django.contrib.sessions.backends.db"

{{ patch("richie-settings-common")|indent(4) }}

class TutorProduction(TutorSettingsMixin, Production):
Expand All @@ -68,6 +74,7 @@ class TutorProduction(TutorSettingsMixin, Production):
SESSION_COOKIE_SECURE = False
{% endif %}

TEXT_CKEDITOR_BASE_PATH = f"//{{RICHIE_HOST}}/static/djangocms_text_ckeditor/ckeditor/"
{{ patch("richie-settings-production")|indent(4) }}


Expand Down
91 changes: 91 additions & 0 deletions tutorrichie/templates/richie/build/richie-factory/Dockerfile
@@ -0,0 +1,91 @@
ARG SITE={{ RICHIE_FACTORY_SITE }}

#--------- Base image with cloned repo
FROM python:3.7-bullseye as base

RUN apt update \
&& apt install -y git \
&& rm -rf /var/lib/apt/lists/*

# Clone repo
ARG RICHIE_FACTORY_REPOSITORY={{ RICHIE_FACTORY_REPOSITORY }}
ARG RICHIE_FACTORY_VERSION={{ RICHIE_FACTORY_VERSION }}
ARG SITE
RUN git clone $RICHIE_FACTORY_REPOSITORY --branch $RICHIE_FACTORY_VERSION --depth 1 /richie

#--------- Front-end builder image
FROM node:16 as frontend-builder

ARG SITE

COPY --from=base /richie/sites/${SITE}/src/frontend /app/richie/sites/${SITE}/src/frontend
WORKDIR /app/richie/sites/${SITE}/src/frontend
# --frozen-lockfile
RUN yarn install && \
yarn compile-translations && \
yarn build-ts-production && \
yarn build-sass-production

#--------- Production image
FROM python:3.7-bullseye as production

ARG SITE

RUN apt update \
&& apt install -y gettext git default-mysql-client \
&& rm -rf /var/lib/apt/lists/*

# User creation
RUN useradd --home-dir /app --create-home --uid=1000 openedx
RUN mkdir -p /data/media /data/static && chown -R openedx:openedx /data
USER openedx

COPY --from=base --chown=openedx:openedx /richie /app/richie
WORKDIR /app/richie/sites/${SITE}

# Install project (with requirements)
RUN python -m venv /app/venv
ENV PATH /app/venv/bin:${PATH}
RUN pip install pip==22.0.4 setuptools==62.1.0 wheel==0.37.1
RUN pip install -r requirements/base.txt
RUN pip install uwsgi==2.0.20
RUN pip install mysqlclient==2.1.0
# The django-cms fork includes drillable search feature,
# it should be removed when this feature will be officially released
# See upstream Dockerfile https://github.com/openfun/fun-richie-site-factory/blob/main/Dockerfile
RUN pip install git+https://github.com/jbpenrath/django-cms@fun-3.11.0#egg=django-cms
# Install requirements for storing media assets on S3/MinIO
RUN pip install django-storages==1.12.3 boto3==1.20.25

WORKDIR /app/richie/sites/${SITE}/src/backend

ENV PYTHONPATH "${PYTHONPATH}:/app/richie/sites/${SITE}/src/backend"
ENV DJANGO_SETTINGS_MODULE ${SITE}.settings
ENV DJANGO_CONFIGURATION Production
ENV DJANGO_SECRET_KEY setme
ENV DJANGO_AWS_ACCESS_KEY_ID setme
ENV DJANGO_AWS_SECRET_ACCESS_KEY setme

ENV SITE=${SITE}

# Collect static assets
COPY --from=frontend-builder --chown=openedx:openedx \
/app/richie/sites/${SITE}/src/backend/base/static/richie \
/app/richie/sites/${SITE}/src/backend/base/static/richie
RUN ./manage.py collectstatic

# Compile translations
RUN mkdir -p locale && ./manage.py compilemessages

# Run server
EXPOSE 8000
CMD uwsgi \
--static-map /static=/data/static/ \
--static-map /media=/data/media/ \
--http 0.0.0.0:8000 \
--thunder-lock \
--single-interpreter \
--enable-threads \
--processes=${UWSGI_WORKERS:-2} \
--buffer-size=8192 \
--wsgi-file ${SITE}/wsgi.py
3 changes: 2 additions & 1 deletion tutorrichie/templates/richie/build/richie/Dockerfile
Expand Up @@ -66,8 +66,9 @@ RUN ./sandbox/manage.py collectstatic
RUN ./sandbox/manage.py compilemessages

# Run server
WORKDIR /app/richie/sandbox
EXPOSE 8000
CMD cd sandbox && uwsgi \
CMD uwsgi \
--static-map /static=/data/static/ \
--static-map /media=/data/media/ \
--http 0.0.0.0:8000 \
Expand Down
7 changes: 4 additions & 3 deletions tutorrichie/templates/richie/hooks/richie/init
@@ -1,11 +1,12 @@
# TODO Update for richie-factory
# Fix media permissions
chown -R openedx:openedx /data/media

# Create tables
./sandbox/manage.py migrate
./manage.py migrate

# Create ES indices
./sandbox/manage.py bootstrap_elasticsearch
./manage.py bootstrap_elasticsearch

# Create required pages
./sandbox/manage.py richie_init
./manage.py richie_init

0 comments on commit 5ea228a

Please sign in to comment.