-
Notifications
You must be signed in to change notification settings - Fork 0
Horizon App
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.
We can create our VPC by running the following:
cd /ops/terraform/global/vpc
tfinit
terraform apply
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
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
We require Geoserver to parse the mapping data. We set Geoserver up in 3 steps:
- Create the global infrastructure the Geoserver container will need, ECR repo and son.
- Manually push the Geoserver image.
- 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.
cd /ops/terraform/apps/horizon_app/geoserver/global
tfinit
terraform apply
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
- 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
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
- Clone app from https://github.com/thinkWhere/foss4g-horizon-render-app
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
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
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
- 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
- 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
- Download the web app code from
- https://github.com/thinkWhere/foss4g-horizon-web-app
- Edit line 8 in the map.html file to refer to your geoserver URL
- 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!
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