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"
NEXT_PUBLIC_APP_URL="https://mohfarawati.de"
NEXT_PUBLIC_SITE_URL="https://mohfarawati.de"
NEXT_PUBLIC_ADMIN_URL="https://root.mohfarawati.de"
# Local dev: app runs on host (npm run dev), only Postgres runs in Docker.
# Production: docker-compose.yml runs the full stack (deploy via `make deploy`).
# --- 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"
# --- Admin auth ---
ADMIN_PASSWORD="change-me"
ADMIN_AUTH_SECRET="replace-with-a-long-random-secret"
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:
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:
docker compose down
restart: stop start
deploy:
git pull
docker compose up -d --build
@git log -1 --oneline
## --- Database --------------------------------------------------------------
logs:
docker compose logs -f --tail=200
db-up:
docker compose up -d db
build:
docker compose build
db-down:
docker compose down
ps:
docker compose ps
migrate:
npm run db:migrate
port:
@echo "Site: http://localhost:3014"
@echo "Admin: http://rootmohfarawati.localhost:3014"
generate: db-generate ## Alias for db-generate
clean-orphans:
docker compose up -d --remove-orphans
db-generate:
npm run db:generate
app-shell:
docker compose exec app sh
db-push:
npm run db:push
db-shell:
studio:
npm run db:studio
psql:
docker compose exec db psql -U postgres -d moh_sass
db-init:
docker compose exec app npm run db:migrate
## --- Quality ---------------------------------------------------------------
db-migrate:
docker compose exec app npm run db:migrate
build:
npm run build
test:
@node scripts/test-summary.mjs
@@ -49,28 +90,20 @@ test:
test-watch:
npm run test:watch
db-generate:
docker compose exec app npm run db:generate
## --- Deploy (server) -------------------------------------------------------
# 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:
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: {
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",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev -p 3014",
"build": "next build --webpack",
"start": "next start",
"lint": "eslint .",
"test": "vitest run",
"test:watch": "vitest",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",