Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DigitalOcean Dokku: fresh install with Node.js Environment

DigitalOcean Dokku / Node.js Cloud Environment

Custom recipe to get full Node.js Cloud Environment in DigitalOcean Dokku droplet running from scratch. Yes. Your own Heroku for $5 per month.

I use this gist to keep track of the important configuration steps required to have a functioning system after fresh install.

When you have executed that's all step by step you will get a new working and stable system which is ready to host & serve your Node.js application and databases.

Dokku installation

  1. Install new droplet with Dokku image.
  2. Open given URL in your browser.
  3. Check option "Use virtualhost naming for apps".
  4. Click "Finish Setup".
  5. Make follow steps before your deploy apps.

Configure locale

echo 'LANG=en_US.UTF-8' > /etc/default/locale
echo 'LC_ALL=en_US.UTF-8' >> /etc/default/locale
sudo locale-gen UTF-8
reboot

Fix memory issues

To prevent errors like:

runtime: panic before malloc heap initialized
fatal error: runtime: cannot allocate heap metadata

You could execute follow commands:

dd if=/dev/zero of=/extraswap bs=1M count=1024
mkswap /extraswap
echo "/extraswap         none            swap    sw                0       0">>/etc/fstab
swapon -a
reboot

supervisord plugin

Normally, dokku only runs the web process within Procfile. The dokku-supervisord plugin will run all process types (web, worker, etc.) and will restart crashed applications.

Install

git clone https://github.com/statianzo/dokku-supervisord.git /var/lib/dokku/plugins/dokku-supervisord
dokku plugins-install

MongoDB plugin

Install

git clone https://github.com/jeffutter/dokku-mongodb-plugin.git /var/lib/dokku/plugins/mongodb
dokku plugins-install

Auto-start

To get mongodb-plugin auto-started after each reboot:

nano /etc/init/dokku-mongodb.conf

And put follow lines:

description "Dokku MongoDB container"
start on starting dokku-redeploy
script
  sleep 2 # give docker some time
  sudo -i -u dokku /usr/local/bin/dokku mongodb:start
end script

Re-install

This point is important if you've cancelled mongodb-plugin installation on a half way or you've got locale errors.

rm -rf /home/dokku/.mongodb
reboot

After reboot execute again:

dokku plugins-install

Redis plugin

git clone https://github.com/luxifer/dokku-redis-plugin.git  /var/lib/dokku/plugins/redis
dokku plugins-install

dokku-apt plugin

dokku-apt is a plugin for dokku that installs apt packages in your dokku environment. This is mostly useful for instances where you have an app that depends on packages being here.

git clone https://github.com/F4-Group/dokku-apt -b 0.3.0 /var/lib/dokku/plugins/dokku-apt
dokku plugins-install

Create new app

Basic flow:

dokku apps:create appName
dokku mongodb:create appName appName
dokku redis:create appName
dokku redis:link appName appName
dokku domains:add appName domain1 domain2
dokku config:set appName NODE_ENV=production PROJECT_ID=appName

Auto-deploy from BitBucket with Codeship

  • Sign-in to Codeship
  • Connect BitBucket account
  • Choice a repo
  • Configure Setup commands:
nvm install 4.0
npm install -g npm
  • Add Continuous Deployment as a script:
#!/bin/sh
git fetch --unshallow || true
git fetch origin "+refs/heads/*:refs/remotes/origin/*"
# checkout a remote branch with
# git checkout -b test origin/test
git remote add dokku dokku@server:appName
git push dokku master
  • or use npm-script, i.e. npm run deploy

  • Add Codeship public key to your server

    • You could do it with using ssh by adding content to /home/dokku/.ssh/authorized_keys
  • See Codeship useful scripts collection

How to use that all?

Follow commands should be executed on your LOCAL computer!

Deploy to Dokku

Add a repo

git remote add appName dokku@server:appName

Push

When you finished commits in your git-repo:

git push appName master

Deploy to BitBucket

Add a repo

git remote add appName git@bitbucket.org:team-name/repo-name.git

Push

git push appName master

Other recipes

@GGAlanSmithee

This comment has been minimized.

Copy link

@GGAlanSmithee GGAlanSmithee commented May 21, 2016

Thanks for this awesome gist. For newer versions of dokku plugins are installed in another way. Might be worth mentioning.

instead of

git clone https://github.com/luxifer/dokku-redis-plugin.git  /var/lib/dokku/plugins/redis
dokku plugins-install

you do

dokku plugin:install https://github.com/luxifer/dokku-redis-plugin.git

for each plugin.

ref

@christophemarois

This comment has been minimized.

Copy link

@christophemarois christophemarois commented Jan 21, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.