From c9d0c9e91fc5bd8090d4d3cd63e323250c57d2e9 Mon Sep 17 00:00:00 2001 From: Jillian Vogel Date: Fri, 15 Nov 2024 17:32:49 +1030 Subject: [PATCH] feat: add bind and compose mount settings for superset to allow development on Superset within Aspects. --- tutoraspects/plugin.py | 28 +++++++++++++++++++ .../templates/base-docker-compose-services | 3 ++ 2 files changed, 31 insertions(+) diff --git a/tutoraspects/plugin.py b/tutoraspects/plugin.py index aeb89ba88..39c9033a3 100644 --- a/tutoraspects/plugin.py +++ b/tutoraspects/plugin.py @@ -480,6 +480,34 @@ def _aspects_public_hosts( pass +@hooks.Filters.IMAGES_BUILD_MOUNTS.add() +def _mount_superset_on_build( + mounts: list[tuple[str, str]], host_path: str +) -> list[tuple[str, str]]: + """ + Automatically add superset repo from the host to the build context whenever + it is added to the `MOUNTS` setting. + """ + if os.path.basename(host_path) == "superset": + mounts += [ + ("aspects-superset", "superset"), + ] + return mounts + + +@hooks.Filters.COMPOSE_MOUNTS.add() +def _mount_superset_compose( + volumes: list[tuple[str, str]], name: str +) -> list[tuple[str, str]]: + """ + When mounting superset with `tutor mounts add /path/to/superset" + bind-mount the host repo in the superset container. + """ + if name == "superset": + volumes += [("superset", "/app")] + return volumes + + ######################################## # INITIALIZATION TASKS ######################################## diff --git a/tutoraspects/templates/base-docker-compose-services b/tutoraspects/templates/base-docker-compose-services index 4f1fffa72..917208d3f 100644 --- a/tutoraspects/templates/base-docker-compose-services +++ b/tutoraspects/templates/base-docker-compose-services @@ -7,6 +7,9 @@ image: {{ DOCKER_IMAGE_SUPERSET }} - ../../env/plugins/aspects/apps/superset/superset_home:/app/superset_home - ../../env/plugins/aspects/apps/superset/scripts:/app/scripts - ../../env/plugins/aspects/build/aspects-superset/openedx-assets:/app/openedx-assets + {%- for mount in iter_mounts(MOUNTS, "superset") %} + - {{ mount }} + {%- endfor %} restart: unless-stopped environment: DATABASE_DIALECT: {{ SUPERSET_DB_DIALECT }}