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
- Create new app
- Auto-deploy from ButBucket with Codeship
- How to use that all?
- Other recipes
- Install new droplet with Dokku image.
- Open given URL in your browser.
- Check option "Use virtualhost naming for apps".
- Click "Finish Setup".
- Make follow steps before your deploy apps.
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
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
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.
git clone https://github.com/statianzo/dokku-supervisord.git /var/lib/dokku/plugins/dokku-supervisord
dokku plugins-install
git clone https://github.com/jeffutter/dokku-mongodb-plugin.git /var/lib/dokku/plugins/mongodb
dokku plugins-install
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
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
git clone https://github.com/luxifer/dokku-redis-plugin.git /var/lib/dokku/plugins/redis
dokku plugins-install
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
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
- 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
- You could do it with using
Follow commands should be executed on your LOCAL computer!
git remote add appName dokku@server:appName
When you finished commits in your git-repo:
git push appName master
git remote add appName [email protected]:team-name/repo-name.git
git push appName master
Thanks for this awesome gist. For newer versions of dokku plugins are installed in another way. Might be worth mentioning.
instead of
you do
for each plugin.
ref