diff --git a/apps/common/views.py b/apps/common/views.py index c69ccf8..4da19c2 100644 --- a/apps/common/views.py +++ b/apps/common/views.py @@ -2,15 +2,19 @@ import fsspec from dagster import AssetKey, DagsterEventType, DagsterInstance, EventRecordsFilter +from django.conf import settings from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin from django.http import Http404, HttpResponseRedirect from django.views import View from revproxy.views import ProxyView +EXPLORER_CLOUDFRONT_URL = settings.EXPLORER_CLOUDFRONT_URL + class DagsterProxyView(LoginRequiredMixin, PermissionRequiredMixin, ProxyView): login_url = "/admin/login/" - upstream = f"{os.environ.get('DAGSTER_WEBSERVER_URL')}/{os.environ.get('DAGSTER_WEBSERVER_PREFIX')}/" + # ignore type warning because parent class uses a property for "upstream" + upstream = f"{os.environ.get('DAGSTER_WEBSERVER_URL')}/{os.environ.get('DAGSTER_WEBSERVER_PREFIX')}/" # type: ignore permission_required = "common.access_dagster_ui" raise_exception = False @@ -55,3 +59,11 @@ def get(self, request, asset_name, partition_name=None): except Exception as e: raise Http404(f"Failed to locate or sign asset '{asset_name}': {str(e)}") + + +class BaselineExplorerProxyView(ProxyView): + """ + A revproxy view to serve the data explorer assets via a cloudfront distribution. + """ + + upstream = EXPLORER_CLOUDFRONT_URL # type: ignore diff --git a/docker-compose.yml b/docker-compose.yml index 9f038bc..cc9175c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,7 +54,6 @@ services: - -c - random_page_cost=0.11 - # MinIO is an Amazon S3 compatible object storage server. minio: restart: unless-stopped @@ -108,6 +107,7 @@ services: MINIO_ROOT_USER: ${MINIO_ROOT_USER} MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD} MINIO_ENDPOINT_URL: http://minio:9000 + EXPLORER_CLOUDFRONT_URL: ${EXPLORER_CLOUDFRONT_URL:-http://localhost:3000} SUPPORT_EMAIL_ADDRESS: ${SUPPORT_EMAIL_ADDRESS} DJANGO_MIGRATE: 1 GOOGLE_APPLICATION_CREDENTIALS: ${GOOGLE_APPLICATION_CREDENTIALS} @@ -178,4 +178,4 @@ volumes: db_data: external: false minio_data: - external: false \ No newline at end of file + external: false diff --git a/env.example b/env.example index d8cb1be..d557612 100644 --- a/env.example +++ b/env.example @@ -27,6 +27,7 @@ MINIO_ROOT_USER=minioadmin MINIO_ROOT_PASSWORD=minioadminpassword MINIO_ENDPOINT_URL=http://minio:9000 # change to http://localhost:9000 if using a local environment SUPPORT_EMAIL_ADDRESS=helpdesk@fews.net +EXPLORER_CLOUDFRONT_URL=http://localhost:3000 PIP_INDEX_URL=https://pypi.python.org/simple/ # Google API related settings diff --git a/hea/settings/base.py b/hea/settings/base.py index 8d87e96..7c76a9e 100644 --- a/hea/settings/base.py +++ b/hea/settings/base.py @@ -361,6 +361,11 @@ PRIVACY_URL = "https://help.fews.net/fdp/privacy-policy" DISCLAIMER_URL = "https://help.fews.net/fdp/data-and-information-use-and-attribution-policy" + +########## DATA EXPLORER CONFIGURATION +EXPLORER_CLOUDFRONT_URL = env.str("EXPLORER_CLOUDFRONT_URL") +########## End DATA EXPLORER CONFIGURATION + # Allow GDAL/GEOS library path overrides to be set in the environment, for MacOS. GDAL_LIBRARY_PATH = env("GDAL_LIBRARY_PATH", default=None) # For example, /opt/homebrew/lib/libgdal.dylib GEOS_LIBRARY_PATH = env("GEOS_LIBRARY_PATH", default=None) # For example, /opt/homebrew/lib/libgeos_c.dylib diff --git a/hea/urls.py b/hea/urls.py index 3d1641d..4b9512e 100644 --- a/hea/urls.py +++ b/hea/urls.py @@ -49,7 +49,7 @@ WealthGroupViewSet, WildFoodGatheringViewSet, ) -from common.views import AssetDownloadView, DagsterProxyView +from common.views import AssetDownloadView, BaselineExplorerProxyView, DagsterProxyView from common.viewsets import ( ClassifiedProductViewSet, CountryViewSet, @@ -147,6 +147,11 @@ AssetDownloadView.as_view(), name="asset_download_partitioned", ), + # Baseline Explorer React GUI using Django rev proxy to serve a cloudfront distro + path("baseline-explorer/", BaselineExplorerProxyView.as_view(), name="baseline_explorer"), + # The URL pattern below does not capture any path parameter from the URL. But django-revproxy views + # require a path argument. We manually pass a default: {"path": ""}. + path("baseline-explorer/", BaselineExplorerProxyView.as_view(), {"path": ""}, name="baseline_explorer"), ]