So why not take this approach (where possible) with infrastructure? […] Need to upgrade? No problem. Build a new, upgraded system and throw the old one away. New app revision? Same thing. Build a server (or image) with a new revision and throw away the old ones.
— Chad Fowler, Immutable Infrastructure and Disposable Components
This builds a virtual server that accepts deployments via git push
.
It runs the Docker-powered mini-Heroku Dokku
on a Hetzner Cloud project.
This is the software you need:
- GNU Make
- Terraform 0.12 or newer
Once you have all required software, in the root directory of this project, run this command and follow the instructions:
$ make HOSTNAME=my.host.example.tld
- asks for your Hetzner Cloud API token and stores it in
terraform.tfvars
- copies your public SSH key
~/.ssh/id_rsa.pub
to the cloud project (so you can log in) - creates a server
- installs dokku + dependencies on that server
- installs the dokku-letsencrypt plugin
With a file named cloud-init/secrets.sh
,
you can customize the creation of your dokku instance.
That file is being ignored by git, use it to pass sensitive information like
credentials for external services to your dokku instance.
Here's an example:
# secrets.sh
dokku apps:create node-js-sample
dokku config:set node-js-sample DATABASE_URL=zzz
Commands in secrets.sh
will be executed as the very last step.
To remove all this, run:
$ terraform destroy