Skip to content

Commit 4a0ba80

Browse files
committed
EXPLORER_CLOUDFRONT_URL & revproxy - HEA-454
1 parent dc5c5d5 commit 4a0ba80

5 files changed

Lines changed: 27 additions & 4 deletions

File tree

apps/common/views.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
import fsspec
44
from dagster import AssetKey, DagsterEventType, DagsterInstance, EventRecordsFilter
5+
from django.conf import settings
56
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
67
from django.http import Http404, HttpResponseRedirect
78
from django.views import View
89
from revproxy.views import ProxyView
910

11+
EXPLORER_CLOUDFRONT_URL = settings.EXPLORER_CLOUDFRONT_URL
12+
1013

1114
class DagsterProxyView(LoginRequiredMixin, PermissionRequiredMixin, ProxyView):
1215
login_url = "/admin/login/"
13-
upstream = f"{os.environ.get('DAGSTER_WEBSERVER_URL')}/{os.environ.get('DAGSTER_WEBSERVER_PREFIX')}/"
16+
# ignore type warning because parent class uses a property for "upstream"
17+
upstream = f"{os.environ.get('DAGSTER_WEBSERVER_URL')}/{os.environ.get('DAGSTER_WEBSERVER_PREFIX')}/" # type: ignore
1418
permission_required = "common.access_dagster_ui"
1519
raise_exception = False
1620

@@ -55,3 +59,11 @@ def get(self, request, asset_name, partition_name=None):
5559

5660
except Exception as e:
5761
raise Http404(f"Failed to locate or sign asset '{asset_name}': {str(e)}")
62+
63+
64+
class DataExplorerProxyView(ProxyView):
65+
"""
66+
A revproxy view to serve the data explorer assets via a cloudfront distribution.
67+
"""
68+
69+
upstream = EXPLORER_CLOUDFRONT_URL # type: ignore

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ services:
5454
- -c
5555
- random_page_cost=0.11
5656

57-
5857
# MinIO is an Amazon S3 compatible object storage server.
5958
minio:
6059
restart: unless-stopped
@@ -108,6 +107,7 @@ services:
108107
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
109108
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
110109
MINIO_ENDPOINT_URL: http://minio:9000
110+
EXPLORER_CLOUDFRONT_URL: ${EXPLORER_CLOUDFRONT_URL:-http://localhost:3000}
111111
SUPPORT_EMAIL_ADDRESS: ${SUPPORT_EMAIL_ADDRESS}
112112
DJANGO_MIGRATE: 1
113113
GOOGLE_APPLICATION_CREDENTIALS: ${GOOGLE_APPLICATION_CREDENTIALS}
@@ -178,4 +178,4 @@ volumes:
178178
db_data:
179179
external: false
180180
minio_data:
181-
external: false
181+
external: false

env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ MINIO_ROOT_USER=minioadmin
2727
MINIO_ROOT_PASSWORD=minioadminpassword
2828
MINIO_ENDPOINT_URL=http://minio:9000 # change to http://localhost:9000 if using a local environment
2929
SUPPORT_EMAIL_ADDRESS=helpdesk@fews.net
30+
EXPLORER_CLOUDFRONT_URL=http://localhost:3000
3031
PIP_INDEX_URL=https://pypi.python.org/simple/
3132

3233
# Google API related settings

hea/settings/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@
361361
PRIVACY_URL = "https://help.fews.net/fdp/privacy-policy"
362362
DISCLAIMER_URL = "https://help.fews.net/fdp/data-and-information-use-and-attribution-policy"
363363

364+
365+
########## DATA EXPLORER CONFIGURATION
366+
EXPLORER_CLOUDFRONT_URL = env.str("EXPLORER_CLOUDFRONT_URL")
367+
########## End DATA EXPLORER CONFIGURATION
368+
364369
# Allow GDAL/GEOS library path overrides to be set in the environment, for MacOS.
365370
GDAL_LIBRARY_PATH = env("GDAL_LIBRARY_PATH", default=None) # For example, /opt/homebrew/lib/libgdal.dylib
366371
GEOS_LIBRARY_PATH = env("GEOS_LIBRARY_PATH", default=None) # For example, /opt/homebrew/lib/libgeos_c.dylib

hea/urls.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
WealthGroupViewSet,
5050
WildFoodGatheringViewSet,
5151
)
52-
from common.views import AssetDownloadView, DagsterProxyView
52+
from common.views import AssetDownloadView, DagsterProxyView, DataExplorerProxyView
5353
from common.viewsets import (
5454
ClassifiedProductViewSet,
5555
CountryViewSet,
@@ -147,6 +147,11 @@
147147
AssetDownloadView.as_view(),
148148
name="asset_download_partitioned",
149149
),
150+
# Baseline Explorer React GUI using Django rev proxy to serve a cloudfront distro
151+
path("baseline-explorer/<path:path>", DataExplorerProxyView.as_view(), name="baseline_explorer"),
152+
# The URL pattern below does not capture any path parameter from the URL. But django-revproxy views
153+
# require a path argument. We manually pass a default: {"path": ""}.
154+
path("baseline-explorer/", DataExplorerProxyView.as_view(), {"path": ""}, name="baseline_explorer"),
150155
]
151156

152157

0 commit comments

Comments
 (0)