Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6b51e74
ci
GregoryGoldfox Apr 6, 2024
3a7381f
ci testing
GregoryGoldfox Apr 6, 2024
c0f1c7e
ci python version update
GregoryGoldfox Apr 6, 2024
8b80805
ci adding pytests
GregoryGoldfox Apr 6, 2024
7afc12b
adding black and isort
GregoryGoldfox Apr 6, 2024
1a271c5
blacked
GregoryGoldfox Apr 6, 2024
3e8814f
adding pytest conf to pyproject.toml
GregoryGoldfox Apr 11, 2024
d8e056b
fixing pyproject.toml
GregoryGoldfox Apr 11, 2024
f583645
adding pytest to poetry and messing with black
GregoryGoldfox Apr 11, 2024
8ce39c4
messing with black
GregoryGoldfox Apr 11, 2024
a3d7b12
not messing with black
GregoryGoldfox Apr 11, 2024
a119482
adding tests
GregoryGoldfox Apr 12, 2024
598512b
fixing imports
GregoryGoldfox Apr 12, 2024
1721eb6
separating alembic test
GregoryGoldfox Apr 12, 2024
4580e07
black is going insane
GregoryGoldfox Apr 12, 2024
2d5066d
configuring yml
GregoryGoldfox Apr 13, 2024
3c34682
configuring yml
GregoryGoldfox Apr 13, 2024
9feae40
configuring yml
GregoryGoldfox Apr 13, 2024
9bbdea3
configuring yml
GregoryGoldfox Apr 13, 2024
923fbc0
Fix postgres service github actions
Apr 13, 2024
1c3acc9
Fix postgres service github actions
Apr 13, 2024
946a20a
Fix postgres service github actions 3
Apr 13, 2024
616b893
Fix postgres service github actions 3
Apr 13, 2024
8703803
Fix postgres service github actions 3
Apr 13, 2024
da91acf
Fix postgres service github actions 3
Apr 13, 2024
bd53c30
Test 1
Apr 13, 2024
17f46bd
Test success
Apr 13, 2024
50a4dc1
Postgres to pytest
Apr 13, 2024
631d87c
fixing db
GregoryGoldfox Apr 15, 2024
297b183
Merge branch 'github_actions' of github.com:bandirom/fastapi-template…
GregoryGoldfox Apr 15, 2024
e680bab
fixing mistakes
GregoryGoldfox Apr 16, 2024
66386c3
fixing mistakes
GregoryGoldfox Apr 16, 2024
e48108e
adding caching
GregoryGoldfox Apr 22, 2024
7a99762
merging
GregoryGoldfox May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Use Python Poetry cache on GitHub Actions workflow

on:
push:
branches:
- github_actions

env:
PYTHON_VERSION: "3.12"
POETRY_VERSION: "1.7.1"
POETRY_URL: https://install.python-poetry.org

jobs:
use_cache:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
id: setup_python
# Poetry cache depends on OS, Python version and Poetry version.
- name: Cache Poetry cache
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
# virtualenv cache should depend on OS, Python version and `poetry.lock` (and optionally workflow files)..
- name: Cache Packages
uses: actions/cache@v3
with:
path: ~/.local
key: poetry-local-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
- name: Install Poetry ${{ env.POETRY_VERSION }}
run: |
curl -sSL ${{ env.POETRY_URL }} | python - --version ${{ env.POETRY_VERSION }}
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install Dependencies
run: poetry install
# Write actual actions here.
100 changes: 100 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Tests
on:
push:
branches:
- '*'

env:
POETRY_VIRTUALENVS_CREATE: false
DATABASE_URI: 'postgresql+asyncpg://fastapi:postgres_password@localhost:5432/template'

jobs:
tests:
name: run pytest
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15.1-alpine
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_PASSWORD: postgres_password
POSTGRES_USER: fastapi
POSTGRES_DB: template
steps:
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: checkout repo
uses: actions/checkout@v4
- name: install dependencies
run: |
pip install poetry
poetry install --with dev
- name: pytest
run:
pytest
black:
name: run black
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: checkout repo
uses: actions/checkout@v4
- name: install dependencies
run: |
pip install black
- name: black
run: black . --check
isort:
name: run isort
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: checkout repo
uses: actions/checkout@v4
- name: install dependencies
run: |
pip install isort
- name: isort
run: isort . --check
alembic_check:
name: run alembic check
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15.1-alpine
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_PASSWORD: postgres_password
POSTGRES_USER: fastapi
POSTGRES_DB: template
steps:
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: checkout repo
uses: actions/checkout@v4
- name: install dependencies
run: |
pip install poetry
poetry install
- name: apply migrations
run: alembic upgrade head
- name: check migrations
run: alembic check
1 change: 1 addition & 0 deletions alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import logging
from logging.config import fileConfig

from sqlalchemy import pool
Expand Down
4 changes: 1 addition & 3 deletions api/services/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@


async def validation_exception_handler(request: Request, exc: ValidationError) -> JSONResponse:
return JSONResponse(status_code=400, content={"detail": {
"code": exc.code, "detail": exc.detail
}})
return JSONResponse(status_code=400, content={"detail": {"code": exc.code, "detail": exc.detail}})
4 changes: 2 additions & 2 deletions core/gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from multiprocessing import cpu_count

bind = "0.0.0.0:8000"
workers : int = cpu_count() * 2 + 1
worker_class = "uvicorn.workers.UvicornWorker"
workers: int = cpu_count() * 2 + 1
worker_class = "uvicorn.workers.UvicornWorker"
Loading