IMPROVED - unify dev pattern: DB-only Docker + host app, safe start, add test:watch
CI / quality (push) Waiting to run
CI / quality (push) Waiting to run
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user