Skip to content

Commit

Permalink
refactor: get rid of the openedx Docker entrypoint
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
regisb committed Apr 15, 2022
1 parent 5de7bec commit d5a790d
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 22 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Note: Breaking changes between versions are indicated by "💥".

## Unreleased

- 💥[Improvement] Make it possible to run `tutor k8s exec <command with multiple arguments>` (#636). As a consequence, it is no longer possible to run quoted commands: `tutor k8s exec "<some command>"`. Instead, you should remove the quotes: `tutor k8s exec <some command>`.
- 💥[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 <command with multiple arguments>` (#636). As a consequence, it is no longer possible to run quoted commands: `tutor k8s exec "<some command>"`. Instead, you should remove the quotes: `tutor k8s exec <some command>`.

## v13.1.11 (2022-04-12)

Expand Down
4 changes: 1 addition & 3 deletions tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def test_set_theme(self, mock_stdout: StringIO) -> None:
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:
Expand Down
1 change: 0 additions & 1 deletion tutor/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from tutor.types import Config, get_typed

BASE_OPENEDX_COMMAND = """
export DJANGO_SETTINGS_MODULE=$SERVICE_VARIANT.envs.$SETTINGS
echo "Loading settings $DJANGO_SETTINGS_MODULE"
"""

Expand Down
8 changes: 3 additions & 5 deletions tutor/templates/build/openedx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
3 changes: 0 additions & 3 deletions tutor/templates/build/openedx/bin/docker-entrypoint.sh

This file was deleted.

2 changes: 1 addition & 1 deletion tutor/templates/build/openedx/bin/openedx-assets
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions tutor/templates/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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"

Expand Down
11 changes: 11 additions & 0 deletions tutor/templates/k8s/deployments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ spec:
env:
- name: SERVICE_VARIANT
value: cms
- name: DJANGO_SETTINGS_MODULE
value: cms.envs.tutor.production
ports:
- containerPort: 8000
volumeMounts:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tutor/templates/k8s/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tutor/templates/local/docker-compose.jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tutor/templates/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit d5a790d

Please sign in to comment.