Skip to content

Horizon App

Iain Hunter edited this page Sep 23, 2019 · 26 revisions

The horizon app represents a typical GIS workload. Here we show how you can set up a Postgres Database, Geoserver and deploy the app itself.

DevOps

Setting up the global environment

1. Creating a global VPC

We can create our VPC by running the following:

cd /ops/terraform/global/vpc
tfinit
terraform apply

2. Creating IAM Credentials

Our app is going to need permissions to setup and use our serverless infrastructure on Amazon Fargate, here we just create the necessary roles and policies

cd /ops/terraform/global/iam
tfinit
terraform apply

3. Create Postgres RDS DB

A postgres database is used here to store information about the task we want to render. However, this could as easily be pulled from a Queue.

cd /ops/terraform/global/rds
tfinit
terraform apply

Setting up Serverless Geoserver

We require Geoserver to parse the mapping data. We set Geoserver up in 3 steps:

  1. Create the global infrastructure the Geoserver container will need, ECR repo and son.
  2. Manually push the Geoserver image.
  3. Finally create the AWS Fargate container.

The reason for this if we do it in one step the container will attempt to access an image from the Container Repo that doesn't yet exist and give you errors.

4. Create Global Geoserver Infrastructure

cd /ops/terraform/apps/horizon_app/geoserver/global
tfinit
terraform apply

5. Manually deploying Geoserver 2.15

5.1 Building Geoserver 2.15

We need to modify the standard thinkWhere/geoServer container to enable CORS for WFS request access from the web app.

mkdir geoserver-cors
cd geoserver-cors
  • Create a new Dockerfile with the following lines
FROM thinkwhere/geoserver:2.15
RUN sed -i 's/<\/web-app>/<filter><filter-name>CorsFilter<\/filter-name><filter-class>org.apache.catalina.filters.CorsFilter<\/filter-class><init-param><param-name>cors.allowed.origins<\/param-name><param-value>*<\/param-value><\/init-param><\/filter><filter-mapping><filter-name>CorsFilter<\/filter-name><url-pattern>\/*<\/url-pattern><\/filter-mapping><\/web-app>/' $CATALINA_HOME/conf/web.xml
  • To build the container docker build . -t geoserver-cors:2.15
  • Run locally to check it works docker run --name=foss4g-geoserver -p 8080:8080 -d -t geoserver-cors:2.15

5.2 Deploying the container to ECR

  • The output of Step 4 will include the URL of the ECR repo eg YOUR-ACCOUNT-ID.dkr.ecr.us-east-1.amazonaws.com/geoserver
  • You now need to tag the local Geoserver container using a special format so it can be uploaded to AWS:
  • docker tag geoserver-cors:2.15 YOUR-ACCOUNT-ID.dkr.ecr.us-east-1.amazonaws.com/geoserver:2.15
  • From the terraform container we need to get a login so we can push the container to AWS:
  • aws ecr get-login --no-include-email
  • Copy and paste the output and run it on the command line we can login to AWS ECR
  • Finally we can push the image to AWS
  • docker push YOUR-ACCOUNT-ID.dkr.ecr.us-east-1.amazonaws.com/geoserver:2.15

6. Create Geoserver Fargate service

Finally we can create the Geoserver fargate service now we have the Geoserver docker container available in ECR

cd /ops/terraform/apps/horizon_app/geoserver/fargate
tfinit
terraform apply

Deploying the Horizon App

7. Create Viewpoint Database

The horizon app requires a database to store the list of viewpoints that will be rendered. To create the database run the database script from the horizon app here:

https://github.com/thinkWhere/foss4g-horizon-render-app/blob/master/devops/db-setup.sql

againt the database you created in Step 3

8. Configure the Geoserver instance

To setup your Geoserver you can edit the script here:

https://github.com/thinkWhere/foss4g-horizon-render-app/blob/master/devops/geoserver-rest.sh

Ensure you update:

GEOSERVER_URL=YOUR_URL_HERE
DATABASE_HOST=YOUR_DB_HOST_HERE

To run:

.\devops\geoserver-rest.sh

9 Create horizon app infrastructure

This will create the Fargate Cluster, the CloudWatch event and the S3 bucket to host the render

cd /ops/terraform/apps/horizon_app/app
tfinit
terraform apply

10 Configure Horizon Render App to Fargate

  • Open the horizon app that you cloned from github
  • Configure ./app/config.py
  • Manually create a IAM user for the Horzion App with full access to S3. Use the users keys to set the S3_ACCESS_KEY and the S3_ACCESS_SECRET_KEY
  • Set the DATABASE_CONNECTION_STRING.host to be the hostname of the database you created in Step 7. This can be grabbed from the RDS console
  • Set the VIEWER_BUCKET to be the name of the bucket you created in Step 9
  • Finally the TERRAIN_DATA_BUCKET is a public bucket we are hosting with the Terrain 50 data inside it.
    S3_ACCESS_KEY = ""
    S3_ACCESS_SECRET_KEY = ""
    DATABASE_CONNECTION_STRING = """
        host='YOUR-RDS-HOST'
        port='5432'
        dbname='appsstaging'
        user='viewpoint_user'
        password='viewpoint'
        """
    VIEWER_BUCKET = ""
    # Public bucket that thinkWhere host (temporarily) data available from Ordnance Survey
    TERRAIN_DATA_BUCKET = "ac-foss4g-terrain-data"
  • Once configured build the container with docker-compose build

11. Upload the container

  • The output of Step 9 will include the URL of the ECR repo eg YOUR-ACCOUNT-ID.dkr.ecr.us-east-1.amazonaws.com/horizon-app
  • You now need to tag the local horizon-app container using a special format so it can be uploaded to AWS:
  • docker tag horizon-app:latest YOUR-ACCOUNT-ID.dkr.ecr.us-east-1.amazonaws.com/horizon-app:latest
  • From the terraform container we need to get a login so we can push the container to AWS:
  • aws ecr get-login --no-include-email
  • Copy and paste the output and run it on the command line we can login to AWS ECR
  • Finally we can push the image to AWS
  • docker push YOUR-ACCOUNT-ID.dkr.ecr.us-east-1.amazonaws.com/horizon-app:latest

12 Deploy Horizon Web App to S3

  • Download the web app code from
  • Navigate to your S3 bucket which is hosting your generated horizon data the AWS Console
    • Select "Upload" and upload files map.html, viewpoint.html, and style.css into the root
    • Select each file and "Make Public" to allow web access to the files
  • Navigate to the "data" folder, and upload files dem.jpg, and peaks.geojson
    • Again, these files need to be made public
    • Select the map.html file, and click on the url to view in a browser!

13 Destroying are app and infrastructure

At the end of the process you'll want to tear down the app and infrastructure we created so we don't have to pay for it. This is down with terraform destroy as follows:

cd /ops/terraform/apps/horizon_app/app
terraform destroy
cd /ops/terraform/apps/horizon_app/geoserver/fargate
terraform destroy
cd /ops/terraform/apps/horizon_app/geoserver/global
terraform destroy
cd /ops/terraform/global/rds
terraform destroy
cd /ops/terraform/global/iam
terraform destroy
cd /ops/terraform/global/vpc
terraform destroy