Skip to content

Commit 0fb2009

Browse files
authored
Merge pull request #140 from natcap/bugfix/132-env-urls
Remove hard-coded clipping service URL
2 parents 8a487b2 + 6f4ff3c commit 0fb2009

File tree

7 files changed

+40
-64
lines changed

7 files changed

+40
-64
lines changed

.env.example

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ CKANEXT__SPATIAL__COMMON_MAP__MAPBOX__ACCESS_TOKEN=""
9696
CKANEXT__SPATIAL__COMMON_MAP__MAPBOX__MAP_ID=""
9797

9898
# Config for mappreview
99-
CKANEXT__MAPPREVIEW__MAPBOX_API_KEY=""
100-
CKANEXT__MAPPREVIEW__MAPBOX_STYLE=""
101-
CKANEXT__MAPPREVIEW__TITILER_URL=""
99+
CKANEXT__MAPPREVIEW__MAPBOX_API_KEY="FIXME"
100+
CKANEXT__MAPPREVIEW__MAPBOX_STYLE="mapbox://styles/FIXME"
101+
CKANEXT__MAPPREVIEW__TITILER_URL="https://titiler-897938321824.us-west1.run.app"
102+
CKANEXT__MAPPREVIEW__CLIPPING_SERVICE_URL="https://clipping-service-897938321824.us-west1.run.app"
102103

103104
# Theme configuration
104105
CKAN__SITE_LOGO=NatCapLogo.jpg
@@ -116,10 +117,6 @@ CKAN__AUTH__PUBLIC_USER_DETAILS=false
116117
# Config for or_facet, allow OR logic for facets
117118
CKANEXT__OR_FACET__OPTIONAL="extras_sources_res_formats extras_placenames tags"
118119

119-
CKANEXT__MAPPREVIEW__MAPBOX_API_KEY="FIXME"
120-
CKANEXT__MAPPREVIEW__MAPBOX_STYLE="mapbox://styles/FIXME"
121-
CKANEXT__MAPPREVIEW__TITILER_URL="https://titiler-897938321824.us-west1.run.app"
122-
123120
CKAN___GOOGLEANALYTICS__ID="G-3EBTM23KV6" # The tracking id, could be from GA4. Google says this is not a secret.
124121
CKAN___GOOGLEANALYTICS__ACCOUNT="data.naturalcapitalproject.stanford.edu" # our GA account name, from the upper-right of the GA panel
125122
#CKANEXT__GOOGLEANALYTICS_USERNAME="" # README says this is required, but I'm not seeing it in the source code and I don't want to provide it. Doesn't appear to be needed.

Makefile

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: deploy deploy-staging sync-on-prod fetch-nginx-config
1+
.PHONY: deploy deploy-staging sync-on-prod fetch-nginx-config clipping-service env-clip ckan-dev
22

33
GIT_DIR := /opt/ckan-catalog/data.naturalcapitalproject.stanford.edu
44
CKAN_PROD_URL := https://data.naturalcapitalproject.stanford.edu
@@ -24,3 +24,22 @@ fetch-nginx-config:
2424
gcloud compute scp $(GCLOUD_COMMON_ARGS) $(PROD_VM_NAME):/etc/nginx/sites-enabled/ckan host-nginx/etc.nginx.sites-available.ckan
2525
gcloud compute scp $(GCLOUD_COMMON_ARGS) $(PROD_VM_NAME):/etc/nginx/nginx.conf host-nginx/etc.nginx.nginx.conf
2626
gcloud compute scp $(GCLOUD_COMMON_ARGS) $(PROD_VM_NAME):/etc/nginx/throttle-bots.conf host-nginx/etc.nginx.throttle-bots.conf
27+
28+
29+
# Targets for local development:
30+
CLIP_ENV := clipenv
31+
32+
env-clip:
33+
conda create -n $(CLIP_ENV) -y -c conda-forge python=3.12
34+
conda env update -n $(CLIP_ENV) --file ./clipping-service/app/requirements.txt
35+
conda env config vars set -n $(CLIP_ENV) DEV_MODE=True
36+
@echo "To activate the environment and run the clipping service:"
37+
@echo ">> conda activate $(CLIP_ENV)"
38+
@echo ">> make clipping-service"
39+
40+
clipping-service:
41+
python -m gunicorn --chdir ./clipping-service/app app:app --reload
42+
43+
ckan-dev:
44+
docker compose -f docker-compose.dev.yml build
45+
docker compose -f docker-compose.dev.yml up --watch

clipping-service/app/app.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,22 @@
2424
from osgeo import osr
2525

2626
app = flask.Flask(__name__, template_folder='templates')
27+
28+
cors_origins = [
29+
'https://data-staging.naturalcapitalproject.org',
30+
'https://data.naturalcapitalproject.stanford.edu'
31+
]
32+
33+
if os.environ.get("DEV_MODE"):
34+
cors_origins.append("https://localhost:*")
35+
2736
CORS(app, resources={
2837
'/*': {
29-
'origins': [
30-
# Only use localhost for local development.
31-
# 'http://localhost:*',
32-
# 'http://127.0.0.1:*',
33-
'https://data-staging.naturalcapitalproject.org',
34-
'https://data.naturalcapitalproject.stanford.edu',
35-
]
38+
'origins': cors_origins
3639
}
3740
})
38-
logging.basicConfig(level=logging.DEBUG)
3941

42+
logging.basicConfig(level=logging.DEBUG)
4043

4144
# PLAN: write a logging handler to listen for progress messages and send those
4245
# to the client.

docker-compose.dev.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ services:
3636
- redisnet
3737
env_file:
3838
- .env
39+
environment:
40+
- CKANEXT__MAPPREVIEW__CLIPPING_SERVICE_URL=http://localhost:8000
3941
depends_on:
4042
db:
4143
condition: service_healthy

src/ckanext-mappreview/ckanext/mappreview/assets/js/mappreview.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ ckan.module("mappreview", function ($, _) {
152152

153153
const config = JSON.parse(this.options.config.replace(/'/g, '"'));
154154
const globalConfig = this._getGlobalConfig();
155+
const clipping_service_url = this._getGlobalConfig().clipping_service_url;
155156

156157
mapboxgl.accessToken = globalConfig.mapbox_api_key;
157158
const map = new mapboxgl.Map({
@@ -909,7 +910,6 @@ ckan.module("mappreview", function ($, _) {
909910
clipping_options['target_cellsize'] = [target_pixel_size, -target_pixel_size];
910911
}
911912

912-
const clipping_service_url = 'https://clipping-service-897938321824.us-west1.run.app';
913913
fetch(`${clipping_service_url}/clip`, {
914914
method: "POST",
915915
body: JSON.stringify(clipping_options),
@@ -987,12 +987,9 @@ ckan.module("mappreview", function ($, _) {
987987
document.getElementById('natcap-clip-submit-button').innerHTML = submit_text;
988988
});
989989

990-
const clipping_endpoint = 'https://clipping-service-897938321824.us-west1.run.app'
991-
992-
993990
function _setEPSGItems(epsg_code) {
994991
console.log(`Updating SRS info for ${epsg_code}`);
995-
fetch(`${clipping_endpoint}/epsg_info?epsg_code=${epsg_code}`, {
992+
fetch(`${clipping_service_url}/epsg_info?epsg_code=${epsg_code}`, {
996993
method: "GET",
997994
}).then(epsg_response => {
998995
if (epsg_response.ok) {
@@ -1028,7 +1025,7 @@ ckan.module("mappreview", function ($, _) {
10281025
console.log('updating source raster from cog ' + cog);
10291026

10301027
var epsg_input = document.getElementById('natcapClipSettingEPSGCode');
1031-
var cog_stats_url = `${clipping_endpoint}/info?cog_url=${encodeURIComponent(cog)}`;;
1028+
var cog_stats_url = `${clipping_service_url}/info?cog_url=${encodeURIComponent(cog)}`;
10321029
fetch(cog_stats_url).then(response => {
10331030
if (response.ok) {
10341031
return response.json();

src/ckanext-natcap/ckanext/natcap/assets/js/natcap-dataset-clip.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/ckanext-natcap/ckanext/natcap/assets/webassets.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ natcap-js:
66
- js/natcap-spatial-query.js
77
- js/natcap-textarea-copy.js
88
- js/natcap-advanced-search.js
9-
- js/natcap-dataset-clip.js
109
- js/natcap-copy-url.js
1110
- js/natcap-text-linkify.js
1211
extra:

0 commit comments

Comments
 (0)