Rushi Patel

June 18, 2024

[Tech][CI/CD] Deployment with Dokku on Digital Ocean

Notes on Setting Up Deployment with Dokku and Git:


Documentation: https://dokku.com/docs/getting-started/installation/

Prerequisite:
- Cloud provider: Digital Ocean
- Terminal commands: MacOS
- Git already installed on your local machine

Steps to setup deployment:

1. Create Droplet (remote machine) on DigitalOcean or any other cloud provider (make sure RAM size is at least 1GB to run rails app)
2. Make sure it has you RSA key for ssh access
3. Terminal > ssh root@xxx.xx.xx.xxx
4. Intall Dokku:
sudo DOKKU_TAG=v0.34.0 bash bootstrap.sh

5. New Terminal > cat ~/.ssh/id_rsa.pub

6. Setup a user's ssh key for deployment by passing in the public ssh key as shown:
 echo 'CONTENTS_OF_ID_RSA_PUB_FILE' | dokku ssh-keys:add admin

7. git remote add dokku dokku@xxx.xx.xx.xxx:app-name

8. Terminal > ssh root@xxx.xx.xx.xxx
dokku config:set --no-restart app-name RAILS_MASTER_KEY=xxxxxxxxx

9. git push dokku main

10. Try step-11 & 14 first. If doesn’t work then remove default Nginx page:
> rm /etc/nginx/sites-enabled/default
> systemctl reload nginx

11. Tell Nginx to point to your dokku app (If custom domain is available skip this step and go to step-13):
dokku domains:add app-name xxx.xx.xx.xxx

If no custom domain go directly to step -14 after step-11

—————————Not recommended———————

12. Manually change port from 3000 to 80 in Nginx file (Not recommended- check step 14)
> cat /home/dokku/app-name/nginx.conf
> nano /home/dokku/app-name/nginx.conf
> nginx -t
> Change 3000 to 80
> ctrl-x + Y + enter
> systemctl status nginx

——-----SSL Certification——————

13. Setup let’s encrypt:
> dokku domains:add app-name www.yoursite.com
> dokku config:set --no-restart app-name DOKKU_LETSENCRYPT_EMAIL=your-email@example.com (not recommended)
> dokku letsencrypt:set app-name email youemail@gmail.com (recommended)
> dokku letsencrypt:enable app-name

—----In case of error: Could not obtain certificates-—---
——Remove unnecessary domain—
> dokku domains:report app-name
> dokku domains:remove app-name xxx.xxx.xxx.xxx

——Certificate retrieval failed!—-
—Check ports. For Encrypt and to view app you need port mapping (step-14)—

———————————————————-

14. Map ports (correct way)
dokku ports:add app-name http:8080:3000
dokku ports:add app-name https:443:3000
dokku ports:list app-name





Written by,
Rushi Patel




About Rushi Patel

Keep scrolling or press my profile icon at the top to view all my posts. Happy reading!