# Dokku

[Dokku](http://dokku.viewdocs.io/dokku/) is an open-source Heroku-like, that helps you manage and deploy web applications.

## Installation

As of debian user we can install with apt

```
# install prerequisites
sudo apt update -qq >/dev/null
sudo apt install -qq -y apt-transport-https

# install docker
wget -nv -O - https://get.docker.com/ | sh

# install dokku
wget -nv -O - https://packagecloud.io/dokku/dokku/gpgkey | sudo apt-key add -
OS_ID="$(lsb_release -cs 2>/dev/null || echo "bionic")"
echo "xenial bionic focal" | grep -q "$OS_ID" || OS_ID="bionic"
echo "deb https://packagecloud.io/dokku/dokku/ubuntu/ ${OS_ID} main" | sudo tee /etc/apt/sources.list.d/dokku.list
sudo apt update -qq >/dev/null
sudo apt install -qq -y dokku
sudo dokku plugin:install-dependencies --core
```

When asked, you can accept web page front end installation.

### Configure your host

#### Using a regular host on the web

If you are using a domain provider, make sure to create an A record in your DNS table,
pointing to your server's Ip.

#### Using localhost
If you are deploying dokker on your local machine (for testing purpose), you will need to modify `/etc/hosts` AND use `dnsmasq` ( Replace `<dokku.local>` by the domain name of your choice).  

1. modify first line of `/etc/hosts` :   
    ```
    127.0.0.1   localhost   <dokku.local>
    ```   
2. `sudo apt install dnsmasq`  
3. `sudo systemctl enable dnsmasq`  
4. Add `address=/<dokku.local>/127.0.0.1` in `/etc/dnsmasq.conf` 
5. Reboot your computer


### Configure ssh

Configure a public/private key pair for ssh root access.  
Run following commands as root:  
1. As root, run `ssh-keygen`  
2. Copy the key to authorized keys for dokku:  
    ```
    cat ~/.ssh/id_rsa.pub  |sshcommand acl-add dokku superuser
    ```  
3. In setup webpage at `http://<dokku.local>`, paste content from  `/root/.ssh/id_rsa.pub` (only the part with `ssh-rsa`).  

![Screenshot of dokku setup webpage](img/dokku-setup.png)

## Create app

```
git clone https://github.com/heroku/python-getting-started
dokku apps:create python-getting-started
dokku postgres:create djangodatabase
dokku postgres:link djangodatabase python-getting-started
cd python-getting-started/
git checkout -b master
git remote add dokku dokku@dokku.talkie.social:django.dokku.talkie.social
sudo git push dokku master
```

