uwblueprint/sistering

[DONE - ARCHIVED FOR REFERENCE] Setup Prod instance - Dokku

Opened this issue · 0 comments

Install all required dependencies to run backend/frontend/db, check our dockerfiles for reference on what to install.

We would like Postgresql 12.11 and Node 14.5.5 as we would like a DB service and a place for our Node (Graphql) backend service to run with versions as similar to our development environment as possible. For your information, we use the docker images node:14.15.5-slim for our local backend container and postgres:12-alpine for our db container.

Action: create bash script to install all dependencies

Docker images:
https://github.com/nodejs/docker-node/blob/main/14/buster-slim/Dockerfile#L20
https://github.com/docker-library/postgres/blob/master/12/alpine/Dockerfile

initial server setup guide: https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-20-04 might help.

For an Apache webserver server, which would be a guide like this: https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-20-04.

The flow of the bash script

  1. Add non-sudo user
  2. Install needed deps to run all services

We want to setup dokku on the machine and run all the required containers in the VM: https://dokku.com/docs/getting-started/installation/

To make this closest to prod as possible, we want to deploy just backend and db in vps, frontend on firebase hosting

 wget -nv -O - https://get.docker.com/ | sh
 wget -nv -O - https://packagecloud.io/dokku/dokku/gpgkey | sudo apt-key add -
 export SOURCE="https://packagecloud.io/dokku/dokku/ubuntu/"
 export OS_ID="$(lsb_release -cs 2>/dev/null || echo "bionic")"
 echo "bionic focal" | grep -q "$OS_ID" || OS_ID="bionic"
 echo "deb $SOURCE $OS_ID main" | sudo tee /etc/apt/sources.list.d/dokku.list
 sudo apt-get update
 sudo apt-get install dokku
 sudo dokku plugin:install-dependencies --core

# you can use any domain you already have access to
# this domain should have an A record or CNAME pointing at your server's IP
dokku domains:set-global sisteringapps.asurtec.com

# from your local machine
# SSH access to github must be enabled on this host
git clone https://github.com/uwblueprint/sistering

# on the Dokku host
dokku apps:create sistering-prod

# on the Dokku host
# install the postgres plugin
# plugin installation requires root, hence the user change
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git

# create a postgres service with the name sisteringdatabase
dokku postgres:create sisteringdatabase

# on the Dokku host
# each official datastore offers a `link` method to link a service to any application
dokku postgres:link sisteringdatabase sistering-prod

dokku config:set --no-restart sistering-prod ENV1=val1 ENV2=val2 ....

# from your local machine
# the remote username *must* be dokku or pushes will fail
cd sistering
git remote add dokku dokku@sisteringapps.asurtec.com:sistering-prod
 cat ~/.ssh/id_rsa.pub | ssh uwblueprint@sisteringapps.asurtec.com sudo dokku ssh-keys:add admin 
git push dokku `git subtree split --prefix backend`:master --force