From d5a790d5d06c894804d08d187ab413f37aa80cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Tue, 12 Apr 2022 16:07:48 +0200 Subject: [PATCH] refactor: get rid of the openedx Docker entrypoint The entrypoint in the "openedx" Docker image was used only to define the DJANGO_SETTINGS_MODULE environment variable, based on SERVICE_VARIANT and SETTINGS. We ditch SETTINGS in favour of defining explicitely DJANGO_SETTINGS_MODULE. The problem with the Docker entrypoint is that it was bypassed whenever we ran `tutor local exec` or `tutor k8s exec`. By removing it we make it simpler for end-users to run manage.py commands in kubernetes. --- CHANGELOG.md | 3 ++- tests/test_jobs.py | 4 +--- tutor/jobs.py | 1 - tutor/templates/build/openedx/Dockerfile | 8 +++----- .../templates/build/openedx/bin/docker-entrypoint.sh | 3 --- tutor/templates/build/openedx/bin/openedx-assets | 2 +- tutor/templates/dev/docker-compose.yml | 6 ++++-- tutor/templates/k8s/deployments.yml | 11 +++++++++++ tutor/templates/k8s/jobs.yml | 7 +++++++ tutor/templates/local/docker-compose.jobs.yml | 4 ++-- tutor/templates/local/docker-compose.yml | 8 ++++---- 11 files changed, 35 insertions(+), 22 deletions(-) delete mode 100755 tutor/templates/build/openedx/bin/docker-entrypoint.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index eae645f..d3b31c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,11 @@ Note: Breaking changes between versions are indicated by "💥". ## Unreleased +- 💥[Improvement] Make it possible to run `tutor k8s exec ` (#636). As a consequence, it is no longer possible to run quoted commands: `tutor k8s exec ""`. Instead, you should remove the quotes: `tutor k8s exec `. +- 💥[Deprecation] Drop support for the `TUTOR_EDX_PLATFORM_SETTINGS` environment variable. It is now recommended to create a plugin instead. - 💥[Improvement] Complete overhaul of the plugin extension mechanism. Tutor now has a hook-based Python API: actions can be triggered at different points of the application life cycle and data can be modified thanks to custom filters. The v0 plugin API is still supported, for backward compatibility, but plugin developers are encouraged to migrate their plugins to the new API. See the new plugin tutorial for more information. - [Improvement] Improved the output of `tutor plugins list`. - [Feature] Add `tutor [dev|local|k8s] status` command, which provides basic information about the platform's status. -- 💥[Improvement] Make it possible to run `tutor k8s exec ` (#636). As a consequence, it is no longer possible to run quoted commands: `tutor k8s exec ""`. Instead, you should remove the quotes: `tutor k8s exec `. ## v13.1.11 (2022-04-12) diff --git a/tests/test_jobs.py b/tests/test_jobs.py index 6ba8a6a..56651ab 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -78,9 +78,7 @@ class JobsTests(unittest.TestCase): self.assertTrue( commands.group(2) .strip() - .startswith( - "export DJANGO_SETTINGS_MODULE=$SERVICE_VARIANT.envs.$SETTINGS" - ) + .startswith('echo "Loading settings $DJANGO_SETTINGS_MODULE"') ) def test_get_all_openedx_domains(self) -> None: diff --git a/tutor/jobs.py b/tutor/jobs.py index 797ef18..cd80d3b 100644 --- a/tutor/jobs.py +++ b/tutor/jobs.py @@ -4,7 +4,6 @@ from tutor import env, fmt, hooks from tutor.types import Config, get_typed BASE_OPENEDX_COMMAND = """ -export DJANGO_SETTINGS_MODULE=$SERVICE_VARIANT.envs.$SETTINGS echo "Loading settings $DJANGO_SETTINGS_MODULE" """ diff --git a/tutor/templates/build/openedx/Dockerfile b/tutor/templates/build/openedx/Dockerfile index ffcd996..638e724 100644 --- a/tutor/templates/build/openedx/Dockerfile +++ b/tutor/templates/build/openedx/Dockerfile @@ -203,12 +203,10 @@ RUN mkdir /openedx/data # service variant is "lms" or "cms" ENV SERVICE_VARIANT lms -ENV SETTINGS tutor.production +ENV DJANGO_SETTINGS_MODULE lms.envs.tutor.production {{ patch("openedx-dockerfile") }} -# Entrypoint will set right environment variables -ENTRYPOINT ["docker-entrypoint.sh"] EXPOSE 8000 ###### Intermediate image with dev/test dependencies @@ -235,7 +233,7 @@ RUN rm -r /openedx/staticfiles && \ {{ patch("openedx-dev-dockerfile-post-python-requirements") }} # Default django settings -ENV SETTINGS tutor.development +ENV DJANGO_SETTINGS_MODULE lms.envs.tutor.development CMD ./manage.py $SERVICE_VARIANT runserver 0.0.0.0:8000 @@ -252,4 +250,4 @@ CMD uwsgi \ --enable-threads \ --processes=${UWSGI_WORKERS:-2} \ --buffer-size=8192 \ - --wsgi-file ${SERVICE_VARIANT}/wsgi.py + --wsgi-file $SERVICE_VARIANT/wsgi.py diff --git a/tutor/templates/build/openedx/bin/docker-entrypoint.sh b/tutor/templates/build/openedx/bin/docker-entrypoint.sh deleted file mode 100755 index 235d2a6..0000000 --- a/tutor/templates/build/openedx/bin/docker-entrypoint.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -e -export DJANGO_SETTINGS_MODULE=$SERVICE_VARIANT.envs.$SETTINGS -exec "$@" \ No newline at end of file diff --git a/tutor/templates/build/openedx/bin/openedx-assets b/tutor/templates/build/openedx/bin/openedx-assets index 1d21038..1b89434 100755 --- a/tutor/templates/build/openedx/bin/openedx-assets +++ b/tutor/templates/build/openedx/bin/openedx-assets @@ -60,7 +60,7 @@ def main(): collect.add_argument( "-s", "--settings", - default=os.environ.get("SETTINGS"), + default="tutor.assets", help="Django settings module", ) collect.add_argument( diff --git a/tutor/templates/dev/docker-compose.yml b/tutor/templates/dev/docker-compose.yml index 7b2041d..06e85bc 100644 --- a/tutor/templates/dev/docker-compose.yml +++ b/tutor/templates/dev/docker-compose.yml @@ -8,8 +8,6 @@ x-openedx-service: target: development args: APP_USER_ID: "{{ HOST_USER_ID }}" - environment: - SETTINGS: tutor.development volumes: # Settings & config - ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro @@ -30,6 +28,8 @@ services: lms: <<: *openedx-service command: ./manage.py lms runserver 0.0.0.0:8000 + environment: + DJANGO_SETTINGS_MODULE: lms.envs.tutor.development ports: - "8000:8000" networks: @@ -40,6 +40,8 @@ services: cms: <<: *openedx-service command: ./manage.py cms runserver 0.0.0.0:8000 + environment: + DJANGO_SETTINGS_MODULE: lms.envs.tutor.development ports: - "8001:8000" diff --git a/tutor/templates/k8s/deployments.yml b/tutor/templates/k8s/deployments.yml index 1dc7d82..03a5c4a 100644 --- a/tutor/templates/k8s/deployments.yml +++ b/tutor/templates/k8s/deployments.yml @@ -67,6 +67,8 @@ spec: env: - name: SERVICE_VARIANT value: cms + - name: DJANGO_SETTINGS_MODULE + value: cms.envs.tutor.production ports: - containerPort: 8000 volumeMounts: @@ -117,6 +119,8 @@ spec: env: - name: SERVICE_VARIANT value: cms + - name: DJANGO_SETTINGS_MODULE + value: cms.envs.tutor.production volumeMounts: - mountPath: /openedx/edx-platform/lms/envs/tutor/ name: settings-lms @@ -160,6 +164,11 @@ spec: containers: - name: lms image: {{ DOCKER_IMAGE_OPENEDX }} + env: + - name: SERVICE_VARIANT + value: lms + - name: DJANGO_SETTINGS_MODULE + value: lms.envs.tutor.production ports: - containerPort: 8000 volumeMounts: @@ -210,6 +219,8 @@ spec: env: - name: SERVICE_VARIANT value: lms + - name: DJANGO_SETTINGS_MODULE + value: lms.envs.tutor.production volumeMounts: - mountPath: /openedx/edx-platform/lms/envs/tutor/ name: settings-lms diff --git a/tutor/templates/k8s/jobs.yml b/tutor/templates/k8s/jobs.yml index d514d01..7b75136 100644 --- a/tutor/templates/k8s/jobs.yml +++ b/tutor/templates/k8s/jobs.yml @@ -12,6 +12,11 @@ spec: containers: - name: lms image: {{ DOCKER_IMAGE_OPENEDX }} + env: + - name: SERVICE_VARIANT + value: lms + - name: DJANGO_SETTINGS_MODULE + value: lms.envs.tutor.production volumeMounts: - mountPath: /openedx/edx-platform/lms/envs/tutor/ name: settings-lms @@ -46,6 +51,8 @@ spec: env: - name: SERVICE_VARIANT value: cms + - name: DJANGO_SETTINGS_MODULE + value: cms.envs.tutor.production volumeMounts: - mountPath: /openedx/edx-platform/lms/envs/tutor/ name: settings-lms diff --git a/tutor/templates/local/docker-compose.jobs.yml b/tutor/templates/local/docker-compose.jobs.yml index 53f1f83..cf37413 100644 --- a/tutor/templates/local/docker-compose.jobs.yml +++ b/tutor/templates/local/docker-compose.jobs.yml @@ -9,7 +9,7 @@ services: image: {{ DOCKER_IMAGE_OPENEDX }} environment: SERVICE_VARIANT: lms - SETTINGS: tutor.production + DJANGO_SETTINGS_MODULE: lms.envs.tutor.production volumes: - ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro - ../apps/openedx/settings/cms:/openedx/edx-platform/cms/envs/tutor:ro @@ -20,7 +20,7 @@ services: image: {{ DOCKER_IMAGE_OPENEDX }} environment: SERVICE_VARIANT: cms - SETTINGS: tutor.production + DJANGO_SETTINGS_MODULE: cms.envs.tutor.production volumes: - ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro - ../apps/openedx/settings/cms:/openedx/edx-platform/cms/envs/tutor:ro diff --git a/tutor/templates/local/docker-compose.yml b/tutor/templates/local/docker-compose.yml index 16aaf67..adc9262 100644 --- a/tutor/templates/local/docker-compose.yml +++ b/tutor/templates/local/docker-compose.yml @@ -104,8 +104,8 @@ services: image: {{ DOCKER_IMAGE_OPENEDX }} environment: SERVICE_VARIANT: lms + DJANGO_SETTINGS_MODULE: lms.envs.tutor.production UWSGI_WORKERS: {{ OPENEDX_LMS_UWSGI_WORKERS }} - SETTINGS: tutor.production restart: unless-stopped volumes: - ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro @@ -135,8 +135,8 @@ services: image: {{ DOCKER_IMAGE_OPENEDX }} environment: SERVICE_VARIANT: cms + DJANGO_SETTINGS_MODULE: cms.envs.tutor.production UWSGI_WORKERS: {{ OPENEDX_CMS_UWSGI_WORKERS }} - SETTINGS: tutor.production restart: unless-stopped volumes: - ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro @@ -169,7 +169,7 @@ services: image: {{ DOCKER_IMAGE_OPENEDX }} environment: SERVICE_VARIANT: lms - SETTINGS: tutor.production + DJANGO_SETTINGS_MODULE: lms.envs.tutor.production command: celery worker --app=lms.celery --loglevel=info --hostname=edx.lms.core.default.%%h --maxtasksperchild=100 --exclude-queues=edx.cms.core.default restart: unless-stopped volumes: @@ -187,7 +187,7 @@ services: image: {{ DOCKER_IMAGE_OPENEDX }} environment: SERVICE_VARIANT: cms - SETTINGS: tutor.production + DJANGO_SETTINGS_MODULE: cms.envs.tutor.production command: celery worker --app=cms.celery --loglevel=info --hostname=edx.cms.core.default.%%h --maxtasksperchild 100 --exclude-queues=edx.lms.core.default restart: unless-stopped volumes: