IMPROVED - unify dev pattern: DB-only Docker + host app, safe start, add test:watch
CI / quality (push) Waiting to run

This commit is contained in:
MOH
2026-08-07 15:05:34 +02:00
parent 0a5f77d8de
commit cdf0380f79
4 changed files with 98 additions and 53 deletions
+15 -4
View File
@@ -1,8 +1,19 @@
DATABASE_URL="postgresql://USER:PASSWORD@HOST:5432/moh_sass?schema=public" # Local dev: app runs on host (npm run dev), only Postgres runs in Docker.
NEXT_PUBLIC_APP_URL="https://mohfarawati.de" # Production: docker-compose.yml runs the full stack (deploy via `make deploy`).
NEXT_PUBLIC_SITE_URL="https://mohfarawati.de"
NEXT_PUBLIC_ADMIN_URL="https://root.mohfarawati.de" # --- Database ---
# Local: localhost:5432 (exposed from Docker). Server: db:5432 (Compose internal).
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/moh_sass"
# --- URLs ---
NEXT_PUBLIC_APP_URL="http://localhost:3014"
NEXT_PUBLIC_SITE_URL="http://localhost:3014"
NEXT_PUBLIC_ADMIN_URL="http://rootmohfarawati.localhost:3014"
ADMIN_HOST="rootmohfarawati.localhost"
NEXT_TELEMETRY_DISABLED="1" NEXT_TELEMETRY_DISABLED="1"
# --- Admin auth ---
ADMIN_PASSWORD="change-me" ADMIN_PASSWORD="change-me"
ADMIN_AUTH_SECRET="replace-with-a-long-random-secret" ADMIN_AUTH_SECRET="replace-with-a-long-random-secret"
ADMIN_BASIC_AUTH_USER="change-me" ADMIN_BASIC_AUTH_USER="change-me"
+80 -47
View File
@@ -1,47 +1,88 @@
.PHONY: start stop restart deploy logs build ps port health clean-orphans app-shell db-shell db-init db-migrate db-generate test test-watch help # mohfarawati.de — task runner.
# Local dev = DB in Docker, app on host (`npm run dev`).
# Production = docker-compose.yml runs the full stack on the server.
MIGRATION_NAME ?= init .DEFAULT_GOAL := help
.PHONY: help install start stop restart db-up db-down \
migrate generate db-generate db-push studio psql \
build deploy deploy-logs deploy-down \
test test-watch \
health help
## --- Help ------------------------------------------------------------------
help:
@echo "Local development (DB in Docker, app on host):"
@echo " make start Start DB + dev server (http://localhost:3014)"
@echo " make stop Stop the database container"
@echo " make restart Restart DB + dev server"
@echo " make install Install host dependencies"
@echo ""
@echo "Database:"
@echo " make db-up Start only the database container"
@echo " make db-down Stop the database container"
@echo " make migrate Apply Drizzle migrations"
@echo " make db-generate Generate a migration from schema changes"
@echo " make db-push Push schema to DB (dev shortcut, no migration)"
@echo " make studio Open Drizzle Studio to browse the database"
@echo " make psql Open a psql shell on the database"
@echo ""
@echo "Quality:"
@echo " make build Production build"
@echo " make test Run the whole test suite + copy-paste summary"
@echo " make test-watch Run the test suite in watch mode"
@echo ""
@echo "Deploy (run on the SERVER, with .env filled in):"
@echo " make deploy Pull latest, rebuild, restart"
@echo " make deploy-logs Follow the app logs"
@echo " make deploy-down Stop the production stack"
@echo " make health Check app health endpoint via public domain"
## --- Local development (DB in Docker, app on host) -------------------------
install:
npm install
start: start:
docker compose up -d --build -@docker compose stop app 2>/dev/null || true
docker compose up -d db
@for _ in $$(seq 1 20); do docker compose exec -T db pg_isready -U postgres >/dev/null 2>&1 && break; sleep 1; done
npm run dev
stop: stop:
docker compose down docker compose down
restart: stop start restart: stop start
deploy: ## --- Database --------------------------------------------------------------
git pull
docker compose up -d --build
@git log -1 --oneline
logs: db-up:
docker compose logs -f --tail=200 docker compose up -d db
build: db-down:
docker compose build docker compose down
ps: migrate:
docker compose ps npm run db:migrate
port: generate: db-generate ## Alias for db-generate
@echo "Site: http://localhost:3014"
@echo "Admin: http://rootmohfarawati.localhost:3014"
clean-orphans: db-generate:
docker compose up -d --remove-orphans npm run db:generate
app-shell: db-push:
docker compose exec app sh npm run db:push
db-shell: studio:
npm run db:studio
psql:
docker compose exec db psql -U postgres -d moh_sass docker compose exec db psql -U postgres -d moh_sass
db-init: ## --- Quality ---------------------------------------------------------------
docker compose exec app npm run db:migrate
db-migrate: build:
docker compose exec app npm run db:migrate npm run build
test: test:
@node scripts/test-summary.mjs @node scripts/test-summary.mjs
@@ -49,28 +90,20 @@ test:
test-watch: test-watch:
npm run test:watch npm run test:watch
db-generate: ## --- Deploy (server) -------------------------------------------------------
docker compose exec app npm run db:generate # Run these ON THE SERVER, inside the repo. docker-compose.yml is the full stack
# (app + db); the server does `git pull` + `make deploy`.
deploy:
git pull
docker compose up -d --build
@git log -1 --oneline
deploy-logs:
docker compose logs -f --tail=200
deploy-down:
docker compose down
health: health:
curl -sS https://mohfarawati.de/api/health curl -sS https://mohfarawati.de/api/health
help:
@echo "Available targets:"
@echo " make start Start all containers"
@echo " make stop Stop and remove containers"
@echo " make restart Restart all containers"
@echo " make deploy Pull latest code and deploy updated stack"
@echo " make logs Follow container logs"
@echo " make build Build images"
@echo " make ps Show container status"
@echo " make port Show app public URL"
@echo " make clean-orphans Remove orphaned old containers"
@echo " make app-shell Open shell in app container"
@echo " make db-shell Open PostgreSQL shell"
@echo " make db-init Apply Drizzle migrations to the DB"
@echo " make db-migrate Apply Drizzle migrations (drizzle-kit migrate)"
@echo " make db-generate Generate a migration from schema changes (drizzle-kit generate)"
@echo " make health Check app health endpoint via public domain"
@echo " make test Run the whole test suite + print a copy-paste summary"
@echo " make test-watch Run the test suite in watch mode"
+1 -1
View File
@@ -7,6 +7,6 @@ export default defineConfig({
dbCredentials: { dbCredentials: {
url: url:
process.env.DATABASE_URL ?? process.env.DATABASE_URL ??
"postgresql://postgres:postgres@localhost:5432/moh_sass?schema=public", "postgresql://postgres:postgres@localhost:5432/moh_sass",
}, },
}); });
+2 -1
View File
@@ -3,11 +3,12 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev", "dev": "next dev -p 3014",
"build": "next build --webpack", "build": "next build --webpack",
"start": "next start", "start": "next start",
"lint": "eslint .", "lint": "eslint .",
"test": "vitest run", "test": "vitest run",
"test:watch": "vitest",
"db:generate": "drizzle-kit generate", "db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate", "db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push", "db:push": "drizzle-kit push",