TileStream is an open source tile server developed by MapBox, which borrows extensively from their commercial MapBox tile server product. TileStream loads map layer packages created in the TileMill application, which are stored on the server as SQLite databases in the mbtiles specification/schema. On the other hand, Heroku is a cloud application platform that supports Python, Ruby, Java and Node.js apps, the latter of which TileStream is dependent upon. This post will show how to deploy a TileStream server on the Heroku cloud application platform, thereby allowing you to serve your map tiles using scalable infrastructure that can respond to fluctuations in the demand of your web maps. See the result here.
Download and Install
If you already have git or heroku toolbelt installed you may skip this step. You can check to see if git and heroku are available on your system by checking the version of each tool. On windows, you will want to work inside of the “git bash shell” which is an unix terminal application installed for your git usage that also connects to the system PATH environment making heroku available.
$ git --version git version 1.8.1.msysgit.1 $ heroku --version heroku/toolbelt/3.2.2 (i386-mingw32) ruby/1.9.3
Setup Heroku
If this is your first time using Heroku, create an account on their website. After doing so you will be able to login to Heroku using the command line. Doing so will “pair” your computer up with your Heroku account via an exchange of your RSA authentication key. If you don’t already have a public RSA key on your computer you will be asked to generate one when you login.
$ heroku login Enter your Heroku credentials. Email: Password (typing will be hidden): Could not find an existing public key. Would you like to generate one? [Yn] yes Generating new SSH public key. Uploading SSH public key ~/.ssh/id_rsa.pub... done Authentication successful.
Create a Heroku App
Create an app, which is Heroku’s fundamental unit of organization to which you can deploy, manage and provision your TileStream server. I am going to call my app tilestream. This formalizes an app on your Heroku account that is accessible via url and git at tilestream.heroku.com and [email protected]:tilestream.git
$ heroku create tilestream Creating tilestream... done, stack is cedar http://tilestream.herokuapp.com/ | [email protected]:tilestream.git
You can check to see if this worked by visiting the url of your new heroku app. A placeholder welcome page will be shown.
The Application
On your computer, create a new directory for your app. I keep all of my Heroku apps in their own folder. You will also need to create 2 files within them: Procfile and package.json. The Procfile allows us to issue commands to the web dyno for your Heroku app (just like issuing commands on your terminal). The package.json file declares our Heroku app as a Node.js application, and lists what we would like installed. Also, create a subfolder for your map tiles. You can move your existing mbtiles packages to the tiles folder, or place an example mbtiles package made available by MapBox: control_room (3MB).
$ mkdir ~/heroku/tilestream.herokuapp.com $ cd ~/heroku/tilestream.herokuapp.com $ touch Procfile package.json $ mkdir tiles
Procfile
web: tilestream --host tilestream.herokuapp.com --uiPort=$PORT --tilePort=$PORT --tiles=./tiles
--host maptiles.herokuapp.com
url of your Heroku app
--uiPort=$PORT
TileStream UI made available through the public port of your app
--tilePort=$PORT
TileStream maps made available through the public port of your app
--tiles=./tiles
tiles folder that contains the mbtiles packages
package.json
{ "name": "tilestream", "author": "Michael Markieta", "version": "0.0.1", "description": "My TileStream Server", "engines": { "node": "0.10.24", "npm": "1.3.11" }, "dependencies": { "tilestream": "1.1.0" } }
name author version description
straight-forward Heroku app description parameters
engines
we want node.js 0.10.24 and npm 1.3.11
dependencies
we want tilestream 1.1.0 from npm
Push it to the Cloud
You will need to start off by initializing a github repository in the root of your Heroku app folder. This will allow you to commit changes to the repo and push them to your Heroku app in the cloud. Heroku relies on git as a transport mechanism to publish your application. When changes are made locally and pushed to the cloud, your code (commit history) is compared to that on Heroku’s servers and only what needs to be changed is transferred (unlike a blanket upload-all typical of ftp).
$ git init Initialized empty Git repository in ~/heroku/tilestream.herokuapp.com/.git/ $ git add . $ git commit -m "initial commit" 3 files changed, 14 insertions(+) create mode 100644 Procfile create mode 100644 package.json create mode 100644 tiles/control_room.mbtiles $ git remote add heroku [email protected]:tilestream.git $ git push heroku master
When this completes you will have TileStream up and running at your app url. Here is the final product of this tutorial using the example mbtiles packages from Mapbox: http://tilestream.herokuapp.com
Sorry, the comment form is closed at this time.