Skip to content

DigitalOcean Dokku Deploy

Justin Craig-Kuhn edited this page May 20, 2024 · 23 revisions

There are many ways to host the KudoChest web components. The following is one possible way using the Dokku platform on a Digital Ocean server. This is a low cost way of getting a single-team server up and running quickly.  
 

Setup

  1. Create an account at Digital Ocean  
     

  2. Create a new Droplet. Select the Marketplace tab and enter "dokku". Select the current Dokku build that appears (these instructions reflect Dokku 0.21.4 on Ubuntu 20.04). The smallest Droplet size should be fine for small teams. Select a datacenter and provide your SSH key so you can access the server.

create_droplet  
  1. Enter the IP address of the Droplet in your browser. The Dokku init screen should appear. Enter a public key you'll use for deploying to the server. In the "Hostname" field, enter the value of <kudochest-host>. Leave "Use virtualhost naming for apps" disabled. Click "Finish Setup".
dokku_hostname  
  1. You must assign a valid domain name to your server so that it can handle SSL traffic. For the best UX, setup a kudochest subdomain on your organization's DNS, such as kudochest.my-company.com, and point it at the new Droplet IP address. This full domain name (subdomain included) will be referred to as <kudochest-host> below.  
     

  2. Optional security step: you should disable root login via SSH. Replace <admin-user> with your desired username.

ssh root@<kudochest-host>
adduser <admin-user>
usermod -aG sudo <admin-user>
su - <admin-user>
mkdir ~/.ssh
chmod 700 ~/.ssh
vim ~/.ssh/authorized_keys
# => Paste result of local: `cat ~/.ssh/id_rsa.pub`
chmod 600 ~/.ssh/authorized_keys
exit
sudo vim /etc/ssh/sshd_config
# => Change PermitRootLogin to "no"
sudo systemctl reload ssh
exit
ssh <admin-user>@<kudochest-host>

 

  1. SSH into the Droplet as <admin-user> (or root if you skipped the last step) and run the following commands.
# Create app
dokku apps:create kudochest

# Setup local storage
sudo mkdir -p /var/lib/dokku/data/storage/kudochest/response_images/tmp
sudo mkdir -p /var/lib/dokku/data/storage/kudochest/response_images/cache
sudo chmod -R 777 /var/lib/dokku/data/storage/kudochest
dokku storage:mount kudochest /var/lib/dokku/data/storage/kudochest:/storage

# Domain
dokku domains:set kudochest <kudochest-host>

# Port forwarding
dokku proxy:ports-set kudochest http:80:3000 https:443:3000

 

  1. Setup the necessary Environment Variables. The following represents a bare minimum. You can generate a new secret key base by running rails secret.
dokku config:set kudochest \
  RAILS_ENV=production \
  RAILS_SECRET_KEY_BASE=<secret-key-base> \
  ASSET_HOST=https://<kudochest-host> \
  WEB_DOMAIN=<kudochest-host>

Make sure the following variables are set if integrating with Discord.

DISCORD_LISTENER_STARTUP_DELAY=15
DOKKU_WAIT_TO_RETIRE=10

 

  1. Use the Dokku Postgres Plugin to create and link the database. You should schedule a daily S3 backup so your users never lose kudos even in case of failures. When the database gets linked to the app, the DATABASE_URL environment variable gets set automatically.
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
dokku postgres:create kudochest
dokku postgres:link kudochest kudochest

# Optional S3 backups
postgres:backup-auth kudochest <aws-access-key-id> <aws-secret-access-key> <aws-default-region>
postgres:backup-schedule kudochest <schedule> <bucket-name>
postgres:backup kudochest <bucket-name>

 

  1. Use the Dokku Redis Plugin for Redis. It's not necessary to backup Redis as it is used only for caching. When Redis gets linked to the app, the REDIS_URL environment variable gets set automatically.
sudo dokku plugin:install https://github.com/dokku/dokku-redis.git redis
dokku redis:create kudochest
dokku redis:link kudochest kudochest

 

  1. Use LetsEncrypt if you need SSL encryption (required for Slack integration).
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
dokku config:set --no-restart kudochest DOKKU_LETSENCRYPT_EMAIL=<admin-email-address>
dokku letsencrypt:enable kudochest
dokku letsencrypt:auto-renew

 

  1. The Procfile in the root of the repo controls what processes get run by Dokku. If you do not need Discord integration, remove listener: bin/discord_listener and git add / git commit. You may also want to tweak details of the CHECKS and DOKKU_SCALE files. By default, one web process and one worker process will be run. See Dokku Process Management for help.  
     

  2. Push the build to the master git branch on your new Dokku server.

git remote add dokku dokku@<kudochest-host>:kudochest
git push dokku master

After the deploy completes, you should see the KudoChest login page when you visit <kudochest-host> in your browser.

Clone this wiki locally