From 42925e148034124c78794d99e8d72a62aa6ce703 Mon Sep 17 00:00:00 2001 From: Etienne Pelletier Date: Mon, 25 Nov 2024 19:46:48 -0500 Subject: [PATCH] changes for mapscript API updates in MapServer 8 (#99) --- Dockerfile | 7 +- docker/docker-compose.override.yml | 1 - docker/docker-compose.yml | 1 - docker/entrypoint.sh | 19 ++++++ geomet_climate/mapfile.py | 1 - geomet_climate/resources/mapfile-base.json | 1 - geomet_climate/wsgi.py | 76 +++++++++------------- 7 files changed, 54 insertions(+), 52 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7791e06..8d02fb6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,12 +15,17 @@ ENV BASEDIR=/data/web/geomet-climate-nightly \ GEOMET_CLIMATE_ES_URL=https://${GEOMET_CLIMATE_ES_USERNAME}:${GEOMET_CLIMATE_ES_PASSWORD}@localhost:9200 \ GEOMET_CLIMATE_OWS_DEBUG=5 # GEOMET_CLIMATE_OWS_LOG=/tmp/geomet-climate-ows.log +ENV DEBIAN_FRONTEND=noninteractive +ENV MAPSERVER_CONFIG_FILE=${BASEDIR}/build/mapserver.config +ENV MS_MAP_PATTERN=${BASEDIR}/build/mapfile/.* WORKDIR $BASEDIR # Install system dependencies RUN apt update && apt install -y software-properties-common && \ - ## Add this WMO PPA + ## Add this UbuntuGIS PPA (mappyfile) + add-apt-repository ppa:ubuntugis/ppa && apt update && \ + ## Add this WMO PPA (mapserver) add-apt-repository ppa:gcpp-kalxas/wmo-staging && apt update && \ ## Install dependencies from debian/control apt install -y mapserver-bin python3-all python3-pip python3-click python3-gdal python3-mappyfile python3-mapscript python3-matplotlib python3-numpy python3-pyproj python3-yaml proj-bin proj-data python3-certifi && \ diff --git a/docker/docker-compose.override.yml b/docker/docker-compose.override.yml index 96b90f2..de39119 100644 --- a/docker/docker-compose.override.yml +++ b/docker/docker-compose.override.yml @@ -3,7 +3,6 @@ services: build: args: GEOMET_CLIMATE_URL: https://geomet-dev-31-nightly.edc-mtl.ec.gc.ca/geomet-climate - # GEOMET_CLIMATE_URL: http://geomet-dev-31.edc-mtl.ec.gc.ca:8099 environment: GEOMET_CLIMATE_OWS_DEBUG: 5 GEOMET_CLIMATE_ES_URL: http://${GEOMET_CLIMATE_ES_USERNAME}:${GEOMET_CLIMATE_ES_PASSWORD}@localhost:9200 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index d419781..ca9c150 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -15,7 +15,6 @@ services: # for SSL-enabled connections to internal hosts (geomet-dev-xx.edc-mtl.ec.gc.ca) - "/etc/ssl/certs:/etc/ssl/certs:ro" # mount host ssl certs - "/usr/local/share/ca-certificates/:/usr/local/share/ca-certificates/:ro" # mount host ca-certificates - networks: default: name: geomet_default diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index ec3e51c..8e23bcb 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -3,6 +3,7 @@ BASEDIR=/data/web/geomet-climate-nightly GEOMET_CLIMATE_BASEDIR=$BASEDIR/build GEOMET_CLIMATE_ES_URL=${GEOMET_CLIMATE_ES_URL} +MAPSERVER_CONFIG_FILE=${MAPSERVER_CONFIG_FILE} # replace localhost ES URL with docker-host URL to ES if [ $GEOMET_CLIMATE_ES_URL != "" ] @@ -13,6 +14,21 @@ fi cd $BASEDIR +# Ensure the directory for MAPSERVER_CONFIG_FILE exists +mkdir -p "$(dirname "$MAPSERVER_CONFIG_FILE")" + +# Ensure MAPSERVER_CONFIG_FILE exists; create it if it doesn't +if [ ! -f "$MAPSERVER_CONFIG_FILE" ]; then + echo "CONFIG" > "$MAPSERVER_CONFIG_FILE" + echo "END" >> "$MAPSERVER_CONFIG_FILE" + echo "MapServer config file created: $MAPSERVER_CONFIG_FILE" +else + echo "MapServer config file already exists: $MAPSERVER_CONFIG_FILE" +fi + +# Set appropriate permissions for the config file +chmod 644 "$MAPSERVER_CONFIG_FILE" + echo "Generating geomet-climate VRTs for all layers..." geomet-climate vrt generate echo "Generating geomet-climate tileindex for all layers..." @@ -36,6 +52,9 @@ mapserv -nh QUERY_STRING="map=$GEOMET_CLIMATE_BASEDIR/mapfile/geomet-climate-WCS echo "Caching WCS (French)..." mapserv -nh QUERY_STRING="map=$GEOMET_CLIMATE_BASEDIR/mapfile/geomet-climate-WCS-fr.map&lang=fr&service=WCS&version=2.1.0&request=GetCapabilities" > $GEOMET_CLIMATE_BASEDIR/geomet-climate-WCS-2.0.1-capabilities-fr.xml && mv -f $GEOMET_CLIMATE_BASEDIR/geomet-climate-WCS-2.0.1-capabilities-fr.xml $GEOMET_CLIMATE_BASEDIR/mapfile + + + echo "Done." # server runs diff --git a/geomet_climate/mapfile.py b/geomet_climate/mapfile.py index 2e5e0a8..6e5ee08 100755 --- a/geomet_climate/mapfile.py +++ b/geomet_climate/mapfile.py @@ -231,7 +231,6 @@ def gen_layer(layer_name, layer_info, template_path, service='WMS'): 'classes': [] } layer['type'] = 'RASTER' - layer['dump'] = True layer['template'] = template_path layer['name'] = layer_name layer['tolerance'] = 150 diff --git a/geomet_climate/resources/mapfile-base.json b/geomet_climate/resources/mapfile-base.json index d187ab1..2529ddb 100644 --- a/geomet_climate/resources/mapfile-base.json +++ b/geomet_climate/resources/mapfile-base.json @@ -3,7 +3,6 @@ "name": "geomet-climate", "imagetype": "PNG", "status": "ON", - "transparent": "ON", "debug": "OFF", "maxsize": 4096, "size": [500, 300], diff --git a/geomet_climate/wsgi.py b/geomet_climate/wsgi.py index ca856c6..35c316a 100755 --- a/geomet_climate/wsgi.py +++ b/geomet_climate/wsgi.py @@ -60,46 +60,28 @@ def metadata_lang(m, lg): function to update the mapfile MAP metadata keys in function of the lang of the request - :param m: mapfile object to update language + :param m: mapfile.web object to update language :param lg: lang of the request """ - m.setMetaData('ows_address', - m.getMetaData('ows_address_{}'.format(lg))) - m.setMetaData('ows_contactperson', - m.getMetaData('ows_contactperson_{}'.format(lg))) - m.setMetaData('ows_city', - m.getMetaData('ows_city_{}'.format(lg))) - m.setMetaData('ows_country', - m.getMetaData('ows_country_{}'.format(lg))) - m.setMetaData('ows_keywordlist_http://purl.org/dc/terms/_items', - m.getMetaData('ows_keywordlist_http://purl.org/dc/terms/_items_{}'.format(lg))) # noqa - m.setMetaData('wms_attribution_title', - m.getMetaData('wms_attribution_title_{}'.format(lg))) - m.setMetaData('ows_contactinstructions', - m.getMetaData('ows_contactinstructions_{}'.format(lg))) - m.setMetaData('ows_contactposition', - m.getMetaData('ows_contactposition_{}'.format(lg))) - m.setMetaData('ows_contactorganization', - m.getMetaData('ows_contactorganization_{}'.format(lg))) - m.setMetaData('wms_attribution_onlineresource', - m.getMetaData('wms_attribution_onlineresource_{}'.format(lg))) # noqa - m.setMetaData('ows_onlineresource', - m.getMetaData('ows_onlineresource_{}'.format(lg))) - m.setMetaData('ows_abstract', - m.getMetaData('ows_abstract_{}'.format(lg))) - m.setMetaData('ows_service_onlineresource', - m.getMetaData('ows_service_onlineresource_{}'.format(lg))) - m.setMetaData('ows_title', - m.getMetaData('ows_title_{}'.format(lg))) - m.setMetaData('ows_hoursofservice', - m.getMetaData('ows_hoursofservice_{}'.format(lg))) - m.setMetaData('ows_stateorprovince', - m.getMetaData('ows_stateorprovince_{}'.format(lg))) - m.setMetaData('ows_keywordlist', - m.getMetaData('ows_keywordlist_{}'.format(lg))) - m.setMetaData('wcs_description', - m.getMetaData('wcs_description_{}'.format(lg))) + m.metadata['ows_address'] = m.metadata[f'ows_address_{lg}'] + m.metadata['ows_contactperson'] = m.metadata[f'ows_contactperson_{lg}'] + m.metadata['ows_city'] = m.metadata[f'ows_city_{lg}'] + m.metadata['ows_country'] = m.metadata[f'ows_country_{lg}'] + m.metadata['ows_keywordlist_http://purl.org/dc/terms/_items'] = m.metadata[f'ows_keywordlist_http://purl.org/dc/terms/_items_{lg}'] # noqa + m.metadata['wms_attribution_title'] = m.metadata[f'wms_attribution_title_{lg}'] # noqa + m.metadata['ows_contactinstructions'] = m.metadata[f'ows_contactinstructions_{lg}'] # noqa + m.metadata['ows_contactposition'] = m.metadata[f'ows_contactposition_{lg}'] # noqa + m.metadata['ows_contactorganization'] = m.metadata[f'ows_contactorganization_{lg}'] # noqa + m.metadata['wms_attribution_onlineresource'] = m.metadata[f'wms_attribution_onlineresource_{lg}'] # noqa + m.metadata['ows_onlineresource'] = m.metadata[f'ows_onlineresource_{lg}'] + m.metadata['ows_abstract'] = m.metadata[f'ows_abstract_{lg}'] + m.metadata['ows_service_onlineresource'] = m.metadata[f'ows_service_onlineresource_{lg}'] # noqa + m.metadata['ows_title'] = m.metadata[f'ows_title_{lg}'] + m.metadata['ows_hoursofservice'] = m.metadata[f'ows_hoursofservice_{lg}'] + m.metadata['ows_stateorprovince'] = m.metadata[f'ows_stateorprovince_{lg}'] # noqa + m.metadata['ows_keywordlist'] = m.metadata[f'ows_keywordlist_{lg}'] + m.metadata['wcs_description'] = m.metadata[f'wcs_description_{lg}'] def get_custom_service_exception(code, locator, text): @@ -192,12 +174,14 @@ def application(env, start_response): LOGGER.debug('Loading mapfile: {}'.format(mapfile_)) mapfile = mapscript.mapObj(mapfile_) if request_ == 'GetCapabilities' and lang == 'fr': - metadata_lang(mapfile, lang) + metadata_lang(mapfile.web, lang) layerobj = mapfile.getLayerByName(layer) - layerobj.setMetaData('ows_title', - layerobj.getMetaData('ows_title_{}'.format(lang))) # noqa - layerobj.setMetaData('ows_layer_group', - layerobj.getMetaData('ows_layer_group_{}'.format(lang))) # noqa + layerobj.metadata['ows_title'] = layerobj.metadata[ + f'ows_title_{lang}' + ] + layerobj.metadata['ows_layer_group'] = layerobj.metadata[ + f'ows_layer_group_{lang}' + ] elif request_ == 'GetLegendGraphic' and layer is not None: mapfile = mapscript.mapObj(mapfile_) @@ -218,15 +202,13 @@ def application(env, start_response): layerobj = mapfile.getLayerByName(layer) if request_ == 'GetCapabilities' and lang == 'fr': metadata_lang(mapfile, lang) - layerobj.setMetaData('ows_title', - layerobj.getMetaData('ows_title_{}'.format(lang))) # noqa - layerobj.setMetaData('ows_layer_group', - layerobj.getMetaData('ows_layer_group_{}'.format(lang))) # noqa + layerobj.metadata['ows_title'] = layerobj.metadata[f'ows_title_{lang}'] # noqa + layerobj.metadata['ows_layer_group'] = layerobj.metadata[f'ows_layer_group_{lang}'] # noqa if time_ and 'ows_timeextent' in layerobj.metadata.keys(): try: dates = [] - timeextent = layerobj.getMetaData('ows_timeextent') + timeextent = layerobj.metadata['ows_timeextent'] start_date, end_date, duration = timeextent.split('/') start_date = isoparse(start_date)