Skip to content

hyukjuns/fastapi-mysql-crud

Repository files navigation

FastAPI Sample API Server

V2 Todo

  1. Note App
GET /notes 모든 메모 조회
GET /notes/{id} 특정 메모 조회
POST /notes 새 메모 추가
PUT /notes/{id} 메모 수정
DELETE /notes/{id} 메모 삭제
  1. MySQL
  2. Dockerfile, Docker-Compose
  3. Kubernetes Manifests
  4. 문서화
  5. CI/CD 개선

Environments

  • Azure
    • Azure Kubernetes Service 1.28.13
    • Kubernetes Addons: Ingress NGINX Controller, ArgoCD, Argo Rollouts
    • Azure Container Registry
  • Github Repository
    • Application Source Code & Kubernetes Manifest
    • Github Actions Pipeline (CI)
  • Slack for Notification
  • Python > 3.11.x
  • FastAPI > 0.115.0
  • VSCode

CI Step (Github Actions)

File: docker-image.yml

Job 01

  1. Checkout repo
  2. Setup Python
  3. Setup pip cache (actions/cache@v3)
  4. Install Dependencies and PyTest Application
  5. Upload Pytest Results as Github Actions Artifacts
  6. Post to a Slack channel
  7. Approve / Deny (environment)

Job 02

  1. Checkout repo
  2. Setup Docker Buildx
  3. Login to ACR
  4. Build and Push Container Image to ACR (docker/[email protected]) (registry type 빌드 캐시 사용)
  5. Modify Rollout Manifest by yq
  6. Post to a Slack channel

CD Step (GitOps) - Argo CD & Argo Rollouts

  1. Detect manifest change by Argo CD
  2. Auto Sync by Argo CD
  3. Blue / Green Deploy by Argo Rollouts
  4. Promote or Abort (Manually)
  5. Swap Active / Preview Service's Selector Hash
  6. Monitoring and rollback or not

cicd

FastAPI Sample Application

Directory: /app

  • main.py: 샘플 GET / POST / PUT / DELETE 구현

  • test_rest.py: 빌드 전 pytest를 위한 샘플 테스트 코드

Containerizing

Dockerfile

Kubernetes Manifests

Directory: kubernetes

Ingress NGINX Controller Installation

rollouts.yaml

ingress.yaml

Reference

About

fastapi, mysql, docker, kubernetes, github actions

Resources

Stars

Watchers

Forks

Packages

No packages published