diff --git a/.env.template b/.env.template index 52eb3984..cc0f2e18 100644 --- a/.env.template +++ b/.env.template @@ -5,13 +5,13 @@ AWS_PROFILE # $USER will be appended to the project name specified here PROJECT_NAME= -# Example production credentials -# These get templated in to your map-config.mml file -# when configuration files are built. -#PROD_TILEGARDEN_DB= -#PROD_TILEGARDEN_HOST= -#PROD_TILEGARDEN_PASSWORD= -#PROD_TILEGARDEN_USER= +# Database credentials +# These get set on the Lambda function and templated into your map-config.xml file at runtime. +#TILEGARDEN_DB_NAME= +#TILEGARDEN_DB_HOST= +#TILEGARDEN_DB_PORT= +#TILEGARDEN_DB_USER= +#TILEGARDEN_DB_PASSWORD= # Function config information ## REQUIRED ## diff --git a/.gitignore b/.gitignore index 5f240c4f..22c3120c 100644 --- a/.gitignore +++ b/.gitignore @@ -64,5 +64,3 @@ typings/ .directory .idea -# configs, if generated -transpiled-configs/ diff --git a/.travis.yml b/.travis.yml index cf47a8eb..828f3918 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ branches: language: node_js before_install: cd src/tiler install: yarn install -before_script: yarn compile script: yarn test deploy: - provider: script diff --git a/docker-compose.yml b/docker-compose.yml index 3d37dd9c..6e2180fb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,15 +18,9 @@ services: ports: - "3000:3000" - "9229:9229" - environment: - - DEV_TILEGARDEN_USER=postgres - - DEV_TILEGARDEN_PASSWORD=postgres - - DEV_TILEGARDEN_DB=postgres - - DEV_TILEGARDEN_HOST=database.lambnik.azavea.com - - PROJECT_NAME=${PROJECT_NAME}-${USER} - env_file: .env + env_file: .env.local links: - - database:database.lambnik.azavea.com + - database:database.internal.tilegarden volumes: - ./src/tiler:/home/tiler - node_modules:/home/tiler/node_modules diff --git a/scripts/build-xml b/scripts/build-xml index 005632f4..663a963e 100755 --- a/scripts/build-xml +++ b/scripts/build-xml @@ -3,8 +3,8 @@ set -e # cli args -in_dir='src/tiler/src/config/' -out_dir='transpiled-configs/' +in_dir='src/tiler/src/config/carto/' +out_dir='src/tiler/src/config/' s3_bucket='' node_env='production' diff --git a/scripts/server b/scripts/server index 430d29ca..a4115350 100755 --- a/scripts/server +++ b/scripts/server @@ -13,27 +13,17 @@ COMMAND can be one of [start, stop, restart, status]. Default is start. } -function restart_services() { - SERVICES=${@:2} - - echo "Restarting service(s) in background..." - docker-compose restart ${SERVICES} - echo "Waiting for services to restart..." - sleep 5 -} - - function main() { - + SERVICES='tiler database' if [ "${1}" = "start" ] then - docker-compose up + docker-compose up ${SERVICES} elif [ "${1}" = "stop" ] then - docker-compose stop + docker-compose stop ${SERVICES} elif [ "${1}" = "restart" ] then - docker-compose restart + docker-compose restart ${SERVICES} elif [ "${1}" = "status" ] then docker-compose ps diff --git a/src/tiler/.gitignore b/src/tiler/.gitignore index bce6fff8..0b80212d 100644 --- a/src/tiler/.gitignore +++ b/src/tiler/.gitignore @@ -5,5 +5,3 @@ claudia.json #Ignore coverage data from jest /coverage/ -# Ignore generated xml files -src/config/*.xml diff --git a/src/tiler/package.json b/src/tiler/package.json index a4b34984..9eb35848 100644 --- a/src/tiler/package.json +++ b/src/tiler/package.json @@ -24,15 +24,14 @@ ], "scripts": { "build-all-xml": "./scripts/build-all-xml.sh src/config src/config", - "deploy": "yarn compile && claudia update --no-optional-dependencies ${LAMBDA_TIMEOUT:+--timeout ${LAMBDA_TIMEOUT}} ${LAMBDA_MEMORY:+--memory ${LAMBDA_MEMORY}} ${LAMBDA_SECURITY_GROUPS:+--security-group-ids ${LAMBDA_SECURITY_GROUPS}} ${LAMBDA_SUBNETS:+--subnet-ids ${LAMBDA_SUBNETS}}", - "deploy-new": "yarn compile && claudia create --no-optional-dependencies --api-module src/api --name ${PROJECT_NAME} --region ${LAMBDA_REGION} ${LAMBDA_ROLE:+--role ${LAMBDA_ROLE}} ${LAMBDA_TIMEOUT:+--timeout ${LAMBDA_TIMEOUT}} ${LAMBDA_MEMORY:+--memory ${LAMBDA_MEMORY}} ${LAMBDA_SECURITY_GROUPS:+--security-group-ids ${LAMBDA_SECURITY_GROUPS}} ${LAMBDA_SUBNETS:+--subnet-ids ${LAMBDA_SUBNETS}} && yarn parse-id", + "deploy": "./scripts/deploy", + "deploy-new": "./scripts/deploy-new", "destroy": "claudia destroy", "dev": "nodemon -e js,mss,json,mml,mss --ignore '*.temp.mml' --exec yarn local", "lint": "eslint src", - "local": "yarn compile && node --inspect=0.0.0.0:9229 -- node_modules/claudia-local-api/bin/claudia-local-api --abbrev 300 --api-module src/api | bunyan -o short", + "local": "node --inspect=0.0.0.0:9229 -- node_modules/claudia-local-api/bin/claudia-local-api --abbrev 300 --api-module src/api | bunyan -o short", "parse-id": "jq -r '.api.id' claudia.json > .api-id", - "test": "eslint src && jest --coverage", - "compile": "yarn build-all-xml" + "test": "eslint src && jest --coverage" }, "devDependencies": { "bunyan": "^1.8.12", diff --git a/src/tiler/scripts/build-xml.sh b/src/tiler/scripts/build-xml.sh index abe03dd5..26d2cd1e 100755 --- a/src/tiler/scripts/build-xml.sh +++ b/src/tiler/scripts/build-xml.sh @@ -1,21 +1,8 @@ #!/usr/bin/env bash -# This script is never meant to be called directly by the user. -# It should only be called by other scripts that pass MML strings -# in to it, so that different environments can have access to the -# version of carto installed on the docker container. +# This script used to be more complicated, involving filling in environment variables. +# Now they stay variables until later in the process, but it's easier to keep this as a +# script than to put the command inline in the places where it's used, especially since +# it seems possible that it could change again. -function main() { - tempFile="${1%%.*}.temp.mml" - - # fill in environment variables - node scripts/template-vars.js "${1}" > ${tempFile} - - # compile with carto - carto ${tempFile} - - # clean up - rm ${tempFile} -} - -main "${1}" "${2}" +carto "${1}" diff --git a/src/tiler/scripts/deploy b/src/tiler/scripts/deploy new file mode 100755 index 00000000..f8c45638 --- /dev/null +++ b/src/tiler/scripts/deploy @@ -0,0 +1,8 @@ +#!/bin/bash + +yarn claudia update --no-optional-dependencies \ + ${LAMBDA_TIMEOUT:+--timeout ${LAMBDA_TIMEOUT}} \ + ${LAMBDA_MEMORY:+--memory ${LAMBDA_MEMORY}} \ + ${LAMBDA_SECURITY_GROUPS:+--security-group-ids ${LAMBDA_SECURITY_GROUPS}} \ + ${LAMBDA_SUBNETS:+--subnet-ids ${LAMBDA_SUBNETS}} \ + --set-env TILEGARDEN_DB_HOST=${TILEGARDEN_DB_HOST},TILEGARDEN_DB_NAME=${TILEGARDEN_DB_NAME},TILEGARDEN_DB_PASSWORD=${TILEGARDEN_DB_PASSWORD},TILEGARDEN_DB_PORT=${TILEGARDEN_DB_PORT},TILEGARDEN_DB_USER=${TILEGARDEN_DB_USER} diff --git a/src/tiler/scripts/deploy-new b/src/tiler/scripts/deploy-new new file mode 100755 index 00000000..334451ce --- /dev/null +++ b/src/tiler/scripts/deploy-new @@ -0,0 +1,11 @@ +#!/bin/bash + +yarn claudia create --no-optional-dependencies --api-module src/api \ + --name ${PROJECT_NAME} --region ${LAMBDA_REGION} \ + ${LAMBDA_ROLE:+--role ${LAMBDA_ROLE}} \ + ${LAMBDA_TIMEOUT:+--timeout ${LAMBDA_TIMEOUT}} \ + ${LAMBDA_MEMORY:+--memory ${LAMBDA_MEMORY}} \ + ${LAMBDA_SECURITY_GROUPS:+--security-group-ids ${LAMBDA_SECURITY_GROUPS}} \ + ${LAMBDA_SUBNETS:+--subnet-ids ${LAMBDA_SUBNETS}} \ + --set-env TILEGARDEN_DB_HOST=${TILEGARDEN_DB_HOST},TILEGARDEN_DB_NAME=${TILEGARDEN_DB_NAME},TILEGARDEN_DB_PASSWORD=${TILEGARDEN_DB_PASSWORD},TILEGARDEN_DB_PORT=${TILEGARDEN_DB_PORT},TILEGARDEN_DB_USER=${TILEGARDEN_DB_USER} \ +&& yarn parse-id diff --git a/src/tiler/scripts/template-vars.js b/src/tiler/scripts/template-vars.js deleted file mode 100644 index cb791099..00000000 --- a/src/tiler/scripts/template-vars.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Stub script that places variable templates with the proper env variable. - * In all likelihood this could be done with one line of sed but I was having - * trouble getting the string replacement part to work out. - */ - -const fs = require('fs') - -const envPrefix = process.env.NODE_ENV === 'production' ? 'PROD_' : 'DEV_' - -fs.readFile(process.argv[2], 'utf-8', function (err, out) { - if (err) process.stderr.write(err) - else { - const templated = out.replace( - /\$\{([a-z0-9_]+)\}/gi, - (_, envName) => { - const varName = `${envPrefix}${envName}` - return `"${process.env[varName]}"` - }, - ) - - process.stdout.write(templated) - } -}) - - diff --git a/src/tiler/src/config/data-type-example-style.mss b/src/tiler/src/config/carto/data-type-example-style.mss similarity index 100% rename from src/tiler/src/config/data-type-example-style.mss rename to src/tiler/src/config/carto/data-type-example-style.mss diff --git a/src/tiler/src/config/data-type-example.mml b/src/tiler/src/config/carto/data-type-example.mml similarity index 70% rename from src/tiler/src/config/data-type-example.mml rename to src/tiler/src/config/carto/data-type-example.mml index c0a552ae..cf7c22fb 100644 --- a/src/tiler/src/config/data-type-example.mml +++ b/src/tiler/src/config/carto/data-type-example.mml @@ -12,10 +12,11 @@ Layer: geometry: polygon srs: "+proj=lcc +lat_1=40.96666666666667 +lat_2=39.93333333333333 +lat_0=39.33333333333334 +lon_0=-77.75 +x_0=600000 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "street_centerline" key_field: "" @@ -25,10 +26,11 @@ Layer: geometry: polygon srs: "+proj=lcc +lat_1=40.96666666666667 +lat_2=39.93333333333333 +lat_0=39.33333333333334 +lon_0=-77.75 +x_0=600000 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "pwd_parcels" key_field: "" @@ -38,10 +40,11 @@ Layer: geometry: polygon srs: "+proj=longlat +datum=WGS84 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "inlets" key_field: "" diff --git a/src/tiler/src/config/map-config.mml b/src/tiler/src/config/carto/map-config.mml similarity index 69% rename from src/tiler/src/config/map-config.mml rename to src/tiler/src/config/carto/map-config.mml index 9e01c4ba..8eab43c3 100644 --- a/src/tiler/src/config/map-config.mml +++ b/src/tiler/src/config/carto/map-config.mml @@ -12,10 +12,11 @@ Layer: geometry: polygon srs: "+proj=lcc +lat_1=40.96666666666667 +lat_2=39.93333333333333 +lat_0=39.33333333333334 +lon_0=-77.75 +x_0=600000 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "street_centerline" key_field: "" @@ -25,10 +26,11 @@ Layer: geometry: polygon srs: "+proj=lcc +lat_1=40.96666666666667 +lat_2=39.93333333333333 +lat_0=39.33333333333334 +lon_0=-77.75 +x_0=600000 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "pwd_parcels" key_field: "" @@ -38,10 +40,11 @@ Layer: geometry: polygon srs: "+proj=longlat +datum=WGS84 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "inlets" key_field: "" diff --git a/src/tiler/src/config/point-example-style.mss b/src/tiler/src/config/carto/point-example-style.mss similarity index 100% rename from src/tiler/src/config/point-example-style.mss rename to src/tiler/src/config/carto/point-example-style.mss diff --git a/src/tiler/src/config/point-example.mml b/src/tiler/src/config/carto/point-example.mml similarity index 61% rename from src/tiler/src/config/point-example.mml rename to src/tiler/src/config/carto/point-example.mml index 1bb522aa..ffe1980a 100644 --- a/src/tiler/src/config/point-example.mml +++ b/src/tiler/src/config/carto/point-example.mml @@ -12,10 +12,11 @@ Layer: geometry: polygon srs: "+proj=longlat +datum=WGS84 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "(select geom,owner,inlettype from inlets where owner = 'PWD') as q" key_field: "" @@ -25,10 +26,11 @@ Layer: geometry: polygon srs: "+proj=longlat +datum=WGS84 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "(select geom,owner,inlettype from inlets where owner = 'AIRPRT') as q" key_field: "" @@ -38,10 +40,11 @@ Layer: geometry: polygon srs: "+proj=longlat +datum=WGS84 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "(select geom,owner,inlettype from inlets where owner = 'STATE') as q" key_field: "" @@ -51,10 +54,11 @@ Layer: geometry: polygon srs: "+proj=longlat +datum=WGS84 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "(select geom,owner,inlettype from inlets where owner = 'PARK') as q" key_field: "" @@ -64,10 +68,11 @@ Layer: geometry: polygon srs: "+proj=longlat +datum=WGS84 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "(select geom,owner,inlettype from inlets where owner = 'LM') as q" key_field: "" @@ -77,10 +82,11 @@ Layer: geometry: polygon srs: "+proj=longlat +datum=WGS84 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "(select geom,owner,inlettype from inlets where owner = 'FEDERAL') as q" key_field: "" @@ -90,10 +96,11 @@ Layer: geometry: polygon srs: "+proj=longlat +datum=WGS84 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "(select geom,owner,inlettype from inlets where owner = 'PRIV') as q" key_field: "" @@ -103,10 +110,11 @@ Layer: geometry: polygon srs: "+proj=longlat +datum=WGS84 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "(select geom,owner,inlettype from inlets where owner = 'CHEL') as q" key_field: "" @@ -116,10 +124,11 @@ Layer: geometry: polygon srs: "+proj=longlat +datum=WGS84 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "(select geom,owner,inlettype from inlets where owner = 'USNAVY') as q" key_field: "" @@ -129,10 +138,11 @@ Layer: geometry: polygon srs: "+proj=longlat +datum=WGS84 +no_defs" Datasource: - host: ${TILEGARDEN_HOST} - dbname: ${TILEGARDEN_DB} - user: ${TILEGARDEN_USER} - password: ${TILEGARDEN_PASSWORD} + host: ${TILEGARDEN_DB_HOST} + port: ${TILEGARDEN_DB_PORT} + dbname: ${TILEGARDEN_DB_NAME} + user: ${TILEGARDEN_DB_USER} + password: ${TILEGARDEN_DB_PASSWORD} type: "postgis" table: "(select geom,owner,inlettype from inlets where owner = 'PRIVPWDMAINT') as q" key_field: "" diff --git a/src/tiler/src/config/style.mss b/src/tiler/src/config/carto/style.mss similarity index 100% rename from src/tiler/src/config/style.mss rename to src/tiler/src/config/carto/style.mss diff --git a/src/tiler/src/config/data-type-example.xml b/src/tiler/src/config/data-type-example.xml new file mode 100644 index 00000000..67055e0d --- /dev/null +++ b/src/tiler/src/config/data-type-example.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/tiler/src/config/map-config.xml b/src/tiler/src/config/map-config.xml new file mode 100644 index 00000000..fe1a2a62 --- /dev/null +++ b/src/tiler/src/config/map-config.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/tiler/src/config/point-example.xml b/src/tiler/src/config/point-example.xml new file mode 100644 index 00000000..0b4a9672 --- /dev/null +++ b/src/tiler/src/config/point-example.xml @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/tiler/src/tiler.js b/src/tiler/src/tiler.js index c3155ae4..21bc8c7f 100644 --- a/src/tiler/src/tiler.js +++ b/src/tiler/src/tiler.js @@ -79,6 +79,17 @@ async function fetchMapFile(options) { } } +/* Substitutes environment variables into a string using a basic regex-driven template syntax. + * + * Any occurrence of ${ENV_VAR} will be replaced with the value of that environment variable. + */ +function fillVars(xmlString) { + return xmlString.replace( + /\$\{([A-Z0-9_]+)\}/g, + (_, envName) => `${process.env[envName]}`, + ) +} + /** * Creates a map based on configured datasource and style information */ @@ -88,15 +99,19 @@ async function createMap(mapConfig) { const map = new mapnik.Map(TILE_WIDTH, TILE_HEIGHT) map.bufferSize = 64 - // Load map specification from xml string + // Load map specification from xml string and apply some transforms and filters try { - const mapConfigXml = await fetchMapFile(configOptions) - const xmlJsObj = await parseXml(mapConfigXml) - const filteredMapConfigJsObj = await filterVisibleLayers(xmlJsObj, layers) - const filteredMapConfigXml = buildXml(filteredMapConfigJsObj) - const configuredMap = await promisifyMethod(map, 'fromString')(filteredMapConfigXml) - configuredMap.extent = bbox(z, x, y, TILE_HEIGHT, configuredMap.srs) - return configuredMap + return await fetchMapFile(configOptions) + .then(fillVars) + .then(parseXml) + .then(xmlJsObj => filterVisibleLayers(xmlJsObj, layers)) + .then(buildXml) + .then(filteredMapConfigXml => promisifyMethod(map, 'fromString')(filteredMapConfigXml)) + .then((configuredMap) => { + /* eslint-disable-next-line no-param-reassign */ + configuredMap.extent = bbox(z, x, y, TILE_HEIGHT, configuredMap.srs) + return configuredMap + }) } catch (err) { throw postgisFilter(err) }