Add Makefile targets for database management and improve dev/production workflows
- Introduced `drop-db` and `reset-db` targets for streamlined database operations, including database recreation and migration applications. - Added `help` target to document available Makefile commands for both development and production environments. - Expanded Makefile with new targets like `push-images` and `deploy` to enhance production deployment workflows. - Consolidated redundant code and added descriptions for improved maintainability and user experience.
This commit is contained in:
79
Makefile
79
Makefile
@@ -1,8 +1,39 @@
|
|||||||
.PHONY: dev dev-full prod down logs logs-dev clean clean-slate
|
.PHONY: help dev dev-full prod down logs logs-dev clean clean-slate drop-db reset-db push-images deploy
|
||||||
|
|
||||||
VERSION ?= latest
|
VERSION ?= latest
|
||||||
REGISTRY := gitea.pragmazest.com/cardosofelipe/app
|
REGISTRY := gitea.pragmazest.com/cardosofelipe/app
|
||||||
|
|
||||||
|
# Default target
|
||||||
|
help:
|
||||||
|
@echo "FastAPI + Next.js Full-Stack Template"
|
||||||
|
@echo ""
|
||||||
|
@echo "Development:"
|
||||||
|
@echo " make dev - Start backend + db (frontend runs separately)"
|
||||||
|
@echo " make dev-full - Start all services including frontend"
|
||||||
|
@echo " make down - Stop all services"
|
||||||
|
@echo " make logs-dev - Follow dev container logs"
|
||||||
|
@echo ""
|
||||||
|
@echo "Database:"
|
||||||
|
@echo " make drop-db - Drop and recreate empty database"
|
||||||
|
@echo " make reset-db - Drop database and apply all migrations"
|
||||||
|
@echo ""
|
||||||
|
@echo "Production:"
|
||||||
|
@echo " make prod - Start production stack"
|
||||||
|
@echo " make deploy - Pull and deploy latest images"
|
||||||
|
@echo " make push-images - Build and push images to registry"
|
||||||
|
@echo " make logs - Follow production container logs"
|
||||||
|
@echo ""
|
||||||
|
@echo "Cleanup:"
|
||||||
|
@echo " make clean - Stop containers"
|
||||||
|
@echo " make clean-slate - Stop containers AND delete volumes (DATA LOSS!)"
|
||||||
|
@echo ""
|
||||||
|
@echo "Subdirectory commands:"
|
||||||
|
@echo " cd backend && make help - Backend-specific commands"
|
||||||
|
@echo " cd frontend && npm run - Frontend-specific commands"
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Development
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
dev:
|
dev:
|
||||||
# Bring up all dev services except the frontend
|
# Bring up all dev services except the frontend
|
||||||
@@ -16,9 +47,6 @@ dev-full:
|
|||||||
# Bring up all dev services including the frontend (full stack)
|
# Bring up all dev services including the frontend (full stack)
|
||||||
docker compose -f docker-compose.dev.yml up --build -d
|
docker compose -f docker-compose.dev.yml up --build -d
|
||||||
|
|
||||||
prod:
|
|
||||||
docker compose up --build -d
|
|
||||||
|
|
||||||
down:
|
down:
|
||||||
docker compose down
|
docker compose down
|
||||||
|
|
||||||
@@ -28,19 +56,46 @@ logs:
|
|||||||
logs-dev:
|
logs-dev:
|
||||||
docker compose -f docker-compose.dev.yml logs -f
|
docker compose -f docker-compose.dev.yml logs -f
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Database Management
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
drop-db:
|
||||||
|
@echo "Dropping local database..."
|
||||||
|
@docker compose -f docker-compose.dev.yml exec -T db psql -U postgres -c "DROP DATABASE IF EXISTS app WITH (FORCE);" 2>/dev/null || \
|
||||||
|
docker compose -f docker-compose.dev.yml exec -T db psql -U postgres -c "DROP DATABASE IF EXISTS app;"
|
||||||
|
@docker compose -f docker-compose.dev.yml exec -T db psql -U postgres -c "CREATE DATABASE app;"
|
||||||
|
@echo "Database dropped and recreated (empty)"
|
||||||
|
|
||||||
|
reset-db: drop-db
|
||||||
|
@echo "Applying migrations..."
|
||||||
|
@cd backend && uv run python migrate.py --local apply
|
||||||
|
@echo "Database reset complete!"
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Production / Deployment
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
prod:
|
||||||
|
docker compose up --build -d
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
docker compose -f docker-compose.deploy.yml pull
|
docker compose -f docker-compose.deploy.yml pull
|
||||||
docker compose -f docker-compose.deploy.yml up -d
|
docker compose -f docker-compose.deploy.yml up -d
|
||||||
|
|
||||||
clean:
|
|
||||||
docker compose down -
|
|
||||||
|
|
||||||
# WARNING! THIS REMOVES CONTAINERS AND VOLUMES AS WELL - DO NOT USE THIS UNLESS YOU WANT TO START OVER WITH DATA AND ALL
|
|
||||||
clean-slate:
|
|
||||||
docker compose -f docker-compose.dev.yml down -v --remove-orphans
|
|
||||||
|
|
||||||
push-images:
|
push-images:
|
||||||
docker build -t $(REGISTRY)/backend:$(VERSION) ./backend
|
docker build -t $(REGISTRY)/backend:$(VERSION) ./backend
|
||||||
docker build -t $(REGISTRY)/frontend:$(VERSION) ./frontend
|
docker build -t $(REGISTRY)/frontend:$(VERSION) ./frontend
|
||||||
docker push $(REGISTRY)/backend:$(VERSION)
|
docker push $(REGISTRY)/backend:$(VERSION)
|
||||||
docker push $(REGISTRY)/frontend:$(VERSION)
|
docker push $(REGISTRY)/frontend:$(VERSION)
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Cleanup
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
clean:
|
||||||
|
docker compose down
|
||||||
|
|
||||||
|
# WARNING! THIS REMOVES CONTAINERS AND VOLUMES AS WELL - DO NOT USE THIS UNLESS YOU WANT TO START OVER WITH DATA AND ALL
|
||||||
|
clean-slate:
|
||||||
|
docker compose -f docker-compose.dev.yml down -v --remove-orphans
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: help lint lint-fix format format-check type-check test test-cov validate clean install-dev sync check-docker install-e2e test-e2e test-e2e-schema test-all drop-db reset-db
|
.PHONY: help lint lint-fix format format-check type-check test test-cov validate clean install-dev sync check-docker install-e2e test-e2e test-e2e-schema test-all
|
||||||
|
|
||||||
# Default target
|
# Default target
|
||||||
help:
|
help:
|
||||||
@@ -25,10 +25,6 @@ help:
|
|||||||
@echo " make test-all - Run all tests (unit + E2E)"
|
@echo " make test-all - Run all tests (unit + E2E)"
|
||||||
@echo " make check-docker - Check if Docker is available"
|
@echo " make check-docker - Check if Docker is available"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "Database:"
|
|
||||||
@echo " make drop-db - Drop local database entirely (requires Docker)"
|
|
||||||
@echo " make reset-db - Drop and recreate database with migrations"
|
|
||||||
@echo ""
|
|
||||||
@echo "Cleanup:"
|
@echo "Cleanup:"
|
||||||
@echo " make clean - Remove cache and build artifacts"
|
@echo " make clean - Remove cache and build artifacts"
|
||||||
|
|
||||||
@@ -123,22 +119,6 @@ test-all:
|
|||||||
@$(MAKE) test
|
@$(MAKE) test
|
||||||
@$(MAKE) test-e2e
|
@$(MAKE) test-e2e
|
||||||
|
|
||||||
# ============================================================================
|
|
||||||
# Database Management
|
|
||||||
# ============================================================================
|
|
||||||
|
|
||||||
drop-db: check-docker
|
|
||||||
@echo "🗑️ Dropping local database..."
|
|
||||||
@cd .. && docker compose -f docker-compose.dev.yml exec -T db psql -U postgres -c "DROP DATABASE IF EXISTS app WITH (FORCE);" 2>/dev/null || \
|
|
||||||
cd .. && docker compose -f docker-compose.dev.yml exec -T db psql -U postgres -c "DROP DATABASE IF EXISTS app;"
|
|
||||||
@cd .. && docker compose -f docker-compose.dev.yml exec -T db psql -U postgres -c "CREATE DATABASE app;"
|
|
||||||
@echo "✅ Database dropped and recreated (empty)"
|
|
||||||
|
|
||||||
reset-db: drop-db
|
|
||||||
@echo "🔄 Applying migrations..."
|
|
||||||
@uv run python migrate.py --local apply
|
|
||||||
@echo "✅ Database reset complete!"
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Cleanup
|
# Cleanup
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user