/fastapi-heroku-template

⚡️ × 🦸 Template repository for deploying FastAPI to Heroku

Primary LanguageMakefile

Template for Deploying FastAPI to Heroku

Table of Contents

Directory Structure

.
├── Procfile
├── README.md
├── main.py
├── requirements.txt
└── runtime.txt

Install Packages

$ pip3 install -r requirements.txt # or make install

Run

$ uvicorn main:app --reload # or make run

Heroku Deploy

Install Homebrew

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install Heroku CLI

Create a Heroku account

$ brew tap heroku/brew && brew install heroku

Login

$ heroku login

Create Heroku Application

$ heroku create <app-name>

Create Repository

$ git init

Commit to Heroku Application

$ git add .
$ git commit -m "<commit-message>"
$ heroku git:remote -a <app-name>
$ git push heroku master

Using Make Command

Before use, enter the application name created with the heroku create command in the app_name variable.

$ make

Commit messages can be used by doing the following

$ make message="first commit" # or make commit

Using Environmental Variables

Create .env File

VARIABLE_NAME='***************'

Install Package

$ pip3 install python-dotenv

Editing File

import os


from dotenv import load_dotenv


load_dotenv()

VARIABLE_NAME = os.getenv("VARIABLE_NAME")

# ...

Makefile

commit:
	git add . && \
+ 	git rm --cached -r .gitignore && \
	git commit -m "$(message)" && \
	heroku git:remote -a $(app_name) && \
	git push heroku master