# DreamHost Cloud Server Installation Notes

Cloud-init script can be used to automate installation of Dokku on
Dreamhost (or any other OpenStack-compatible cloud with minimal
changes).

A new server instance can be created on DreamHost Cloud from the command line
using OpenStack client or from the web UI and with the same command
use a cloud-init script to install Dokku. Install the [OpenStack
CLI](https://help.dreamhost.com/hc/en-us/articles/216185658-How-to-Install-the-OpenStack-command-line-clients),
download the [DreamHost Cloud credentials
file](https://iad2.dreamcompute.com/project/access_and_security/api_access/openrc/)
before proceeding and make sure your public SSH key is added to the
cloud.

```sh
source openrc.sh # Set the environment variables for DreamHost Cloud
```

This allows OpenStack client to connect to DreamHost API endpoints.
The command below creates a new server instance named `my-dokku-instance`
based on Ubuntu 24.04, with 2 GB RAM and 1 CPU (the flavor called
`supersonic`), opening network port access to HTTP and SSH (the
`default` security group), and the name of the chosen SSH key. This
key will be automatically added to the new server in the
`authorized_keys` for the default SSH user (`ubuntu`), and it will
be reused by Dokku.

```sh
openstack server create \
  --image Ubuntu-24.04 \
  --flavor gp1.supersonic \
  --security-group default \
  --key-name $YOUR_SSH_KEYNAME \
  --user-data dokku-cloudinit.sh \
  my-dokku-instance
```

The content of dokku-cloudinit.sh script contains instructions to add
Docker and Dokku's apt repositories and install Dokku with the proper
debconf options set. Don't forget to add the FQDN for your application
server:

```yaml
#cloud-config

apt:
  sources:
    source_dokku: 
      source: 'deb https://packagecloud.io/dokku/dokku/ubuntu/ $RELEASE main'
      key: |
        -----BEGIN PGP PUBLIC KEY BLOCK-----
        Version: GnuPG v1.4.11 (GNU/Linux)

[encoded data, 4234 characters]
        9mVAREENSiAuc4P93l8TtrN1bAqXaTX5oz+lepqWmHWvY+RiNiw=
        =laU4
        -----END PGP PUBLIC KEY BLOCK-----
    source_docker: 
      source: 'deb [arch=amd64] https://download.docker.com/linux/ubuntu $RELEASE stable'
      key: |
        -----BEGIN PGP PUBLIC KEY BLOCK-----

[encoded data, 4161 characters]
        YT90qFF93M3v01BbxP+EIY2/9tiIPbrd
        =0YYh
        -----END PGP PUBLIC KEY BLOCK-----

  debconf_selections:
    vhost:    dokku dokku/vhost_enable boolean true
    # set the domain name of the new Dokku server
    hostname: dokku dokku/hostname string $YOUR_FULL_QUALIFIED_DOMAIN
    # this copies over the public SSH key assigned to the server
    key:      dokku dokku/key_file string /home/ubuntu/.ssh/authorized_keys
    
packages:
    - dokku
package_update: true
package_upgrade: true
package_reboot_if_required: true
```

Shortly after running the create command you will get a confirmation that the
instance has been created, and after about a minute it should be ready to login. Check the IP of the instance through the web UI or by running:

```sh
nova list
```

SSH with the `ubuntu` username and the public key previously added.
Keep in mind that if you logged in quick enough Dokku might still be installing in the background, and not be ready. The installation takes a few minutes.
