From e37ceb058c9621e8d5571a6a4288b4b86b371287 Mon Sep 17 00:00:00 2001 From: Anto Subash Date: Sun, 31 May 2026 21:24:29 +0200 Subject: [PATCH] chore: use shared dev-services stack (Postgres/Redis/MinIO) Co-Authored-By: Claude Opus 4.8 (1M context) --- .env.example | 12 ++++++++-- CLAUDE.md | 18 ++++++++++++++ Makefile | 8 +++++-- docker-compose.yml | 59 +++++++++++++--------------------------------- 4 files changed, 50 insertions(+), 47 deletions(-) diff --git a/.env.example b/.env.example index 3e2b52ed..965022a9 100644 --- a/.env.example +++ b/.env.example @@ -2,9 +2,17 @@ # All module-level settings (SMTP, Celery, users, etc.) are now managed in # the admin UI at /settings/modules — no env vars needed. -# Database (required) +# Database (required). Default is local SQLite. To use the shared +# ../dev-services Postgres, uncomment the line below (db simple_module_python, +# user postgres/postgres): SM_DATABASE_URL=sqlite+aiosqlite:///./app.db -# SM_DATABASE_URL=postgresql+asyncpg://sm:sm@localhost:5432/simple_module +# SM_DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/simple_module_python + +# Celery against the shared ../dev-services Redis. Host-run worker/beat use +# localhost; the docker-compose worker/beat override to the `redis` hostname. +# This project owns Redis logical DBs 4 (broker) and 5 (result backend). +# SM_BG_TASKS_BROKER_URL=redis://localhost:6379/4 +# SM_BG_TASKS_RESULT_BACKEND=redis://localhost:6379/5 # Process identity (production must override SM_SECRET_KEY) SM_ENVIRONMENT=development diff --git a/CLAUDE.md b/CLAUDE.md index e0b3524f..c6315d0d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,6 +6,24 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co Python 3.12 + FastAPI + SQLModel + Alembic on the backend; Inertia.js + React + Tailwind 4 + Vite on the frontend. `uv` workspaces for Python, `npm` workspaces for JS. Package managers: `uv sync --all-packages` and `npm install`. +## Local database & services (shared dev-services stack) + +**Do NOT start your own Postgres/Redis container.** All repos in `~/Repos` share +one stack defined in `~/Repos/dev-services` (one PostGIS + Redis + MinIO + Adminer +on the `devnet` Docker network). `make docker-up` here brings that shared stack up +(it no longer starts a local postgres/redis); `make docker-down` only stops this +repo's own containers (worker/beat), never the shared stack. + +This repo's slice: + +- **Postgres**: `localhost:5432`, `postgres`/`postgres`, database + **`simple_module_python`** (the default `SM_DATABASE_URL` is SQLite; uncomment + the Postgres line in `.env.example` to use the shared DB). +- **Redis**: `localhost:6379`, logical DBs **4** (broker) / **5** (result backend). + +If a port is taken by an old per-project container, stop that container rather +than remapping ports. To add a database, edit `dev-services/init/01-databases.sql`. + ## Commands All day-to-day tasks go through `make`: diff --git a/Makefile b/Makefile index cc298e14..ae499391 100644 --- a/Makefile +++ b/Makefile @@ -161,10 +161,14 @@ kill: @-lsof -ti:8000,5050,5173 | xargs kill -9 2>/dev/null @echo "Ports 8000, 5050, 5173 freed." -# Docker +# Docker — Postgres/Redis now live in the shared ../dev-services stack. +# docker-up brings that shared stack up (idempotent, shared with other repos). docker-up: - docker compose up -d postgres redis + docker compose -f ../dev-services/compose.yml up -d +# Only stop THIS project's own containers (worker/beat). Never tear down the +# shared stack here — other repos depend on it. Use `make down` in +# ../dev-services to stop the shared services. docker-down: docker compose down diff --git a/docker-compose.yml b/docker-compose.yml index f1d90f8a..5a98a961 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,31 +1,9 @@ services: - postgres: - image: postgres:16 - environment: - POSTGRES_DB: simple_module - POSTGRES_USER: sm - POSTGRES_PASSWORD: sm - ports: - - "5432:5432" - volumes: - - pgdata:/var/lib/postgresql/data - healthcheck: - test: ["CMD-SHELL", "pg_isready -U sm -d simple_module"] - interval: 5s - timeout: 5s - retries: 10 - - redis: - image: redis:7-alpine - ports: - - "6379:6379" - volumes: - - redisdata:/data - healthcheck: - test: ["CMD", "redis-cli", "ping"] - interval: 5s - timeout: 3s - retries: 10 + # Postgres + Redis now come from the shared ../dev-services stack + # (one PostGIS + one Redis on the external `devnet` network). Start it first + # with `make up` in ~/Repos/dev-services. This project uses: + # database: simple_module_python (on shared postgres:5432, postgres/postgres) + # redis: DB 4 (broker) / DB 5 (result backend) worker: build: @@ -33,14 +11,10 @@ services: dockerfile: docker/worker.Dockerfile env_file: .env environment: - SM_BG_TASKS_BROKER_URL: redis://redis:6379/0 - SM_BG_TASKS_RESULT_BACKEND: redis://redis:6379/1 - SM_DATABASE_URL: ${SM_DATABASE_URL:-postgresql+asyncpg://sm:sm@postgres:5432/simple_module} - depends_on: - redis: - condition: service_healthy - postgres: - condition: service_healthy + SM_BG_TASKS_BROKER_URL: redis://redis:6379/4 + SM_BG_TASKS_RESULT_BACKEND: redis://redis:6379/5 + SM_DATABASE_URL: ${SM_DATABASE_URL:-postgresql+asyncpg://postgres:postgres@postgres:5432/simple_module_python} + networks: [devnet] command: - "uv" - "run" @@ -58,14 +32,13 @@ services: dockerfile: docker/worker.Dockerfile env_file: .env environment: - SM_BG_TASKS_BROKER_URL: redis://redis:6379/0 - SM_BG_TASKS_RESULT_BACKEND: redis://redis:6379/1 - SM_DATABASE_URL: ${SM_DATABASE_URL:-postgresql+asyncpg://sm:sm@postgres:5432/simple_module} + SM_BG_TASKS_BROKER_URL: redis://redis:6379/4 + SM_BG_TASKS_RESULT_BACKEND: redis://redis:6379/5 + SM_DATABASE_URL: ${SM_DATABASE_URL:-postgresql+asyncpg://postgres:postgres@postgres:5432/simple_module_python} depends_on: - redis: - condition: service_healthy worker: condition: service_started + networks: [devnet] command: - "uv" - "run" @@ -76,6 +49,6 @@ services: - "-l" - "info" -volumes: - pgdata: - redisdata: +networks: + devnet: + external: true