Compare commits

...

4 Commits

Author SHA1 Message Date
Régis Behmo
803894a4dd feat: Dockerfile optimizations 2023-05-25 10:50:53 +02:00
Muhammad Faraz Maqsood
804b70e42d fix: fixed dependency error 2023-05-25 12:06:35 +05:00
Muhammad Faraz Maqsood
6eebef14c5 feat: add dependency of lms to discovery 2023-05-25 11:55:26 +05:00
Muhammad Faraz Maqsood
941127c00b feat: upgrade to palm 2023-05-24 18:16:38 +05:00
7 changed files with 78 additions and 34 deletions

View File

@ -2,7 +2,7 @@ variables:
TUTOR_PLUGIN: discovery TUTOR_PLUGIN: discovery
TUTOR_IMAGES: discovery TUTOR_IMAGES: discovery
TUTOR_PYPI_PACKAGE: tutor-discovery TUTOR_PYPI_PACKAGE: tutor-discovery
OPENEDX_RELEASE: olive OPENEDX_RELEASE: palm
GITHUB_REPO: overhangio/tutor-discovery GITHUB_REPO: overhangio/tutor-discovery
include: include:

View File

@ -34,8 +34,8 @@ setup(
long_description_content_type="text/x-rst", long_description_content_type="text/x-rst",
packages=find_packages(exclude=["tests*"]), packages=find_packages(exclude=["tests*"]),
include_package_data=True, include_package_data=True,
install_requires=["tutor>=15.0.0,<16.0.0"], install_requires=["tutor>=16.0.0,<17.0.0"],
python_requires=">=3.7", python_requires=">=3.8",
entry_points={"tutor.plugin.v1": ["discovery = tutordiscovery.plugin"]}, entry_points={"tutor.plugin.v1": ["discovery = tutordiscovery.plugin"]},
classifiers=[ classifiers=[
"Development Status :: 5 - Production/Stable", "Development Status :: 5 - Production/Stable",
@ -43,9 +43,9 @@ setup(
"License :: OSI Approved :: GNU Affero General Public License v3", "License :: OSI Approved :: GNU Affero General Public License v3",
"Operating System :: OS Independent", "Operating System :: OS Independent",
"Programming Language :: Python", "Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
], ],
) )

View File

@ -1,2 +1 @@
__version__ = "15.0.0" __version__ = "16.0.0"

View File

@ -4,4 +4,6 @@ discovery-job:
DEFAULT_PARTNER_CODE: openedx DEFAULT_PARTNER_CODE: openedx
volumes: volumes:
- ../plugins/discovery/apps/settings/tutor:/openedx/discovery/course_discovery/settings/tutor:ro - ../plugins/discovery/apps/settings/tutor:/openedx/discovery/course_discovery/settings/tutor:ro
depends_on: {{ [("lms", RUN_LMS), ("mysql", RUN_MYSQL)]|list_if }} depends_on:
- lms
{% if RUN_MYSQL %}- mysql{% endif %}

View File

@ -5,4 +5,7 @@ discovery:
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- ../plugins/discovery/apps/settings/tutor:/openedx/discovery/course_discovery/settings/tutor:ro - ../plugins/discovery/apps/settings/tutor:/openedx/discovery/course_discovery/settings/tutor:ro
depends_on: {{ [("elasticsearch", RUN_ELASTICSEARCH), ("lms", RUN_LMS), ("mysql", RUN_MYSQL)]|list_if }} depends_on:
- lms
{% if RUN_MYSQL %}- mysql{% endif %}
{% if RUN_ELASTICSEARCH %}- elasticsearch{% endif %}

View File

@ -1,6 +1,9 @@
from __future__ import annotations
from glob import glob from glob import glob
import os import os
import pkg_resources import pkg_resources
import typing as t
from tutor import hooks as tutor_hooks from tutor import hooks as tutor_hooks
@ -74,6 +77,7 @@ tutor_hooks.Filters.IMAGES_PUSH.add_item(
) )
) )
# Automount /openedx/discovery folder from the container # Automount /openedx/discovery folder from the container
@tutor_hooks.Filters.COMPOSE_MOUNTS.add() @tutor_hooks.Filters.COMPOSE_MOUNTS.add()
def _mount_course_discovery(mounts, name): def _mount_course_discovery(mounts, name):
@ -115,3 +119,17 @@ tutor_hooks.Filters.CONFIG_UNIQUE.add_items(
tutor_hooks.Filters.CONFIG_OVERRIDES.add_items( tutor_hooks.Filters.CONFIG_OVERRIDES.add_items(
list(config.get("overrides", {}).items()) list(config.get("overrides", {}).items())
) )
########################################
# Credentials Public Host
########################################
@tutor_hooks.Filters.APP_PUBLIC_HOSTS.add()
def _discovery_public_hosts(hosts: list[str], context_name: t.Literal["local", "dev"]) -> list[str]:
if context_name == "dev":
# todo: will may change the below dev port when i try this plugin in dev mode
hosts += ["discovery.{{ LMS_HOST }}:8000"]
else:
hosts += ["discovery.{{ LMS_HOST }}"]
return hosts

View File

@ -1,19 +1,39 @@
FROM docker.io/ubuntu:20.04 {% if is_buildkit_enabled() %}# syntax=docker/dockerfile:1.4{% endif %}
###### Minimal image with base system requirements for most stages
FROM docker.io/ubuntu:20.04 as minimal
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && \ RUN {% if is_buildkit_enabled() %}--mount=type=cache,target=/var/cache/apt,sharing=locked \
apt install -y curl git-core language-pack-en python3 python3-pip python3-venv \ --mount=type=cache,target=/var/lib/apt,sharing=locked{% endif %} \
build-essential libcairo2 libffi-dev libmysqlclient-dev libxml2-dev libxslt-dev libjpeg-dev libssl-dev apt update && \
apt install -y curl git-core language-pack-en python3 python3-pip python3-venv \
build-essential libcairo2 libffi-dev libmysqlclient-dev libxml2-dev libxslt-dev libjpeg-dev libssl-dev
ENV LC_ALL en_US.UTF-8 ENV LC_ALL en_US.UTF-8
###### Git-clone course-discovery repo
FROM minimal as code
ARG DISCOVERY_REPOSITORY=https://github.com/openedx/course-discovery.git
ARG DISCOVERY_VERSION='{{ OPENEDX_COMMON_VERSION }}'
RUN mkdir -p /openedx/discovery && \
git clone $DISCOVERY_REPOSITORY --branch $DISCOVERY_VERSION --depth 1 /openedx/discovery
##### Empty layer with just the repo at the root.
# This is useful when overriding the build context with a host repo:
# docker build --build-context course-discovery=/path/to/course-discovery
FROM scratch as discovery
COPY --from=code /openedx/discovery /
##### Production layer
FROM minimal as production
# Create app user
ARG APP_USER_ID=1000 ARG APP_USER_ID=1000
RUN if [ "$APP_USER_ID" = 0 ]; then echo "app user may not be root" && false; fi
RUN useradd --home-dir /openedx --create-home --shell /bin/bash --uid ${APP_USER_ID} app RUN useradd --home-dir /openedx --create-home --shell /bin/bash --uid ${APP_USER_ID} app
USER ${APP_USER_ID} USER ${APP_USER_ID}
ARG DISCOVERY_REPOSITORY=https://github.com/edx/course-discovery.git # Copy repo
ARG DISCOVERY_VERSION={{ OPENEDX_COMMON_VERSION }} COPY --chown=app:app --from=discovery / /openedx/discovery
RUN mkdir -p /openedx/discovery && \
git clone $DISCOVERY_REPOSITORY --branch $DISCOVERY_VERSION --depth 1 /openedx/discovery
WORKDIR /openedx/discovery WORKDIR /openedx/discovery
# Setup empty yml config file, which is required by production settings # Setup empty yml config file, which is required by production settings
@ -23,35 +43,37 @@ ENV DISCOVERY_CFG /openedx/config.yml
# Install python venv # Install python venv
RUN python3 -m venv ../venv/ RUN python3 -m venv ../venv/
ENV PATH "/openedx/venv/bin:$PATH" ENV PATH "/openedx/venv/bin:$PATH"
# https://pypi.org/project/setuptools/
# https://pypi.org/project/pip/ RUN {% if is_buildkit_enabled() %}--mount=type=cache,target=/openedx/.cache/pip,sharing=shared {% endif %}pip install \
# https://pypi.org/project/wheel/ # https://pypi.org/project/setuptools/
RUN pip install setuptools==65.5.1 pip==22.3.1 wheel==0.38.4 # https://pypi.org/project/pip/
# https://pypi.org/project/wheel/
setuptools==67.7.2 pip==23.1.2. wheel==0.40.0
# Install a recent version of nodejs # Install a recent version of nodejs
RUN pip install nodeenv RUN pip install nodeenv==1.7.0
# nodejs version picked from https://github.com/openedx/course-discovery/blob/master/Dockerfile # nodejs version picked from https://github.com/openedx/course-discovery/blob/master/Dockerfile
RUN nodeenv /openedx/nodeenv --node=16.14.2 --prebuilt RUN nodeenv /openedx/nodeenv --node=16.14.2 --prebuilt
ENV PATH /openedx/nodeenv/bin:${PATH} ENV PATH /openedx/nodeenv/bin:${PATH}
# Install npm/bower requirements
ARG NPM_REGISTRY='{{ NPM_REGISTRY }}'
RUN {% if is_buildkit_enabled() %}--mount=type=cache,target=/openedx/.npm/,sharing=shared,uid=${APP_USER_ID} {% endif %}npm clean-install --no-audit --registry=$NPM_REGISTRY --production
RUN {% if is_buildkit_enabled() %}--mount=type=cache,target=/openedx/.cache/bower/,sharing=shared,uid=${APP_USER_ID} {% endif %}./node_modules/.bin/bower install --allow-root --production
# Install python and nodejs requirements # Install python and nodejs requirements
# This is identical to "make production-requirements" but it was split in multiple # This is identical to "make production-requirements" but it was split in multiple
# instructions to benefit from docker image caching # instructions to benefit from docker image caching
RUN pip install -r requirements.txt # Install base requirements
{% for extra_requirements in DISCOVERY_EXTRA_PIP_REQUIREMENTS %}RUN pip install '{{ extra_requirements }}' RUN {% if is_buildkit_enabled() %}--mount=type=cache,target=/openedx/.cache/pip,sharing=shared {% endif %}pip install -r requirements.txt
{% for extra_requirement in DISCOVERY_EXTRA_PIP_REQUIREMENTS %}RUN {% if is_buildkit_enabled() %}--mount=type=cache,target=/openedx/.cache/pip,sharing=shared {% endif %}pip install '{{ extra_requirements }}'
{% endfor %} {% endfor %}
ARG NPM_REGISTRY={{ NPM_REGISTRY }} # Install extra requirements
RUN npm install --verbose --registry=$NPM_REGISTRY --production RUN {% if is_buildkit_enabled() %}--mount=type=cache,target=/openedx/.cache/pip,sharing=shared {% endif %}pip install \
RUN ./node_modules/.bin/bower install --allow-root --production # Use redis as a django cache https://pypi.org/project/django-redis/
django-redis==5.2.0 \
# Install django-redis for using redis as a django cache # uwsgi server https://pypi.org/project/uWSGI/
# https://pypi.org/project/django-redis/ uwsgi==2.0.21
RUN pip install django-redis==5.2.0
# Install uwsgi
# https://pypi.org/project/uWSGI/
RUN pip install uwsgi==2.0.21
# Collect static assets # Collect static assets
COPY --chown=app:app assets.py ./course_discovery/settings/assets.py COPY --chown=app:app assets.py ./course_discovery/settings/assets.py