Skip to content

t19cs033/fastapi-coolify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

FastAPI + Coolify Deployment Guide

logo

This repository demonstrates how to deploy a FastAPI application using Coolify with minimal setup.

Quick Start

Project Structure

fastapi-coolify/
├── main.py
└── requirements.txt

Setup Instructions

Step 1: Configure FastAPI in Coolify Dashboard

  1. Login to Coolify Dashboard
  2. Click "+ New""Application"
  3. Select "GitHub" Select GitHub
  4. Paste the repository link: https://github.com/t19cs033/fastapi-coolify/ Paste the repository link
  5. Set Port Number (we used port 8003, but you can set any port freely. If you change it, make sure to update the port in your source code as well) Set Port Number
  6. If using Cloudflare Tunnel, specify in Domains: fastapi.yourdomain.com:8003 Cloudflare Tunnel domain
  7. Click "Deploy" button (this takes about 45 seconds)

Step 2: Verify Deployment

Access fastapi.yourdomain.com and you should see:

{"message":"Hello World!","status":"success"}

If this appears, your deployment was successful.

Using Cloudflare Tunnel (Recommended)

If you don't want to open ports on localhost or cloud instances, use Cloudflare Tunnel.

Benefits:

  • No need to open firewall ports
  • Automatic HTTPS
  • Enhanced security
  • Better performance

Setup Guide: https://coolify.io/docs/knowledge-base/cloudflare/tunnels/overview

Code Files

main.py

from fastapi import FastAPI
import os

app = FastAPI(title="My FastAPI App")

@app.get("/")
def read_root():
    return {"message": "Hello World!", "status": "success"}

@app.get("/health")
def health_check():
    return {"status": "healthy"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
    return {"item_id": item_id, "q": q}

# Coolify configuration
if __name__ == "__main__":
    import uvicorn
    PORT = int(os.environ.get("PORT", 8003))
    uvicorn.run("main:app", host="0.0.0.0", port=PORT)

requirements.txt

fastapi==0.104.1
uvicorn[standard]==0.24.0

Configuration Notes

  • Host Configuration: Use host="0.0.0.0" (not localhost)
  • Port Flexibility: Port can be customized, just ensure consistency between Coolify settings and source code
  • Auto-Detection: Coolify and Nixpacks automatically detect Python environment from requirements.txt
  • No Additional Config: No need for nixpacks.toml or Dockerfile

Resources

Development

Local Testing:

pip install -r requirements.txt
python main.py
# Access: http://localhost:8003

API Documentation:

  • Interactive docs: http://yourdomain.com/docs
  • OpenAPI schema: http://yourdomain.com/openapi.json

About

Deploy a FastAPI application using Coolify

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages