flowchart LR
CI(Continuous\nIntegration) --> CDel(Continuous\nDelivery) --> CD(Continuous\nDeployment)
Let's today setup a continuous deployment pipeline for our application. Before, we teach our CI/CD pipeline how to bring our application to the clouds (in this exercise PaaS Heroku), we need to test the setup on our workstation.
Heroku is one of the first PaaS platforms that achieved large commercial success. The Heroku engineers created the famous 12factor apps. Check also Heroku (Engineering) Values.
-
Setup an account on heroku.com
-
Please go to your hello-world python project from the last exercises. Follow the README.md and use Makefile targets to verify whether your application works.
-
Let's see whether we can start our application with gunicorn:
gunicorn hello_world:app
Gunicorn is a Python WSGI HTTP Server for UNIX. The default flask WSGI is only for development purposes. It is not suited for production.
-
The first step is to tell Heroku how to run our application. For this purpose, we will create a Procfile with the following content:
web: gunicorn hello_world:app
You can refer to the official documentations for more information.
-
How shall we test it? Luckily, Heroku provides us a CLI that let's to run our application as it would in the cloud. Follow the instruction devcenter.heroku.com/articles/heroku-cli to install the heroku CLI (hint: use
snap
). -
Let's verify whether Heroku will be able to run our application:
heroku local
Please use
curl
orhttp
to query your app. -
Time to deploy our app to Heroku:
# first we need to login to Heroku heroku login -i # create the app at the heroku side heroku create # refresh the Heroku web UI, you should see your # app name # (your internet browser) # notice # heroku uses git-a git remote -v # verify whether you commited Procfile to your git repo git status # deploy git push heroku master # Check the logs heroku logs
to ensure that you have your files also in github:
git push
An illustration how your local git repository is connected to two remotes (
git remote -v
):flowchart BT l(local\ngit) -- master --> H(remote\nheroku) l -- master --> G(remote\ngithub)
-
Go to the web interface and open your application to see whether it works.
Please use the Github Action to deploy our application on push to the master/main branch. There is a ready to use action deploy to heroku.
Benefits of using PaaS:
heroku ps:scale web=0
heroku ps:scale web=1
Add a status badge to your project README.md
, following the official documentation.
statuscake.com is a simple, yet powerful tool that informs us when our application is down. It checks from servers from around a world whether clients are able to use our service. Let's check how it works:
-
Create an account on statuscake.com
-
Create a contact group
-
Add a Uptime monitoring test:
- URL - url of your app on Heroku
- Name - as you wish
-
Change the test to make it fail, e.g., add the path to URL that our application is not handling.
-
After observing few errors, please change URL to the correct one.
- Programming Katas
- fswatch
- mutagen - sync with a remote machine
- vagrant - automatize a VM creation
- packer
- https://www.netlify.com/ - popular alternative to Heroku