Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ DATABASE__HOSTNAME=localhost
DATABASE__USERNAME=rDGJeEDqAz
DATABASE__PASSWORD=XsPQhCoEfOQZueDjsILetLDUvbvSxAMnrVtgVZpmdcSssUgbvs
DATABASE__PORT=5455
DATABASE__DB=default_db
DATABASE__DB=default_db

PROMETHEUS__ENABLED=true
PROMETHEUS__ADDR="127.0.0.1"
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: 2
updates:
- package-ecosystem: pip
- package-ecosystem: uv
directory: /
schedule:
interval: monthly
open-pull-requests-limit: 5
open-pull-requests-limit: 1
allow:
- dependency-type: "all"
groups:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dev_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
dev_build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Login to DockerHub
uses: docker/login-action@v3
Expand Down
35 changes: 13 additions & 22 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
image: postgres:18
env:
POSTGRES_PASSWORD: postgres
options: >-
Expand All @@ -22,36 +22,27 @@ jobs:
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v5
- name: "Set up Python"
uses: actions/setup-python@v6
with:
python-version: "3.13.1"
python-version-file: "pyproject.toml"

- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
virtualenvs-create: true
virtualenvs-in-project: false
virtualenvs-path: /opt/venv
version: "0.9.2"
enable-cache: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: /opt/venv
key: venv-${{ runner.os }}-python-3.13.1-${{ hashFiles('poetry.lock') }}

- name: Install dependencies and actiavte virtualenv
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --no-interaction --no-root
- name: Install the project
run: uv sync --locked --all-extras --dev
shell: bash

- name: Run tests
env:
SECURITY__JWT_SECRET_KEY: very-not-secret
DATABASE__HOSTNAME: localhost
DATABASE__PASSWORD: postgres
run: |
poetry run pytest
uv run pytest
39 changes: 12 additions & 27 deletions .github/workflows/type_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,23 @@ jobs:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v5
- name: "Set up Python"
uses: actions/setup-python@v6
with:
python-version: "3.13.1"
python-version-file: "pyproject.toml"

- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
virtualenvs-create: true
virtualenvs-in-project: true
version: "0.9.2"
enable-cache: true

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: false
virtualenvs-path: /opt/venv

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: /opt/venv
key: venv-${{ runner.os }}-python-3.13.1-${{ hashFiles('poetry.lock') }}

- name: Install dependencies and actiavte virtualenv
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --no-interaction --no-root
- name: Install the project
run: uv sync --locked --all-extras --dev
shell: bash

- name: Run ${{ matrix.check }}
run: |
poetry run ${{ matrix.check }} .
uv run ${{ matrix.check }} .
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-yaml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.12
rev: v0.14.14
hooks:
- id: ruff-format

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.12
rev: v0.14.14
hooks:
- id: ruff
- id: ruff-check
args: [--fix]
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
FROM python:3.13.5-slim-bookworm AS base
FROM python:3.14-slim-trixie AS base

ENV PYTHONUNBUFFERED=1
WORKDIR /build

# Create requirements.txt file
FROM base AS poetry
RUN pip install poetry==2.1.3
RUN poetry self add poetry-plugin-export
COPY poetry.lock pyproject.toml ./
RUN poetry export -o /requirements.txt --without-hashes
FROM base AS uv
COPY --from=ghcr.io/astral-sh/uv:0.9.2 /uv /uvx /bin/
COPY uv.lock pyproject.toml ./
RUN uv export --no-dev --no-hashes -o /requirements.txt --no-install-workspace --frozen
RUN uv export --only-group dev --no-hashes -o /requirements-dev.txt --no-install-workspace --frozen

FROM base AS final
COPY --from=poetry /requirements.txt .
COPY --from=uv /requirements.txt .

# Create venv, add it to path and install requirements
RUN python -m venv /venv
Expand All @@ -28,8 +28,9 @@ COPY alembic.ini .
COPY pyproject.toml .
COPY init.sh .

# Expose port
# Expose port 8000 for app and optional 9090 for prometheus metrics
EXPOSE 8000
EXPOSE 9090

# Make the init script executable
RUN chmod +x ./init.sh
Expand All @@ -39,4 +40,4 @@ ENTRYPOINT ["./init.sh"]

# Set CMD to uvicorn
# /venv/bin/uvicorn is used because from entrypoint script PATH is new
CMD ["/venv/bin/uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "2", "--loop", "uvloop"]
CMD ["/venv/bin/uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1", "--loop", "uvloop"]
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
BIND_PORT ?= 8000
BIND_HOST ?= localhost

.PHONY: help
help: ## Print this help message
grep -E '^[\.a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.env: ## Ensure there is env file or create one
echo "No .env file found. Want to create it from .env.example? [y/n]" && read answer && if [ $${answer:-'N'} = 'y' ]; then cp .env.example .env;fi

.PHONY: local-setup
local-setup: ## Setup local postgres database
docker compose up -d

.PHONY: up
up: local-setup ## Run FastAPI development server
uv run alembic upgrade head
uv run uvicorn app.main:app --reload --host $(BIND_HOST) --port $(BIND_PORT)

.PHONY: run
run: up ## Alias for `up`

.PHONY: down
down: ## Stop database
docker compose down

.PHONY: test
test: local-setup ## Run unit tests
uv run pytest .

.PHONY: lint
lint: local-setup ## Run all linters
uv run pre-commit run -a
uv run mypy .
Loading