Coolify part 2 : deploying Flask/Quart app via Github
Introduction
This is part-2, make sure you've read part-1 of the series.
Interesting fact I encountered when reading / learning about Coolify is the abundance of JS/TS project examples but non-existant for Python project especially Flask or Quart.
I prefer to use a modular library like Flask/Quart rather than a "battery-included" library like Django. I love the freedom of choice when using Flask/Quart!
Deploy project via Coolify in your VPS
Continuing from the previous part (installing Coolify in VPS), now we can start deploying projects!
Tutorial references
There are plenty of references you can learn from, I don't want to waste my time writing / trying to explain what's been covered by others.
Videos
Articles
- First and foremost: Coolify docs
- Article #1
- Article #2
Requirement: watch the videos, read the articles + Coolify docs
Server setup
I encountered something odd, maybe a glitch: at first the server did not run well. It kept on saying something wrong with the yaml script. How I solved this: in Server -> Proxy tab, reset configuration to default
. This fixed the error and the server proxy runs well.
Deploy source: Github
Deploying via Github remains the easiest method. From the references provided above you should've got a picture on how to do this. However it's interesting there's lacking tutorials / references on how to deploy a Python webapp.
Install Github app
The references are pretty clear how to do this, also for better security and best practice: never give access to all repos, so choose only the selected repos.
Configuration
This one is an important step, as the references (JS/TS webapp) shows we only need to select the resource from Github and deploy --> DONE! But it's not the same with deploying Python based webapps. I'm using Flask and Quart, we need to add a line in the Start Command.
- Projects -> Configuration -> General: look for Start Command and input this template command:
your_server_runner binding your_app_name:app
What you input there depends on your server runner, for example app.py program:
- Using Gunicorn:
gunicorn -b 0.0.0.0:9000 app:app
- Using Hypercorn:
hypercorn --bind '0.0.0.0:3000' app:app
- Using Granian:
granian --interface asgi --host 0.0.0.0 --port 5000 app:app
Below is a Flask synchronous app:
Quart asynchronous app:
As you can see the commands are similar, just depends on the server runner you're using.
<--IMPORTANT!--> The step here is crucial and could make or break your app deployment if incorrectly setup. For example in the Flask app I'm using port 9000, then in the Network config we need to expose the correct port.
Press SAVE to activate the new config.
Modify firewall rules
Since we are going to use some other ports for our web apps, we need to enable them via firewall rules.
ufw allow 3000/tcp # port 3000
ufw allow 8080/tcp # port 8080
ufw allow 9000/tcp # port 9000
ufw status # check the firewall status
ufw reload # reload firewall to the latest config
Deploy the project
Assuming everything else is correct, last part is to press Deploy. You'll be taken to a new screen where the deployment process is shown underway and depending on the complexity of your app, it might take a while.
Deployment Log
Once the deployment process is done, go to the Logs tab. If you get these kinds of logs:
- Running on http://0.0.0.0:3000
- Listening at: http://0.0.0.0:9000
That means you've successfully built your app! Now click the Links tab where you can find the url, select the url and it will open a new window in a web browser. If you see your app then deployment is a SUCCESS...congrats!
Auto-build feature
One of the best part of Coolify: it supports auto-build feature just like in Vercel and other serverless providers. That means if you did an update to your webapp and pushed the update to Github, Coolify will auto-detect the changes and automatically auto-build and re-deploy the app.