mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-08-26 16:40:40 +03:00
Merge pull request #196 from grillazz/195-switch-project-to-uv
195 switch project to uv
This commit is contained in:
commit
e88f68e2bf
28
.github/workflows/build-and-test.yml
vendored
28
.github/workflows/build-and-test.yml
vendored
@ -7,20 +7,19 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [ "3.13" ]
|
python-version: [ "3.13" ]
|
||||||
poetry-version: [ "1.8.5" ]
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
PYTHONDONTWRITEBYTECODE: 1
|
PYTHONDONTWRITEBYTECODE: 1
|
||||||
PYTHONUNBUFFERED: 1
|
PYTHONUNBUFFERED: 1
|
||||||
POSTGRES_DB: testdb
|
POSTGRES_DB: testdb
|
||||||
POSTGRES_HOST: 127.0.0.1
|
POSTGRES_HOST: 127.0.0.1
|
||||||
POSTGRES_USER: app-user
|
POSTGRES_USER: panettone
|
||||||
POSTGRES_PASSWORD: secret
|
POSTGRES_PASSWORD: secret
|
||||||
PGPASSWORD: secret
|
PGPASSWORD: secret
|
||||||
REDIS_HOST: 127.0.0.1
|
REDIS_HOST: 127.0.0.1
|
||||||
@ -37,7 +36,7 @@ jobs:
|
|||||||
sqldb:
|
sqldb:
|
||||||
image: postgres:16
|
image: postgres:16
|
||||||
env:
|
env:
|
||||||
POSTGRES_USER: app-user
|
POSTGRES_USER: panettone
|
||||||
POSTGRES_PASSWORD: secret
|
POSTGRES_PASSWORD: secret
|
||||||
POSTGRES_DB: testdb
|
POSTGRES_DB: testdb
|
||||||
ports:
|
ports:
|
||||||
@ -48,18 +47,13 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Create database schema
|
- name: Create database schema
|
||||||
run: PGPASSWORD=secret psql -h 127.0.0.1 -d testdb -U app-user -c "CREATE SCHEMA shakespeare; CREATE SCHEMA happy_hog;"
|
run: PGPASSWORD=secret psql -h 127.0.0.1 -d testdb -U panettone -c "CREATE SCHEMA shakespeare; CREATE SCHEMA happy_hog;"
|
||||||
- uses: actions/setup-python@v5
|
|
||||||
|
- name: Install the latest version of uv and set the python version
|
||||||
|
uses: astral-sh/setup-uv@v5
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
- name: Install Poetry
|
|
||||||
uses: abatilo/actions-poetry@v3
|
- name: Test with python ${{ matrix.python-version }}
|
||||||
with:
|
run: uv run --frozen pytest
|
||||||
poetry-version: ${{ matrix.poetry-version }}
|
|
||||||
- name: Install dependencies
|
|
||||||
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
|
|
||||||
run: poetry install --no-interaction --no-root
|
|
||||||
- name: Test Code
|
|
||||||
run: poetry run pytest tests/
|
|
||||||
- name: Lint Code
|
|
||||||
run: poetry run ruff check .
|
|
||||||
|
87
Dockerfile
87
Dockerfile
@ -1,43 +1,62 @@
|
|||||||
FROM python:3.13-slim-bookworm AS base
|
FROM ubuntu:oracular AS build
|
||||||
RUN apt-get update \
|
|
||||||
&& apt-get upgrade -y \
|
|
||||||
&& apt-get install -y --no-install-recommends curl git build-essential \
|
|
||||||
&& apt-get autoremove -y
|
|
||||||
ENV POETRY_HOME="/opt/poetry"
|
|
||||||
RUN curl -sSL https://install.python-poetry.org | python3 -
|
|
||||||
|
|
||||||
FROM base AS install
|
RUN apt-get update -qy && apt-get install -qyy \
|
||||||
WORKDIR /home/code
|
-o APT::Install-Recommends=false \
|
||||||
|
-o APT::Install-Suggests=false \
|
||||||
|
build-essential \
|
||||||
|
ca-certificates \
|
||||||
|
python3-setuptools \
|
||||||
|
python3.13-dev \
|
||||||
|
git
|
||||||
|
|
||||||
# allow controlling the poetry installation of dependencies via external args
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
|
||||||
ARG INSTALL_ARGS="--no-root --no-interaction --no-ansi"
|
|
||||||
ENV POETRY_HOME="/opt/poetry"
|
|
||||||
ENV PATH="$POETRY_HOME/bin:$PATH"
|
|
||||||
COPY pyproject.toml poetry.lock ./
|
|
||||||
|
|
||||||
# install without virtualenv, since we are inside a container
|
ENV UV_LINK_MODE=copy \
|
||||||
RUN poetry config virtualenvs.create false \
|
UV_COMPILE_BYTECODE=1 \
|
||||||
&& poetry install $INSTALL_ARGS
|
UV_PYTHON_DOWNLOADS=never \
|
||||||
|
UV_PYTHON=python3.13 \
|
||||||
|
UV_PROJECT_ENVIRONMENT=/panettone
|
||||||
|
|
||||||
# cleanup
|
COPY pyproject.toml /_lock/
|
||||||
RUN curl -sSL https://install.python-poetry.org | python3 - --uninstall
|
COPY uv.lock /_lock/
|
||||||
RUN apt-get purge -y curl git build-essential \
|
|
||||||
&& apt-get clean -y \
|
|
||||||
&& rm -rf /root/.cache \
|
|
||||||
&& rm -rf /var/apt/lists/* \
|
|
||||||
&& rm -rf /var/cache/apt/*
|
|
||||||
|
|
||||||
FROM install AS app-image
|
RUN --mount=type=cache,target=/root/.cache
|
||||||
|
RUN cd /_lock && uv sync \
|
||||||
|
--locked \
|
||||||
|
--no-dev \
|
||||||
|
--no-install-project
|
||||||
|
##########################################################################
|
||||||
|
FROM ubuntu:oracular
|
||||||
|
|
||||||
ENV PYTHONPATH=/home/code/ PYTHONHASHSEED=0 PYTHONASYNCIODEBUG=1
|
ENV PATH=/panettone/bin:$PATH
|
||||||
|
|
||||||
COPY tests/ tests/
|
RUN groupadd -r panettone
|
||||||
COPY app/ app/
|
RUN useradd -r -d /panettone -g panettone -N panettone
|
||||||
COPY alembic/ alembic/
|
|
||||||
COPY .env alembic.ini ./
|
|
||||||
|
|
||||||
# create a non-root user and switch to it, for security.
|
STOPSIGNAL SIGINT
|
||||||
RUN addgroup --system --gid 1001 "app-user"
|
|
||||||
RUN adduser --system --uid 1001 "app-user"
|
|
||||||
USER "app-user"
|
|
||||||
|
|
||||||
|
RUN apt-get update -qy && apt-get install -qyy \
|
||||||
|
-o APT::Install-Recommends=false \
|
||||||
|
-o APT::Install-Suggests=false \
|
||||||
|
python3.13 \
|
||||||
|
libpython3.13 \
|
||||||
|
libpcre3 \
|
||||||
|
libxml2
|
||||||
|
|
||||||
|
RUN apt-get clean
|
||||||
|
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
COPY --from=build --chown=panettone:panettone /panettone /panettone
|
||||||
|
|
||||||
|
USER panettone
|
||||||
|
WORKDIR /panettone
|
||||||
|
COPY /app/ app/
|
||||||
|
COPY /tests/ tests/
|
||||||
|
COPY .env app/
|
||||||
|
COPY alembic.ini app/
|
||||||
|
COPY alembic/ app/alembic/
|
||||||
|
COPY logging-uvicorn.json /panettone/logging-uvicorn.json
|
||||||
|
|
||||||
|
RUN python -V
|
||||||
|
RUN python -Im site
|
||||||
|
RUN python -Ic 'import uvicorn'
|
||||||
|
4288
poetry.lock
generated
4288
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
122
pyproject.toml
122
pyproject.toml
@ -1,90 +1,34 @@
|
|||||||
[tool.poetry]
|
[project]
|
||||||
name = "fastapi-sqlalchemy-asyncpg"
|
name = "fastapi-sqlalchemy-asyncpg"
|
||||||
version = "0.0.17"
|
version = "0.1.0"
|
||||||
description = ""
|
description = "A modern FastAPI application with SQLAlchemy 2.0 and AsyncPG for high-performance async database operations. Features include JWT authentication with Redis token storage, password hashing, connection pooling, data processing with Polars, Rich logging, task scheduling with APScheduler, and Shakespeare datasets integration."
|
||||||
authors = ["Jakub Miazek <the@grillazz.com>"]
|
readme = "README.md"
|
||||||
packages = []
|
requires-python = ">=3.13"
|
||||||
license = "MIT"
|
dependencies = [
|
||||||
package-mode = false
|
"fastapi[all]>=0.115.6",
|
||||||
|
"pydantic[email]>=2.10.3",
|
||||||
[tool.poetry.dependencies]
|
"pydantic-settings>=2.7.0",
|
||||||
python = "^3.13"
|
"sqlalchemy>=2.0.36",
|
||||||
fastapi = {version = "^0.115.6", extras = ["all"]}
|
"uvicorn[standard]>=0.34.0",
|
||||||
pydantic = {version = "^2.10.3", extras = ["email"]}
|
"asyncpg>=0.30.0",
|
||||||
pydantic-settings = "^2.7.0"
|
"alembic>=1.14.0",
|
||||||
sqlalchemy = "^2.0.36"
|
"httpx>=0.28.1",
|
||||||
uvicorn = { version = "^0.34.0", extras = ["standard"]}
|
"pytest>=8.3.4",
|
||||||
asyncpg = "^0.30.0"
|
"pytest-cov>=6.0.0",
|
||||||
alembic = "^1.14.0"
|
"uvloop>=0.21.0",
|
||||||
httpx = "^0.28.1"
|
"httptools>=0.6.4",
|
||||||
pytest = "^8.3.4"
|
"rich>=13.9.4",
|
||||||
pytest-cov = "^6.0.0"
|
"pyjwt[cryptography]>=2.10.1",
|
||||||
uvloop = "^0.21.0"
|
"redis>=5.2.1",
|
||||||
httptools = "^0.6.4"
|
"bcrypt>=4.2.1",
|
||||||
rich = "^13.9.4"
|
"polars>=1.17.1",
|
||||||
pyjwt = {version = "^2.10.1", extras = ["cryptography"]}
|
"python-multipart>=0.0.20",
|
||||||
redis = "^5.2.1"
|
"fastexcel>=0.12.0",
|
||||||
bcrypt = "^4.2.1"
|
"fastapi-cache2>=0.2.1",
|
||||||
polars = "^1.17.1"
|
"inline-snapshot>=0.17.0",
|
||||||
python-multipart = "^0.0.20"
|
"dirty-equals>=0.8.0",
|
||||||
fastexcel = "^0.12.0"
|
"polyfactory>=2.18.1",
|
||||||
fastapi-cache2 = "^0.2.1"
|
"granian>=1.7.0",
|
||||||
inline-snapshot = "^0.17.0"
|
"apscheduler[redis,sqlalchemy]>=4.0.0a5",
|
||||||
dirty-equals = "^0.8.0"
|
"pendulum @ git+https://github.com/sdispater/pendulum.git@develop"
|
||||||
polyfactory = "^2.18.1"
|
]
|
||||||
granian = "^1.7.0"
|
|
||||||
apscheduler = {version = "^4.0.0a5", extras = ["redis,sqlalchemy"]}
|
|
||||||
pendulum = {git = "https://github.com/sdispater/pendulum.git", rev="develop"}
|
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
|
||||||
devtools = { extras = ["pygments"], version = "^0.12.2" }
|
|
||||||
safety = "*"
|
|
||||||
pyupgrade = "*"
|
|
||||||
ipython = "^8.26.0"
|
|
||||||
ruff = "^0.6.1"
|
|
||||||
sqlacodegen = "^3.0.0rc5"
|
|
||||||
tryceratops = "^2.3.3"
|
|
||||||
locust = "^2.31.3"
|
|
||||||
|
|
||||||
[build-system]
|
|
||||||
requires = ["poetry-core>=1.0.0"]
|
|
||||||
build-backend = "poetry.core.masonry.api"
|
|
||||||
|
|
||||||
[tool.ruff]
|
|
||||||
line-length = 120
|
|
||||||
indent-width = 4
|
|
||||||
|
|
||||||
lint.select = ["E", "F", "UP", "N", "C", "B"]
|
|
||||||
lint.ignore = ["E501"]
|
|
||||||
|
|
||||||
# Exclude a variety of commonly ignored directories.
|
|
||||||
exclude = ["alembic",]
|
|
||||||
# Assume Python 3.13
|
|
||||||
target-version = "py313"
|
|
||||||
|
|
||||||
[tool.ruff.lint.flake8-quotes]
|
|
||||||
docstring-quotes = "double"
|
|
||||||
|
|
||||||
[tool.ruff.lint.flake8-bugbear]
|
|
||||||
extend-immutable-calls = ["fastapi.Depends",]
|
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
|
||||||
addopts = "-v --doctest-modules --doctest-glob=*.md --ignore=alembic"
|
|
||||||
asyncio_mode = "strict"
|
|
||||||
env_files = [".env"]
|
|
||||||
|
|
||||||
[tool.tryceratops]
|
|
||||||
exclude = ["alembic",]
|
|
||||||
|
|
||||||
[tool.ruff.format]
|
|
||||||
# Like Black, use double quotes for strings.
|
|
||||||
quote-style = "double"
|
|
||||||
|
|
||||||
# Like Black, indent with spaces, rather than tabs.
|
|
||||||
indent-style = "space"
|
|
||||||
|
|
||||||
# Like Black, respect magic trailing commas.
|
|
||||||
skip-magic-trailing-comma = false
|
|
||||||
|
|
||||||
# Like Black, automatically detect the appropriate line ending.
|
|
||||||
line-ending = "auto"
|
|
Loading…
x
Reference in New Issue
Block a user