Files
natureinpots_community/Makefile

122 lines
3.9 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Project Variables
ENV_FILE=.env
ENV_EXAMPLE=.env.example
DOCKER_COMPOSE=docker compose
PROJECT_NAME=plant_price_tracker
# Commands
.PHONY: help up down rebuild logs logs-web logs-worker logs-flower logs-all status seed shell dbshell reset test
help:
@echo "Available targets:"
@echo " up - Build and start the app (bootstraps .env if needed)"
@echo " down - Stop and remove containers"
@echo " rebuild - Rebuild containers from scratch"
@echo " logs-web - Show recent logs for the web service"
@echo " logs-worker - Show recent logs for the Celery worker"
@echo " logs-flower - Show recent logs for the Flower UI"
@echo " logs-all - Show recent logs for all services"
@echo " status - Show container health status"
@echo " seed - Manually seed the database"
@echo " shell - Open a bash shell in the web container"
@echo " dbshell - Open a MySQL shell"
@echo " reset - Nuke everything and restart clean"
@echo " test - Run test suite (TBD)"
up:
@if [ ! -f $(ENV_FILE) ]; then \
echo "[⚙] Generating .env from example..."; \
cp $(ENV_EXAMPLE) $(ENV_FILE); \
fi
$(DOCKER_COMPOSE) up --build -d
@$(MAKE) wait
up-nobuild:
@if [ ! -f $(ENV_FILE) ]; then \
echo "[⚙] Generating .env from example..."; \
cp $(ENV_EXAMPLE) $(ENV_FILE); \
fi
$(DOCKER_COMPOSE) up -d
@$(MAKE) wait
down:
$(DOCKER_COMPOSE) down
rebuild:
$(DOCKER_COMPOSE) down -v --remove-orphans
$(DOCKER_COMPOSE) build
$(DOCKER_COMPOSE) up -d db
sleep 5 # give MySQL a moment to initialize
$(DOCKER_COMPOSE) exec -T db mysql -uroot -p$$(grep MYSQL_ROOT_PASSWORD .env | cut -d '=' -f2) -e "DROP DATABASE IF EXISTS natureinpots; CREATE DATABASE natureinpots CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
$(DOCKER_COMPOSE) up --build -d
@$(MAKE) wait
preload:
@docker exec -it $$(docker ps -qf "name=$(PROJECT_NAME)-web") flask preload-data
logs-web:
@echo "[📜] Tailing last 200 lines of web service logs…"
$(DOCKER_COMPOSE) logs --tail=200 -f web
logs-worker:
@echo "[📜] Tailing last 200 lines of worker service logs…"
$(DOCKER_COMPOSE) logs --tail=200 -f worker
logs-flower:
@echo "[📜] Tailing last 200 lines of flower service logs…"
$(DOCKER_COMPOSE) logs --tail=200 -f flower
logs-all:
@echo "[📜] Tailing last 200 lines of ALL services logs…"
$(DOCKER_COMPOSE) logs --tail=200 -f
# alias old 'logs' to unified
logs: logs-all
status:
@echo "[📊] Health status of containers:"
@docker ps --filter "name=$(PROJECT_NAME)-" --format "table {{.Names}}\t{{.Status}}"
seed:
@docker exec -it $$(docker ps -qf "name=$(PROJECT_NAME)-web") flask preload-data
shell:
@docker exec -it $$(docker ps -qf "name=$(PROJECT_NAME)-web") bash
dbshell:
@docker exec -it $$(docker ps -qf "name=$(PROJECT_NAME)-db") \
mysql -u$$(grep MYSQL_USER $(ENV_FILE) | cut -d '=' -f2) \
-p$$(grep MYSQL_PASSWORD $(ENV_FILE) | cut -d '=' -f2) \
$$(grep MYSQL_DATABASE $(ENV_FILE) | cut -d '=' -f2)
reset:
@echo "[💣] Nuking containers and volumes..."
$(DOCKER_COMPOSE) down -v --remove-orphans
@echo "[🧼] Cleaning caches and migrations..."
sudo rm -rf __pycache__ */__pycache__ */*/__pycache__ *.pyc *.pyo *.db migrations
@echo "[🚀] Rebuilding project fresh..."
@$(MAKE) up
test:
@echo "[🚧] Test suite placeholder"
# insert pytest or unittest commands here
wait:
@echo "[⏳] Waiting for web container to be healthy..."
@timeout 30 bash -c '\
WEB_CONTAINER=$$($(DOCKER_COMPOSE) ps -q web); \
if [ -z "$$WEB_CONTAINER" ]; then \
echo "[❌] Could not detect web container!"; \
exit 1; \
fi; \
echo "[] Detected container: $$WEB_CONTAINER"; \
while [ "$$(docker inspect -f "{{.State.Health.Status}}" $$WEB_CONTAINER 2>/dev/null)" != "healthy" ]; do \
sleep 2; echo -n "."; \
done; echo "\n[✅] $$WEB_CONTAINER is healthy!"'
migrate:
flask db migrate -m "auto"
upgrade:
flask db upgrade