Skip to content

smindev/github-actions-deploy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

github-actions-deploy

Example FastAPI app with a full CI/CD pipeline via GitHub Actions: separate workflows for tests, linting, Docker build/push, and deploy triggers for Render, Vercel, and Fly.io.

FastAPI App

Simple app defined in app/main.py.

Run locally:

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000

Endpoints:

  • GET / returns greeting JSON
  • GET /health returns status JSON

Tests

Workflow: .github/workflows/tests.yml runs pytest. Manual run locally:

pip install -r requirements.txt pytest
pytest

Linting

Workflow: .github/workflows/lint.yml runs Ruff. Add Ruff locally:

pip install ruff
ruff check .

Docker

Dockerfile builds the service. Build locally:

docker build -t ghcr.io/<owner>/<repo>:local .

Run container:

docker run --rm -p 8000:8000 ghcr.io/<owner>/<repo>:local

Workflow .github/workflows/docker-build.yml builds and pushes ghcr.io/<owner>/<repo>:latest.

Deployment Workflows

You can enable any provider by adding required secrets.

Render

  • Create a Render Web Service from repo or specify Docker.
  • Obtain Deploy Hook URL from Render dashboard.
  • Add secret RENDER_DEPLOY_HOOK_URL. Workflow: .github/workflows/deploy-render.yml.

Vercel

  • Create Vercel project.
  • Add secrets: VERCEL_TOKEN, VERCEL_ORG_ID, VERCEL_PROJECT_ID. Workflow: .github/workflows/deploy-vercel.yml. For Python FastAPI on Vercel you typically wrap with serverless adapter or use edge functions; consider a separate vercel.json.

Fly.io

  • Install flyctl locally: brew install flyctl.
  • Run flyctl launch to create fly.toml (add it to repo) and choose internal port 8000.
  • Set secret FLY_API_TOKEN. Workflow: .github/workflows/deploy-fly.yml.

Example fly.toml (create this after flyctl launch):

app = "your-app-name"
[build]
  image = "ghcr.io/<owner>/<repo>:latest"
[env]
  PORT = "8000"
[http_service]
  internal_port = 8000
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 1

GitHub Actions Trigger Strategy

All workflows trigger on push to main. You can refine:

  • Run tests + lint on PR only.
  • Run docker build after merge.
  • Run deploy workflows only on tagged releases using:
on:
  push:
    tags:
      - 'v*'

Suggested Secrets

Add via repo Settings -> Secrets and variables -> Actions:

  • RENDER_DEPLOY_HOOK_URL
  • VERCEL_TOKEN
  • VERCEL_ORG_ID
  • VERCEL_PROJECT_ID
  • FLY_API_TOKEN

Extending

  • Add caching (pip cache) to speed builds.
  • Add matrix strategy for multiple Python versions in tests.
  • Add Snyk or Trivy scan step in Docker workflow.

Pipeline Flow

  1. Code pushed -> tests + lint run.
  2. If merged to main -> docker image built/pushed.
  3. Deploy workflows trigger provider updates using latest image or source.

Local Development Summary

python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt pytest ruff
ruff check .
pytest
uvicorn app.main:app --reload --port 8000

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 2

  •  
  •