Skip to content

Production Deployment

Stuart Olivera edited this page Apr 18, 2019 · 11 revisions

Below are steps & notes to get BrickHack's hosting infrastructure setup. This assumes you already have Dokku running on a machine and can SSH into the box. DNS should likely be set up as well but isn't required for bare minimum functionality.

For example purposes, we'll be talking about the brickhack-stage app, but the same goes for brickhack-prod (just with slightly different environment variable values).

If you have any questions at all, please don't hesitate to reach out to Stuart! This doc is very much a work in progress but we want to keep it as up to date as possible.

Deploying

Travis will automatically deploy to staging or production based on the branch.

  • develop branch -> brickhack-stage Dokku app
  • master branch -> brickhack-prod Dokku app

Dokku

Currently used and required Dokku plugins (other than the defaults):

Dokku Setup Steps

dokku apps:create brickhack-stage
dokku config:set brickhack-stage MYSQL_DATABASE_SCHEME=mysql2
dokku mysql:create brickhack-stage
dokku mysql:link brickhack-stage brickhack-stage
dokku redis:create brickhack-stage
dokku redis:link brickhack-stage brickhack-stage
dokku checks:disable brickhack-stage worker
dokku config:set brickhack-stage \ [environment variables]

Where [environment-variables] is a list of all environment variables:

BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-ruby.git \
ENVIRONMENT="" \
ROLLBAR_ACCESS_TOKEN="" \
ROLLBAR_ENV="" \
SECRET_KEY_BASE="" \
DOKKU_DEPLOY_HOOKS_PREFIX=/app \
GOOGLESHEETS_KEY="" \
GITHUB_TOKEN="" \
GITHUB_REPO="codeRIT/brickhack.io" \
GITHUB_ENV=""

SECRET_KEY_BASE (above) must be set to run a deploy. You can generate secrets via bundle exec rake secret. This "secret" is a 64-byte hexadecimal string (128 characters). You could also generate this with head -c 64 /dev/urandom | xxd -ps -c 128 if you are on a standard Linux distribution.

Once all configuration is set, add Dokku as a remote & run an initial deploy.

Initial deploy

First, we have to disable our CHECKS. Since our initial deploy won't have a working database, our checks will fail and block deploys.

On the server, run:

dokku checks:disable brickhack-stage web

Then, do a local deploy to Dokku (skipping Travis):

git remote add dokku [email protected]:brickhack-stage
git push dokku master

By doing a test push locally, you'll be able to easily see the progress of the build and any errors. Debugging deploys via Travis leads to scrambled logs and excess build failing emails (for everyone).

Once this succeeds, return back to the server to re-enable our web checks and seed the now-prepared database.

dokku checks:enable brickhack-stage web

Validating initial deploy

  • Deploy should succeed without any red flags in the build log

If everything works, verify any configs for Travis (web UI and .travis.yml) and do a test deploy via Travis.

Gallery

To do things like redirect /gallery to /gallery/, an nginx rule is needed.

Create a rewrites.conf with the following:

rewrite ^/gallery?$ http://$host/gallery/ permanent;

Don't forget to restart nginx after both of these files have been added: dokku nginx:build-config $APP

Production Branches

By default, Dokku apps use the master branch. However, for apps such as our staging app, we use the develop branch. For this, we need to specify local & remote branches at the time we push:

git push dokku develop:master

Environment Variables

Various services require environment variables to operate. These variables are set via Dokku's dokku config:set tool.

Rollbar

Rollbar captures and notifies of errors in production, and requires a server-side access token.

ROLLBAR_ACCESS_TOKEN=""
ROLLBAR_ENV="" # staging or production

Google Sheets

The Google Sheets API is used to grab up-to-date schedule information. To obtain an API key:

  1. Visit https://console.developers.google.com/apis/credentials
  2. In the "Create Credentials" dropdown, click "API Key"
  3. Go to the "Library" tab on the right
  4. Search for "Google Sheets" and enable the API
GOOGLESHEETS_KEY=""

Skylight

Skylight provides detailed performance analytics for our app.

SKYLIGHT_AUTHENTICATION=""