One of the application servers on DigitalOcean runs Dokku (opens in a new tab), a docker-powered PaaS that is compatible with Heroku buildpacks. Dokku was chosen due to its ease of maintainece and deployment.

DigitalOcean offers a pre-installed Dokku image as a 1-Click installation. The current Dokku droplet was created by choosing a Dokku image for Ubuntu using the Dokku DigitalOcean Droplet Installation Notes (opens in a new tab).

Deploying an application to Dokku

The following steps were adapted from the Dokku deployment guide (opens in a new tab).

  1. SSH into the droplet with Dokku installed:

    ssh USERNAME@137.184.85.112
  2. Create the app

    dokku apps:create fossil-map
  3. Create the backing services

    Dokku by default does not provide datastores (e.g. MySQL, PostgreSQL) on a newly created app. Instead, new datastores are connected to your app via official plugins (opens in a new tab).

    a. Install plugin (if needed)

    sudo dokku plugin:install https://github.com/dokku/dokku-mongo.git mongo

    b. Create service(s)

    # Example for a new postgres service
    dokku mongo:create fossilmap
  4. Linking backing services to application

    Once the services have been created, you then set the DATABASE_URL environment variable by linking the servies, as follows:

    # on the Dokku host each official datastore offers a `link` method to link a service to any application
    dokku mongo:link fossilmap fossil-map
  5. Add git remote (on local machine)

    # the remote username *must* be dokku or pushes will fail
    git remote add dokku@137.184.85.112:fossil-map
    git push dokku dokku:master

    After pushing you should have output similar to below:

    Counting objects: 231, done.
    Delta compression using up to 8 threads.
    Compressing objects: 100% (162/162), done.
    Writing objects: 100% (231/231), 36.96 KiB | 0 bytes/s, done.
    Total 231 (delta 93), reused 147 (delta 53)
    -----> Cleaning up...
    -----> Building ruby-getting-started from herokuish...
    -----> Adding BUILD_ENV to build environment...
    -----> Ruby app detected
    -----> Compiling Ruby/Rails
    -----> Using Ruby version: ruby-2.2.1
    -----> Installing dependencies using 1.9.7
           Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
           Fetching gem metadata from https://rubygems.org/...........
           Fetching version metadata from https://rubygems.org/...
           Fetching dependency metadata from https://rubygems.org/..
           Using rake 10.4.2
    
    ...
    
    =====> Application deployed:
           http://ruby-getting-started.dokku.me

Setting up SSL

Dokku has a complete ssl plugin (opens in a new tab) built in that can be used to import SSL certificates (below is a short example, please refer to the ssl documentation (opens in a new tab) for more information):

dokku certs:add fossil-map server.crt server.key

As an alternative, the Dokku project offers an optional letsencrypt plugin that can be used to automate SSL certificate retrieval and renewal.

# on the Dokku host
# install the letsencrypt plugin
# plugin installation requires root, hence the user change    
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
 
# configure the plugin
dokku config:set --global DOKKU_LETSENCRYPT_EMAIL=your-email@your.domain.com
 
# set a custom domain that you own for your application
dokku domains:set ruby-getting-started ruby-getting-started.your.domain.com
 
# enable letsencrypt
dokku letsencrypt:enable ruby-getting-started
 
# enable auto-renewal
dokku letsencrypt:cron-job --add

Setting environmental variables

Private data, such as API keys or passwords required for application configuration should be kept in environmental variables (and not in an application's repository). The following was adapted from the Dokku Environmental Variables (opens in a new tab) documentation.

The config plugin provides the following commands to manage variables:

config (<app>|--global)                                   Display all global or app-specific config vars
config:get (<app>|--global) KEY                           Display a global or app-specific config value
config:set (<app>|--global) KEY1=VALUE1 [KEY2=VALUE2 ...] Set one or more config vars
config:unset (<app>|--global) KEY1 [KEY2 ...]             Unset one or more config vars

Troubleshooting

Pre-receive hook declined

When pushing to dokku using git push dokku dokku:master from your local repository, you might encounter the following error:

! [remote rejected] dokku -> master (pre-receive hook declined)

One common way to fix this is by updating the docker configuration file with its default version from GitHub. To do so, log onto the Dokku server with sudo priveldges and execute the follwing:

sudo wget -O /etc/init/docker.conf https://raw.github.com/dotcloud/docker/master/contrib/init/upstart/docker.conf

This will download and replace a new version of the docker.conf. After that has successfully run, you'll need to restart the docker service with:

sudo service docker restart
from pathlib import Path
import json
json_path = Path.cwd().parent / Path(  )
areas_json = json.load(open(json_path))