chore(*): adopt project templates
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
.venv
|
||||
.env
|
||||
__pycache__
|
||||
*.pyc
|
||||
.ruff_cache
|
||||
.pytest_cache
|
||||
sessions
|
||||
+19
-6
@@ -1,14 +1,27 @@
|
||||
RUN_ENVIRONMENT=prod
|
||||
TZ=UTC
|
||||
|
||||
LOG__LEVEL=INFO
|
||||
LOG__LEVEL_EXTERNAL=WARNING
|
||||
LOG__SHOW_TIME=false
|
||||
LOG__CONSOLE_WIDTH=150
|
||||
|
||||
DB__HOST=postgres
|
||||
DB__PORT=5432
|
||||
DB__USER=beavergram
|
||||
DB__PASSWORD=beavergram
|
||||
DB__DB_NAME=beavergram
|
||||
DB__MIN_POOL_SIZE=5
|
||||
DB__MAX_POOL_SIZE=20
|
||||
DB__SCRIPTS_CONNECTION_URL=postgresql://beavergram:beavergram@localhost:5432/beavergram
|
||||
|
||||
TG__SESSION_NAME=beavergram
|
||||
TG__SESSIONS_DIR=sessions
|
||||
|
||||
API__HOST=0.0.0.0
|
||||
API__PORT=8080
|
||||
|
||||
AUTH__TOKEN=<AUTH__TOKEN>
|
||||
AUTH__TOKEN=
|
||||
|
||||
STORAGE__ROOT=./storage
|
||||
STORAGE__SHARD_DEPTH=2
|
||||
|
||||
LOG__LEVEL=INFO
|
||||
LOG__LEVEL_EXTERNAL=WARNING
|
||||
LOG__SHOW_TIME=false
|
||||
LOG__CONSOLE_WIDTH=150
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
## Checking commands
|
||||
After writing code, always run from `backend/`:
|
||||
```shell
|
||||
ruff format
|
||||
ruff check --fix
|
||||
ty check
|
||||
```
|
||||
+5
-4
@@ -1,5 +1,7 @@
|
||||
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
|
||||
|
||||
RUN apt-get update && apt-get install -y build-essential && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENV PATH="/app/.venv/bin:$PATH" \
|
||||
@@ -7,10 +9,6 @@ ENV PATH="/app/.venv/bin:$PATH" \
|
||||
UV_COMPILE_BYTECODE=1 \
|
||||
UV_LINK_MODE=copy
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends build-essential \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY pyproject.toml uv.lock ./
|
||||
RUN uv sync --frozen --no-install-project --no-dev
|
||||
|
||||
@@ -20,4 +18,7 @@ RUN uv sync --frozen --no-dev
|
||||
COPY alembic.ini ./
|
||||
COPY migrations ./migrations
|
||||
|
||||
COPY scripts ./scripts
|
||||
|
||||
ENTRYPOINT ["python", "-m"]
|
||||
CMD ["api"]
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
COMPOSE := cd .. && docker compose
|
||||
IMAGE := beavergram/backend
|
||||
IMAGE_INPUTS := pyproject.toml uv.lock Dockerfile
|
||||
CODE := src scripts ../frontend
|
||||
SERVICES := api userbot
|
||||
changed = ! git diff --quiet $(1) -- $(2) 2>/dev/null
|
||||
stamp = { git update-ref $(1) HEAD 2>/dev/null || true; }
|
||||
|
||||
.PHONY: fmt check build pre-deploy post-deploy migrate revision session
|
||||
|
||||
fmt:
|
||||
uv run ruff format
|
||||
uv run ruff check --fix
|
||||
|
||||
check:
|
||||
uv run ruff format --check
|
||||
uv run ruff check
|
||||
uv run ty check
|
||||
|
||||
build:
|
||||
$(COMPOSE) build api
|
||||
|
||||
pre-deploy:
|
||||
@if $(call changed,refs/deploy/backend,$(IMAGE_INPUTS)) || ! docker image inspect $(IMAGE) >/dev/null 2>&1; then \
|
||||
$(MAKE) build && $(call stamp,refs/deploy/backend) && $(call stamp,refs/deploy/backend-code); \
|
||||
fi
|
||||
@$(COMPOSE) config --services | grep -qx postgres && $(COMPOSE) up -d postgres || true
|
||||
$(MAKE) migrate
|
||||
|
||||
post-deploy:
|
||||
@if $(call changed,refs/deploy/backend-code,$(CODE)); then \
|
||||
running=$$($(COMPOSE) ps --services --status running | grep -x $(addprefix -e ,$(SERVICES))); \
|
||||
[ -z "$$running" ] || $(COMPOSE) restart $$running; \
|
||||
$(call stamp,refs/deploy/backend-code); \
|
||||
fi
|
||||
|
||||
migrate:
|
||||
$(COMPOSE) run --rm migrator $(or $(filter-out $@,$(MAKECMDGOALS)),upgrade head)
|
||||
|
||||
revision:
|
||||
$(COMPOSE) run --rm migrator revision --autogenerate -m "$(m)"
|
||||
|
||||
%:
|
||||
@:
|
||||
|
||||
session:
|
||||
uv run python scripts/session/create.py
|
||||
@@ -0,0 +1,15 @@
|
||||
services:
|
||||
api:
|
||||
networks:
|
||||
default: {}
|
||||
caddy:
|
||||
aliases:
|
||||
- beavergram-api
|
||||
|
||||
postgres:
|
||||
ports:
|
||||
- "127.0.0.1:${DB__PORT:-5432}:5432"
|
||||
|
||||
networks:
|
||||
caddy:
|
||||
external: true
|
||||
@@ -0,0 +1,107 @@
|
||||
services:
|
||||
api:
|
||||
build: backend
|
||||
image: beavergram/backend
|
||||
profiles: [api, services]
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
- path: backend/.env
|
||||
required: false
|
||||
environment:
|
||||
RUN_ENVIRONMENT: prod
|
||||
TZ: ${TZ:-UTC}
|
||||
STORAGE__ROOT: /app/storage
|
||||
volumes:
|
||||
- ./backend/src:/app/src
|
||||
- ./backend/scripts:/app/scripts
|
||||
- ./backend/sessions:/app/sessions
|
||||
- ./frontend/build:/app/static:ro
|
||||
- ${STORAGE__ROOT:-./storage}:/app/storage
|
||||
command: [api]
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
required: false
|
||||
networks:
|
||||
default:
|
||||
database:
|
||||
|
||||
userbot:
|
||||
build: backend
|
||||
image: beavergram/backend
|
||||
profiles: [userbot, services]
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
- path: backend/.env
|
||||
required: false
|
||||
environment:
|
||||
RUN_ENVIRONMENT: prod
|
||||
TZ: ${TZ:-UTC}
|
||||
STORAGE__ROOT: /app/storage
|
||||
volumes:
|
||||
- ./backend/src:/app/src
|
||||
- ./backend/scripts:/app/scripts
|
||||
- ./backend/sessions:/app/sessions
|
||||
- ${STORAGE__ROOT:-./storage}:/app/storage
|
||||
command: [userbot]
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
required: false
|
||||
networks:
|
||||
database:
|
||||
|
||||
postgres:
|
||||
image: timescale/timescaledb:2.27.1-pg17
|
||||
profiles: [postgres, external]
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_USER: ${DB__USER:-beavergram}
|
||||
POSTGRES_PASSWORD: ${DB__PASSWORD:-beavergram}
|
||||
POSTGRES_DB: ${DB__DB_NAME:-beavergram}
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
- ./backend/migrations/init:/docker-entrypoint-initdb.d:ro
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${DB__USER:-beavergram}"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
networks:
|
||||
database:
|
||||
aliases:
|
||||
- ${DB__HOST:-postgres}
|
||||
|
||||
migrator:
|
||||
build: backend
|
||||
image: beavergram/backend
|
||||
profiles: [migrate]
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
- path: backend/.env
|
||||
required: false
|
||||
environment:
|
||||
RUN_ENVIRONMENT: prod
|
||||
volumes:
|
||||
- ./backend/src:/app/src
|
||||
- ./backend/migrations:/app/migrations
|
||||
- ./backend/alembic.ini:/app/alembic.ini
|
||||
entrypoint: [alembic]
|
||||
command: [upgrade, head]
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
required: false
|
||||
networks:
|
||||
database:
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
|
||||
networks:
|
||||
database:
|
||||
Reference in New Issue
Block a user