Whipping Up Deployment Magic with Dokku: A Humorous Recipe for Success
Welcome to the magical kitchen, where we're about to embark on a culinary adventure, whipping up a delectable deployment using Dokku and a dash of humor. If you're tired of the complicated and time-consuming deployment processes, fear not! We have just the right recipe to tickle your taste buds.
Ingredients:
1 Virtual Private Server (VPS)
1 trusty terminal
1 ssh connection
1 magic command script:
# Download the installation script
wget -NP . https://dokku.com/bootstrap.sh
# Run the installer
sudo DOKKU_TAG=v0.32.3 bash bootstrap.sh
# Clear global domains
dokku domains:clear-global
# Add your SSH key to the dokku user
PUBLIC_KEY="your-public-key-contents-here"
echo "$PUBLIC_KEY" | dokku ssh-keys:add admin
# Create your first app and you're off!
dokku apps:create test-app
1 custom domain
1 pinch of patience (essential ingredient!)
Instructions:
Connect to your VPS via SSH and kick off the magic spell by entering the command script.
Follow the on-screen prompts to complete the setup, ensuring Dokku is properly installed.
Push your app to the newly created app on Dokku using git from your local machine:
git remote add dokku dokku@your-server-ip:test-app
git push dokku master
- Now, let's add the custom domain. Grab your domain name and create a DNS A record pointing to your server IP.
dokku domains:add test-app your-custom-domain.com
# Port mapping
dokku ports:set test-app http:8080:5000
Port Mapping Explained:
In the enchanting line
dokku ports:set test-app http:8080:5000
, we're setting up port mapping for our Dokku-deployed application.http
: Specifies the protocol being used, which is HTTP in this case. For HTTPS, you'd usehttps
.8080
(hostPort): The port on the host machine (VPS) is mapped to the container. Accessing your VPS on port 8080 directs traffic to the container.5000
(containerPort): The port inside the Docker container where your application runs. External requests reach this port inside the container.
So, when someone knocks on your VPS's door at port 8080, Dokku waves its wand and guides them through the secret door at port 5000 inside the container where your app is having its magical feast.
- SSL setup:
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
dokku letsencrypt:set test-app email your@email.tld
dokku letsencrypt:enable test-app
- Voilà! Your beautifully deployed app with a custom domain is ready to be savored.
Bonus: The CI/CD Finale
Now, for the grand finale – the CI/CD part. Use this action file after creating .github/workflows:
name: Docker
on:
push:
branches:
- master
tags:
- v*
pull_request:
jobs:
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- id: deploy
name: Deploy to Dokku
uses: idoberko2/dokku-deploy-github-action@v1
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
dokku-host: '$server-ip-here'
app-name: 'test-app'
git-push-flags: '--force'
Replace '$server-ip-here' and 'test-app' with your server IP and app name. Don't forget to add your SSH private key as a secret in your GitHub repo.
And there you have it – a recipe for success served with a side of humor! Bon appétit!
Here's a video tutorial for the same!