192 lines
No EOL
6.4 KiB
Makefile
192 lines
No EOL
6.4 KiB
Makefile
.PHONY: help install dev-services dev-stop-services dev-backend dev-frontend dev build test lint clean up down restart logs celery-worker celery-beat celery-flower celery-shell
|
|
|
|
IMAGE_NAME = my-flask-react-app
|
|
|
|
# Git Remotes
|
|
ORIGIN_REMOTE = origin
|
|
DEPLOY_REMOTE = deploy
|
|
|
|
# Get current git commit hash
|
|
GIT_HASH = $(shell git rev-parse --short HEAD)
|
|
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
|
|
|
|
help: ## Show this help message
|
|
@echo "Available commands:"
|
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
|
|
|
install: ## Install dependencies
|
|
@echo "Installing backend dependencies..."
|
|
cd backend && python3 -m venv venv
|
|
. backend/venv/bin/activate && pip install -r backend/requirements/dev.txt
|
|
@echo "Installing frontend dependencies..."
|
|
cd frontend && npm install
|
|
|
|
dev-services: ## Start development services (postgres & redis only)
|
|
@echo "Starting development services (postgres & redis)..."
|
|
docker compose -f docker-compose.dev.yml up -d
|
|
|
|
dev-stop-services: ## Stop development services
|
|
@echo "Stopping development services..."
|
|
docker compose -f docker-compose.dev.yml down
|
|
|
|
dev-backend: ## Start backend server locally
|
|
@echo "Starting backend server..."
|
|
cd backend && . venv/bin/activate && flask run
|
|
|
|
dev-frontend: ## Start frontend server locally
|
|
@echo "Starting frontend server..."
|
|
cd frontend && npm run dev
|
|
|
|
dev: ## Start development environment
|
|
@echo "Starting development environment..."
|
|
docker-compose -f docker-compose.dev.yml up -d
|
|
@echo "In one terminal run: make dev-backend"
|
|
@echo "In another terminal run: make dev-frontend"
|
|
|
|
build: ## Build Docker images
|
|
@echo "Building Docker images..."
|
|
docker compose build
|
|
|
|
up: ## Start all services
|
|
@echo "Starting all services..."
|
|
docker compose up -d
|
|
|
|
down: ## Stop all services
|
|
@echo "Stopping all services..."
|
|
docker compose down
|
|
|
|
restart: ## Restart all services
|
|
@echo "Restarting all services..."
|
|
docker compose restart
|
|
|
|
logs: ## Show logs from all services
|
|
docker compose logs -f
|
|
|
|
test: ## Run all tests
|
|
@echo "Running backend tests..."
|
|
cd backend && . venv/bin/activate && pytest
|
|
@echo "Running frontend tests..."
|
|
cd frontend && npm test
|
|
|
|
test-backend: ## Run backend tests only
|
|
cd backend && . venv/bin/activate && pytest
|
|
|
|
test-backend-cov: ## Run backend tests with coverage
|
|
cd backend && . venv/bin/activate && pytest --cov=app --cov-report=html --cov-report=term
|
|
|
|
test-backend-verbose: ## Run backend tests with verbose output
|
|
cd backend && . venv/bin/activate && pytest -v
|
|
|
|
test-backend-unit: ## Run backend unit tests only
|
|
cd backend && . venv/bin/activate && pytest -m unit
|
|
|
|
test-backend-integration: ## Run backend integration tests only
|
|
cd backend && . venv/bin/activate && pytest -m integration
|
|
|
|
test-backend-auth: ## Run backend authentication tests only
|
|
cd backend && . venv/bin/activate && pytest -m auth
|
|
|
|
test-backend-product: ## Run backend product tests only
|
|
cd backend && . venv/bin/activate && pytest -m product
|
|
|
|
test-backend-order: ## Run backend order tests only
|
|
cd backend && . venv/bin/activate && pytest -m order
|
|
|
|
test-frontend: ## Run frontend tests only
|
|
cd frontend && npm test
|
|
|
|
lint: ## Run linting
|
|
@echo "Linting backend..."
|
|
cd backend && . venv/bin/activate && flake8 app tests
|
|
@echo "Linting frontend..."
|
|
cd frontend && npm run lint
|
|
|
|
lint-backend: ## Lint backend only
|
|
cd backend && . venv/bin/activate && flake8 app tests
|
|
|
|
lint-frontend: ## Lint frontend only
|
|
cd frontend && npm run lint
|
|
|
|
format: ## Format code
|
|
@echo "Formatting backend..."
|
|
cd backend && . venv/bin/activate && black app tests
|
|
cd backend && . venv/bin/activate && isort app tests
|
|
@echo "Formatting frontend..."
|
|
cd frontend && npx prettier --write "src/**/*.{js,jsx,ts,tsx,css}"
|
|
|
|
format-backend: ## Format backend code only
|
|
@echo "Formatting backend with black..."
|
|
cd backend && . venv/bin/activate && black app tests
|
|
@echo "Sorting imports with isort..."
|
|
cd backend && . venv/bin/activate && isort app tests
|
|
|
|
format-backend-check: ## Check if backend code needs formatting
|
|
@echo "Checking backend formatting..."
|
|
cd backend && . venv/bin/activate && black --check app tests
|
|
cd backend && . venv/bin/activate && isort --check-only app tests
|
|
|
|
format-frontend: ## Format frontend code only
|
|
@echo "Formatting frontend..."
|
|
cd frontend && npx prettier --write "src/**/*.{js,jsx,ts,tsx,css}"
|
|
|
|
migrate: ## Run database migrations
|
|
cd backend && . venv/bin/activate && flask db upgrade
|
|
|
|
shell: ## Open Flask shell
|
|
cd backend && . venv/bin/activate && flask shell
|
|
|
|
clean: ## Clean up build artifacts
|
|
@echo "Cleaning up..."
|
|
cd backend && rm -rf __pycache__ *.pyc .pytest_cache
|
|
cd frontend && rm -rf dist node_modules/.cache
|
|
|
|
prune: ## Remove unused Docker resources
|
|
docker system prune -a
|
|
|
|
backup: ## Backup database
|
|
docker exec crafting-shop-postgres pg_dump -U crafting crafting_shop > backup.sql
|
|
|
|
restore: ## Restore database (usage: make restore FILE=backup.sql)
|
|
docker exec -i crafting-shop-postgres psql -U crafting crafting_shop < $(FILE)
|
|
|
|
# Celery Commands
|
|
celery-worker: ## Start Celery worker locally
|
|
@echo "Starting Celery worker..."
|
|
cd backend && . venv/bin/activate && celery -A celery_worker worker --loglevel=info --concurrency=4
|
|
|
|
celery-beat: ## Start Celery Beat scheduler locally
|
|
@echo "Starting Celery Beat scheduler..."
|
|
cd backend && . venv/bin/activate && celery -A celery_worker beat --loglevel=info
|
|
|
|
celery-flower: ## Start Flower monitoring locally
|
|
@echo "Starting Flower monitoring..."
|
|
cd backend && . venv/bin/activate && celery -A celery_worker flower --port=5555
|
|
|
|
celery-shell: ## Open Celery shell for task inspection
|
|
@echo "Opening Celery shell..."
|
|
cd backend && . venv/bin/activate && celery -A celery_worker shell
|
|
|
|
logs-celery: ## Show Celery worker logs
|
|
docker compose logs -f celery_worker
|
|
|
|
logs-celery-beat: ## Show Celery Beat logs
|
|
docker compose logs -f celery_beat
|
|
|
|
logs-flower: ## Show Flower logs
|
|
docker compose logs -f flower
|
|
|
|
docker-build: ## Show Flower logs
|
|
docker build -f docker/Dockerfile -t $(IMAGE_NAME):$(GIT_HASH) -t $(IMAGE_NAME):latest .
|
|
|
|
docker-run: ## Show Flower logs
|
|
docker run -p 8001:8000 $(IMAGE_NAME):latest
|
|
|
|
# Push to deploy remote (triggers deployment)
|
|
push-deploy:
|
|
@echo "Pushing to deploy remote ($(GIT_BRANCH))..."
|
|
git push $(DEPLOY_REMOTE) $(GIT_BRANCH)
|
|
|
|
# Push to deploy remote (triggers deployment)
|
|
push-deploy-force:
|
|
@echo "Pushing to deploy remote ($(GIT_BRANCH))..."
|
|
git push $(DEPLOY_REMOTE) $(GIT_BRANCH) --force-with-lease
|