Skip to content

Backport improvements #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 23, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,4 @@ dmypy.json
cython_debug/

credentials.env
volumes/
31 changes: 7 additions & 24 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/runConfigurations/Dev_Dependencies.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions .idea/runConfigurations/FastAPI_app.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion .idea/runConfigurations/Socket_io_app.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 7 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ containers:
docker compose build --build-arg UID=`id -u`

dev-http:
uv run ./src/http_app/dev_server.py
docker compose up dev-http

dev-socketio:
uv run ./src/socketio_app/dev_server.py
docker compose up dev-socketio

run:
uv run uvicorn http_app:create_app --host 0.0.0.0 --port 8000 --factory
migrate:
docker compose run --rm migrate

autogenerate-migration:
docker compose run --rm autogenerate-migration

test:
uv run pytest -n auto --cov
Expand All @@ -34,9 +37,6 @@ update-dependencies:
uv lock --upgrade
uv sync --all-groups --frozen

migrate:
uv run alembic upgrade heads

format:
uv run ruff format --check .

Expand All @@ -53,8 +53,5 @@ check: lint format typing test
docs:
uv run mkdocs serve

adr:
adr-viewer --serve --adr-path docs/adr

docs-build:
uv run mkdocs build
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,31 @@ Create your GitHub repository using this template (The big green `Use this templ
Optionally tweak name and authors in the `pyproject.toml` file, however the metadata
are not used when building the application, nor are referenced anywhere in the code.

Before running any commands, install `uv`:
Before running any commands, install `uv` and `Docker`:

- On Mac (using `brew`): `brew install uv`
- You can install `uv` on Mac using `brew`: `brew install uv`
- Download and install Docker: https://www.docker.com/products/docker-desktop/

Using Docker:

* `make containers`: Build containers
* `docker compose run --rm dev make migrate`: Run database migrations
* `docker compose up dev-http`: Run HTTP application with hot reload
* `docker compose up dev-socketio`: Run HTTP application with hot reload
* `docker compose up dramatiq-worker`: Run the dramatiq worker
* `docker compose run --rm test`: Run test suite
* `docker compose run --rm migrate`: Run database migrations
* `docker compose run --rm autogenerate-migration`: Generate a new migration file

Locally:
Using Make (you still need Docker for most of them):

* `make migrate`: Run database migrations
* `make install-dependencies`: Install requirements
* `make dev-dependencies`: Install dev requirements
* `make update-dependencies`: Updates requirements
* `make migrate`: Run database migrations
* `make dev-http`: Run HTTP application with hot reload
* `make dev-socketio`: Run HTTP application with hot reload
* `make test`: Run test suite
* `make migrate`: Run database migrations
* `make autogenerate-migration`: Generate a new migration file

## Other commands for development

Expand Down
4 changes: 4 additions & 0 deletions alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME
hooks = ruff
ruff.type = exec
ruff.executable = %(here)s/.venv/bin/ruff
ruff.options = format REVISION_SCRIPT_FILENAME
3 changes: 3 additions & 0 deletions credentials.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GC_USERNAME: <GRAFANA_USERNAME>
GC_PASSWORD: <GRAFANA_TOKEN>
GC_ENDPOINT: <GRAFANA_OTLP_ENDPOINT>
72 changes: 60 additions & 12 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@ services:
dockerfile: Dockerfile
context: .
target: dev
env_file: local.env
env_file: docker.env
environment:
APP_NAME: "bootstrap-fastapi"
APP_NAME: "backend-fastapi"
ports:
- '8000:8000'
working_dir: "/app/src"
volumes:
- '.:/app'
depends_on:
- redis
- otel-collector
redis:
condition: service_healthy
otel-collector:
condition: service_started
mariadb:
condition: service_healthy
command:
- python
- ./http_app/dev_server.py

dev-socketio:
<<: *dev
environment:
APP_NAME: "bootstrap-socketio"
APP_NAME: "backend-socketio"
ports:
- '8001:8001'
command:
Expand Down Expand Up @@ -52,6 +56,7 @@ services:
- jaeger
ports:
- "12345:12345"
- "4317:4317"
volumes:
- ./config.alloy:/etc/alloy/config.alloy
command:
Expand All @@ -63,11 +68,34 @@ services:

redis:
image: redis
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5

mariadb:
image: mariadb:11.4
environment:
MYSQL_ROOT_PASSWORD: "stanis"
MYSQL_DATABASE: "backend"
MYSQL_USER: "corinna"
MYSQL_PASSWORD: "gioieiiere"
volumes:
- ./volumes/mariadb:/var/lib/mysql
ports:
- "3306:3306"
healthcheck:
test: [ "CMD", "healthcheck.sh", "--su-mysql", "--connect", "--innodb_initialized" ]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s

dramatiq-worker:
<<: *dev
environment:
APP_NAME: "bootstrap-dramatiq-worker"
APP_NAME: "backend-dramatiq-worker"
ports: []
command:
- dramatiq
Expand Down Expand Up @@ -151,12 +179,32 @@ services:
#### One-off commands ####
##########################
test:
build:
dockerfile: Dockerfile
context: .
target: dev
volumes:
- '.:/app'
<<: *dev
environment:
APP_NAME: "backend-test"
ports: []
command:
- "make"
- "test"

migrate:
<<: *dev
environment:
APP_NAME: "backend-migrations"
ports: []
command:
- "alembic"
- "upgrade"
- "heads"

autogenerate-migration:
<<: *dev
environment:
APP_NAME: "backend-migration-generator"
ports: []
command:
- "alembic"
- "revision"
- "--autogenerate"
- "-m"
- "Description message"
6 changes: 6 additions & 0 deletions local.env → docker.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ AUTH__JWKS_URL: "http://oathkeeper:4456/.well-known/jwks.json"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector:4317"
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST: ".*"
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE: ".*"
CORS_ORIGINS: ["*"]
GC_USERNAME: FAKE_USERNAME
GC_PASSWORD: FAKE_PASS
GC_ENDPOINT: FAKE_ENDPOINT
SQLALCHEMY_CONFIG__default__engine_url: mysql+asyncmy://corinna:gioieiiere@mariadb/backend?charset=utf8mb4
SQLALCHEMY_CONFIG__default__async_engine: true
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ readme = "README.md"
dependencies = [
"aiosqlite>=0.18.0",
"asgiref<4.0.0,>=3.7.2",
"asyncmy>=0.2.10",
"cloudevents-pydantic<1.0.0,>=0.0.3",
"dependency-injector[pydantic]<5.0.0,>=4.41.0",
"dramatiq[redis,watch]<2.0.0,>=1.17.1",
Expand All @@ -24,7 +25,6 @@ dependencies = [
"pydantic<3.0.0,>=2.2.1",
"pydantic-asyncapi>=0.2.1",
"pydantic-settings<3.0.0,>=2.0.3",
"rich<14.0.0,>=13.2.0",
"SQLAlchemy[asyncio,mypy]<3.0.0,>=2.0.0",
"sqlalchemy-bind-manager",
"structlog<25.1.1,>=25.1.0",
Expand Down
6 changes: 6 additions & 0 deletions src/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ script_location = migrations
prepend_sys_path = .
file_template = %%(year)d-%%(month).2d-%%(day).2d-%%(hour).2d%%(minute).2d%%(second).2d-%%(rev)s_%%(slug)s
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.

[post_write_hooks]
hooks = ruff
ruff.type = exec
ruff.executable = /venv/bin/ruff
ruff.options = format REVISION_SCRIPT_FILENAME
Loading