Files
website/Makefile
Andrew dfdef3d7f4 feat: docker compose dev environment
Replaces the bare-metal `composer run dev` workflow with a fully
containerized 9-service stack orchestrated by docker compose. Single
command brings up the full app — three subdomains (marketing /
account / admin) reachable via Traefik with TLS, MariaDB + Valkey
+ Mailpit + Vite HMR + Horizon + scheduler all wired in.

Components:
- docker-compose.yml: traefik, app (php-fpm), web (nginx), mariadb,
  valkey, mailpit, vite, horizon, scheduler.
- docker/: Dockerfiles, nginx config, entrypoint scripts.
- Makefile: convenience targets (up / down / logs / shell / migrate
  / seed / test / pint / etc).
- .env.docker.example: template for Docker-stack environment vars
  (separate from website/.env so bare-metal devs aren't disrupted).
- website/vite.config.ts: server.host / origin / hmr / cors hooks
  driven by VITE_HOST / VITE_ORIGIN / VITE_HMR_HOST so the same
  config serves both bare-metal and Docker.
- website/bootstrap/app.php: redirectGuestsTo() now uses
  request()->getScheme() so http: dev hosts don't get force-https
  redirects.
- composer.json: drops laravel/sail (replaced by this stack).
- docs/superpowers/specs/2026-04-25-docker-compose-dev-environment-design.md:
  full design spec.

Bare-metal `composer run dev` workflow stays usable for anyone who
prefers it — Docker stack reads .env.docker, doesn't fight
website/.env.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 22:10:53 -04:00

136 lines
3.6 KiB
Makefile

# ==============================================================================
# EZSCALE — Makefile shortcuts for the docker compose dev stack
# ==============================================================================
SHELL := /bin/bash
DC := docker compose
EXEC := $(DC) exec -T app
RUN := $(DC) run --rm app
.DEFAULT_GOAL := help
# -------------------------------------------------------------------- lifecycle
.PHONY: help
help: ## Show this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
.PHONY: init
init: ## First-time setup: copy .env.docker, build, install deps, migrate
@if [ ! -f .env.docker ]; then cp .env.docker.example .env.docker && echo "[init] created .env.docker"; fi
$(DC) build --pull
$(DC) up -d mariadb valkey
@echo "[init] waiting 10s for mariadb to settle..."
@sleep 10
$(RUN) composer install
$(DC) run --rm vite npm install
$(DC) up -d
@echo ""
@echo "Stack is up. Open https://ezscale.docker.localhost"
.PHONY: up
up: ## Start all services in the background
$(DC) up -d
.PHONY: down
down: ## Stop all services (volumes preserved)
$(DC) down
.PHONY: restart
restart: ## Restart all services
$(DC) restart
.PHONY: build
build: ## Rebuild all images
$(DC) build --pull
.PHONY: rebuild
rebuild: ## Rebuild from scratch (no cache)
$(DC) build --pull --no-cache
.PHONY: destroy
destroy: ## Stop everything AND wipe data volumes (DB, mail, etc.)
$(DC) down -v
.PHONY: ps
ps: ## Show service status
$(DC) ps
# ------------------------------------------------------------------------ logs
.PHONY: logs
logs: ## Tail logs (use SVC=name to scope to one service)
ifdef SVC
$(DC) logs -f $(SVC)
else
$(DC) logs -f
endif
# -------------------------------------------------------------------- shells
.PHONY: sh
sh: ## Bash inside the app container
$(DC) exec app bash
.PHONY: web-sh
web-sh: ## Shell inside the nginx container
$(DC) exec web sh
.PHONY: db-sh
db-sh: ## MariaDB CLI
$(DC) exec mariadb mariadb -uezscale -pezscale_local ezscale_billing
.PHONY: redis-sh
redis-sh: ## Valkey CLI
$(DC) exec valkey valkey-cli
# ----------------------------------------------------------- artisan / composer
.PHONY: artisan
artisan: ## Run an artisan command (use ARGS="migrate")
$(EXEC) php artisan $(ARGS)
.PHONY: composer
composer: ## Run composer (use ARGS="require ...")
$(EXEC) composer $(ARGS)
.PHONY: tinker
tinker: ## Open a tinker shell
$(DC) exec app php artisan tinker
# ---------------------------------------------------------------------- frontend
.PHONY: npm
npm: ## Run npm in the vite container (use ARGS="install ...")
$(DC) exec vite npm $(ARGS)
.PHONY: vite-build
vite-build: ## One-off production build
$(DC) run --rm vite npm run build
# ----------------------------------------------------------------------- testing
.PHONY: test
test: ## Run the Pest suite
$(EXEC) php artisan test --compact $(ARGS)
.PHONY: pint
pint: ## Format dirty PHP files
$(EXEC) vendor/bin/pint --dirty --format agent
# -------------------------------------------------------------- DB convenience
.PHONY: migrate
migrate: ## Run pending migrations
$(EXEC) php artisan migrate
.PHONY: fresh
fresh: ## Drop all tables, re-migrate, seed
$(EXEC) php artisan migrate:fresh --seed
.PHONY: seed
seed: ## Run seeders
$(EXEC) php artisan db:seed
# --------------------------------------------------------------- diagnostics
.PHONY: doctor
doctor: ## Print key compose info for debugging
$(DC) config --services
@echo ""
$(DC) ps
@echo ""
$(DC) exec app php -v 2>/dev/null || echo "app not running"