A Hello World FastAPI app that deployed to Vercel using CI/CD.
Warning! According to Vercel Python Documentation, Vercel only support Python 3.9, Python 3.6 already deprecated. I recommend to use conda or mamba in order to set Python version in custom environment.
All the API codes (routes, models) are in server
folder. main.py
is to run FastAPI with uvicorn.
The API files structure as follows.
.
│ .gitignore
│ .vercelignore
│ main.py
│ README.md
│ requirements.txt
│ vercel.json
│
├───.github
│ └───workflows
│ preview.yaml
│ production.yaml
│
├───.vercel
│ project.json
│ README.txt
│
└───server
api.py
model.py
routes.py
__init__.py
The steps to run this API in local are as follows.
-
Create new environment and install requirements.
conda create -p .conda_env python=3.9 --file requirements.txt
-
Activate the environment.
conda activate ./.conda_env
-
Run the API.
python main.py
The CI/CD deployment steps are as follows.
-
Install Vercel CLI.
npm i -g vercel
-
Login Vercel CLI.
vercel login
-
Download this code as zip.
-
Create your new repository and git clone your repo.
-
Extract zip to your new repo folder.
-
Open terminal and link repo to Vercel.
vercel link
-
Add GitHub repository secrets for GitHub Actions
Name Description VERCEL_TOKEN Vercel account token. You can get it by following. VERCEL_ORG_ID Vercel Organization ID. You can get it from .vercel/project.json
.VERCEL_PROJECT_ID Vercel Project ID. You can get it from .vercel/project.json
. -
Commit repo.
-
Add main branch.
git branch -M main
-
Push to GitHub.
git push -u origin main
-
GitHub Actions will run immediately.