Awesome
Ubuntu Server Setup for Dokku
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->Initial Ubuntu VPS server setup prior to installation of Dokku.
- Introduction
- Getting Started
- Post setup actions
- Supported Ubuntu versions
- Running tests
- Author
- Contributing ๐ค
- Show your support
- License ๐
Introduction
This script uses Jason Hee's excellent Ubuntu setup script as a starting point for provisioning Ubuntu Servers in preparation for installation of Dokku.
Why not just use Jason Hee's script ๐ค?
Jason Hee's script is perfect! What this script does is that it adds a bunch of extra useful things such as ...
- Zsh, ohmyzsh + some fancy terminal enhancements
- Custom Vim Distribution
- tmux
- Optional Postfix setup with either Sendgrid or MailJet
- Automatic Security Updates
- Logwatch
- fail2ban and a few other security features
- and more.
... so if you're not interested in these things and just want to quickly get up and running with Dokku, then use Jason Hee's script.
Note: the script doesn't install Dokku, you have to restart the server after running this script, and login as the newly created user, then install Dokku like this:
# v0.27.6 was the latest tag at the time this README was initially written
# change to whatever the latest version will be when you read this
wget https://raw.githubusercontent.com/dokku/dokku/v0.27.6/bootstrap.sh && \
sudo DOKKU_TAG=v0.27.6 bash bootstrap.sh
Getting Started
-
spin up a VPS using your preferred service provider (DigitalOcean, Hetzner, Linode, Vultr, etc.), ensuring that you
- set the server's hostname to the domain that you'll be using as global domain on Dokku. This will ensure
/etc/hostname
and thehostname
command respond correctly (something Dokku relies on). - specify an SSH key when bootstrapping your VPS
- set the server's hostname to the domain that you'll be using as global domain on Dokku. This will ensure
-
Configure DNS.
- You'll need an A record for the naked domain (the "
@
" one) pointing to your IP with the lowest TTL possible - You'll need a wildcard A record (use '
*
') pointing to your IP with the lowest TTL possible
- You'll need an A record for the naked domain (the "
-
SSH into your server, clone this repository (& submodules) into your home directory, and run the setup script:
cd ~ git clone --recurse-submodules https://github.com/engineervix/pre-dokku-server-setup.git \ && cd pre-dokku-server-setup \ && bash setup.sh
Note: If you run the script with no arguments, it will neither setup
postfix
on your server nor downloadtexlive-full
. The following optional arguments are available (for help, you can simply runbash setup.sh -h
orbash setup.sh --help
):--mailjet # setup postfix with MailJest --sendgrid # setup postfix with Sendgrid --texlive # install texlive-full
Note: if you select both
--mailjet
and--sendgrid
, the script will terminate with anexit 1
code, and you'd have to try again.
When the setup script is run, you will be prompted
-
to enter the username of the new user account
-
to add a public ssh key (which should be from your local machine) for the new account. You can display it on your local terminal via (assuming it's called
id_rsa.pub
and it's in the~/.ssh/
directory.Feel free to change the path / name if you saved it in a different location / named it differently) ...
cat ~/.ssh/id_rsa.pub
... then copy it and paste it in the terminal on your server.
Note ยป If you don't have an existing key and you would like to generate one, or perhaps you already have one and would like to generate another ssh key from your local machine:
ssh-keygen -t ed25519 -C "your_email@example.com"
-
to specify a timezone for the server. It will be set to 'Africa/Lusaka' if you do not specify a value.
-
When setting up Postfix and configuring System Updates and Notification Settings, you'll be asked for
-
the System Administrator's email address (to receive notifications)
-
the email address that'll be associated with sending emails. You need to use a Mailjet OR Sendgrid verified email address for this.
This script assumes that the email address you supply is associated with your Mailjet/Sendgrid domain.
myhostname
is therefore extracted from this email address. So, if your "mail_from" email address is josh@example.co.zm, then example.co.zm will be used asmyhostname
in the Postfix setup. -
Post setup actions
-
Reboot and login as the new user
-
Test your email configuration. See example below:
Here's an example to test that your email works. I use the awesome mail-tester.com and with this configuration you should get a ~10/10 score. Remember to change recipient@someplace.com with whatever email address you'll get when you go to mail-tester.com.
echo "Hi there, this is my test message, and I am sending it to you\!" | mutt -s "Hello from your server" recipient@someplace.com
-
On Ubuntu 22.04, you'll need to fix your vim config as follows: (see https://github.com/amix/vimrc/issues/645#issuecomment-1120374288)
cd ~/.vim/janus/vim/tools/tlib/plugin/ && \ git pull origin master
-
Install Dokku, setup your projects and deploy ๐. I created this gist to serve as a goto reference for deploying (mostly Django) applications to Dokku.
# v0.27.6 was the latest tag at the time this README was initially written # change to whatever the latest version will be when you read this
wget https://raw.githubusercontent.com/dokku/dokku/v0.27.6/bootstrap.sh && \ sudo DOKKU_TAG=v0.27.6 bash bootstrap.sh
Some excellent resources:
- How to deploy Django project to Dokku
- Setting up Dokku with DigitalOcean and Namecheap (GitHub gist)
- Deploying an app with Dokku
- Dokku Docs: Process Management
- Dokku Docs: Zero Downtime Deploys
- Dokku with Let's Encrypt behind Cloudflare
- Cloudflare certificates + Dokku
- Securing Dokku with Let's Encrypt TLS Certificates
-
Fix
apt-key
Deprecation Warning on UbuntuIn our case, it'll be something along these lines:
sudo apt-key export 86E50310 | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/yarn.gpg && \ sudo apt-key export 12576482 | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/lynis.gpg && \ sudo apt-key export 288B3315 | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/dokku.gpg
Note: better to first check with
sudo apt-key list
, as described in How to Fix โapt-keyโ Deprecation Warning on Ubuntu
Supported Ubuntu versions
Jason Hee's excellent Ubuntu setup script has been tested against Ubuntu 14.04, Ubuntu 16.04, Ubuntu 18.04, Ubuntu 20.04 and 22.04. However, this project primarily targets Ubuntu 20.04 and Ubuntu 22.04 (It'll most likely also work on 18.04).
Running tests
Tests are run against a set of Vagrant VMs. To run the tests, run the following in the project's directory:
./tests/tests.sh
Author
๐ค Victor Miti
- Blog: https://blog.victor.co.zm
- Twitter:
- Github: @engineervix
Contributing ๐ค
Contributions, issues and feature requests are most welcome!
Feel free to check the issues page and take a look at the contributing guide before you get started
Show your support
Please give a โญ๏ธ if you found this project helpful!
License ๐
Copyright ยฉ 2022 Victor Miti.
This project is licensed under the terms of the MIT license.