# Makefile for Medication Reminder App # Consolidated version with grouped targets and reduced redundancy .PHONY: help install clean dev build test lint docker k8s # Default target .DEFAULT_GOAL := help # Colors for output BLUE := \033[34m GREEN := \033[32m YELLOW := \033[33m RED := \033[31m RESET := \033[0m ##@ General help: ## Display this help message @printf "$(BLUE)Medication Reminder App - Available Commands$(RESET)\n" @printf "\n" @awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " $(GREEN)%-20s$(RESET) %s\n", $$1, $$2 } /^##@/ { printf "\n$(YELLOW)%s$(RESET)\n", substr($$0, 5) } ' $(MAKEFILE_LIST) install: ## Install dependencies @printf "$(BLUE)Installing dependencies...$(RESET)\n" @bun install clean: ## Clean build artifacts and dependencies @printf "$(BLUE)Cleaning up...$(RESET)\n" @rm -rf node_modules dist build .cache reset: clean install ## Reset project (clean and reinstall) @printf "$(GREEN)Project reset completed!$(RESET)\n" ##@ Development dev: ## Start development server @printf "$(BLUE)Starting development server...$(RESET)\n" @bun run dev build: ## Build the application for development @printf "$(BLUE)Building application for development...$(RESET)\n" @NODE_ENV=development bun run build build-prod: ## Build the application for production @printf "$(BLUE)Building application for production...$(RESET)\n" @bun run build preview: ## Preview the built application @printf "$(BLUE)Starting preview server...$(RESET)\n" @bun run preview setup: ## Setup the project @printf "$(BLUE)Setting up project...$(RESET)\n" @bun run setup ##@ Testing & Quality test: ## Run unit tests @printf "$(BLUE)Running unit tests...$(RESET)\n" @bun run test test-watch: ## Run unit tests in watch mode @printf "$(BLUE)Running tests in watch mode...$(RESET)\n" @bun run test:watch test-coverage: ## Run tests with coverage @printf "$(BLUE)Running tests with coverage...$(RESET)\n" @bun run test:coverage test-integration: ## Run integration tests @printf "$(BLUE)Running integration tests...$(RESET)\n" @bun run test:integration test-e2e: ## Run end-to-end tests @printf "$(BLUE)Running e2e tests...$(RESET)\n" @bun run test:e2e test-e2e-ui: ## Run e2e tests with interactive UI @printf "$(BLUE)Running e2e tests with UI...$(RESET)\n" @bun run test:e2e:ui test-auth-debug: ## Run authentication debug tests @printf "$(BLUE)Running authentication debug tests...$(RESET)\n" @bunx playwright test --config=tests/e2e/playwright.auth.config.ts test-auth-debug-ui: ## Run authentication debug tests with UI @printf "$(BLUE)Running authentication debug tests with UI...$(RESET)\n" @bunx playwright test --config=tests/e2e/playwright.auth.config.ts --ui test-all: ## Run all tests (unit + integration + e2e) @printf "$(BLUE)Running all tests...$(RESET)\n" @bun run test:all lint: ## Run linting and fix issues @printf "$(BLUE)Running linting checks...$(RESET)\n" @bun run lint @bun run lint:fix 2>/dev/null || true pre-commit: ## Run pre-commit checks @printf "$(BLUE)Running pre-commit checks...$(RESET)\n" @bun run pre-commit check: lint test-all ## Run complete quality check (lint + all tests) @printf "$(GREEN)Quality check completed!$(RESET)\n" ##@ Docker docker-build: ## Build Docker images (local and multi-platform) @printf "$(BLUE)Building Docker images...$(RESET)\n" @bun run docker:build-local @bun run docker:build 2>/dev/null || true docker-build-local: ## Build Docker image for local platform only @printf "$(BLUE)Building local Docker image...$(RESET)\n" @./scripts/buildx-helper.sh build-local docker-build-multi: ## Build multi-platform Docker images @printf "$(BLUE)Building multi-platform Docker images...$(RESET)\n" @./scripts/buildx-helper.sh build-multi docker-build-multi-dev: ## Build multi-platform Docker images for development @printf "$(BLUE)Building multi-platform Docker images for development...$(RESET)\n" @./scripts/buildx-helper.sh build-multi-dev docker-build-push: ## Build and push multi-platform Docker images @printf "$(BLUE)Building and pushing multi-platform Docker images...$(RESET)\n" @./scripts/buildx-helper.sh build-push docker-buildx-create: ## Create and use a new buildx builder instance @printf "$(BLUE)Creating new buildx builder instance...$(RESET)\n" @docker buildx create --name meds-builder --use --bootstrap @printf "$(GREEN)Buildx builder 'meds-builder' created and activated$(RESET)\n" docker-buildx-build: ## Build multi-platform image using buildx @printf "$(BLUE)Building multi-platform image with buildx...$(RESET)\n" @docker buildx build --platform linux/amd64,linux/arm64 \ --build-arg JWT_SECRET=$$(openssl rand -base64 32) \ --build-arg SESSION_SECRET=$$(openssl rand -base64 32) \ --build-arg NODE_ENV=production \ --build-arg APP_NAME=$$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.app.name)") \ --build-arg APP_BASE_URL=$$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.app.baseUrl)") \ -t $$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.container.imageUrl)") . docker-buildx-build-push: ## Build and push multi-platform image using buildx @printf "$(BLUE)Building and pushing multi-platform image with buildx...$(RESET)\n" @docker buildx build --platform linux/amd64,linux/arm64 \ --build-arg JWT_SECRET=$$(openssl rand -base64 32) \ --build-arg SESSION_SECRET=$$(openssl rand -base64 32) \ --build-arg NODE_ENV=production \ --build-arg APP_NAME=$$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.app.name)") \ --build-arg APP_BASE_URL=$$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.app.baseUrl)") \ -t $$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.container.imageUrl)") --push . docker-buildx-build-load: ## Build multi-platform image and load to local Docker @printf "$(BLUE)Building multi-platform image and loading to local Docker...$(RESET)\n" @docker buildx build --platform linux/amd64 \ --build-arg JWT_SECRET=$$(openssl rand -base64 32) \ --build-arg SESSION_SECRET=$$(openssl rand -base64 32) \ --build-arg NODE_ENV=production \ --build-arg APP_NAME=$$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.app.name)") \ --build-arg APP_BASE_URL=$$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.app.baseUrl)") \ -t $$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.container.imageUrl)") --load . docker-buildx-inspect: ## Inspect current buildx builder @printf "$(BLUE)Inspecting current buildx builder...$(RESET)\n" @docker buildx inspect docker-buildx-ls: ## List all buildx builder instances @printf "$(BLUE)Listing all buildx builder instances...$(RESET)\n" @docker buildx ls docker-buildx-build-dev: ## Build development image using buildx @printf "$(BLUE)Building development image with buildx...$(RESET)\n" @docker buildx build --platform linux/amd64 \ --build-arg JWT_SECRET=dev-jwt-secret-key-not-for-production \ --build-arg SESSION_SECRET=dev-session-secret-key-not-for-production \ --build-arg NODE_ENV=development \ --build-arg DEBUG_MODE=true \ --build-arg APP_NAME=$$(NODE_ENV=development bun -e "import {createUnifiedConfigForEnvironment} from './config/unified.config.ts'; console.log(createUnifiedConfigForEnvironment('development').app.name)") \ --build-arg APP_BASE_URL=$$(NODE_ENV=development bun -e "import {createUnifiedConfigForEnvironment} from './config/unified.config.ts'; console.log(createUnifiedConfigForEnvironment('development').app.baseUrl)") \ -t $$(NODE_ENV=development bun -e "import {createUnifiedConfigForEnvironment} from './config/unified.config.ts'; const config = createUnifiedConfigForEnvironment('development'); console.log(config.container.registry + '/' + config.container.repository + ':dev')") --load . docker-buildx-build-with-registry: ## Build and push to specific registry (requires REGISTRY variable) @printf "$(BLUE)Building and pushing to custom registry...$(RESET)\n" @if [ -z "$(REGISTRY)" ]; then \ printf "$(RED)Error: REGISTRY variable not set. Use: make docker-buildx-build-with-registry REGISTRY=your-registry.com$(RESET)\n"; \ exit 1; \ fi @docker buildx build --platform linux/amd64,linux/arm64 \ --build-arg JWT_SECRET=$$(openssl rand -base64 32) \ --build-arg SESSION_SECRET=$$(openssl rand -base64 32) \ --build-arg NODE_ENV=production \ --build-arg APP_NAME=$$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.app.name)") \ --build-arg APP_BASE_URL=$$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.app.baseUrl)") \ -t $(REGISTRY)/$$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.container.repository)"):$$(bun -e "import {unifiedConfig} from './config/unified.config.ts'; console.log(unifiedConfig.container.tag)") --push . docker-buildx-rm: ## Remove the meds-builder buildx instance @printf "$(BLUE)Removing meds-builder buildx instance...$(RESET)\n" @docker buildx rm meds-builder || true @printf "$(GREEN)Buildx builder 'meds-builder' removed$(RESET)\n" docker-push: ## Push existing Docker images to registry @printf "$(BLUE)Pushing Docker images to registry...$(RESET)\n" @./scripts/buildx-helper.sh push docker-setup: ## Setup Docker buildx builder instance @printf "$(BLUE)Setting up Docker buildx builder...$(RESET)\n" @./scripts/buildx-helper.sh setup docker-inspect: ## Inspect Docker buildx builder @printf "$(BLUE)Inspecting Docker buildx builder...$(RESET)\n" @./scripts/buildx-helper.sh inspect docker-bake: ## Build using docker-bake.hcl @printf "$(BLUE)Building using docker-bake.hcl...$(RESET)\n" @./scripts/buildx-helper.sh bake docker-list: ## List available Docker buildx builders @printf "$(BLUE)Listing Docker buildx builders...$(RESET)\n" @./scripts/buildx-helper.sh list docker-down: ## Stop and remove Docker containers @printf "$(BLUE)Stopping Docker containers...$(RESET)\n" @if docker-compose -f docker/docker-compose.yaml ps --services 2>/dev/null | grep -q .; then \ docker-compose -f docker/docker-compose.yaml down; \ printf "$(GREEN)Docker containers stopped$(RESET)\n"; \ else \ printf "$(YELLOW)No containers running$(RESET)\n"; \ fi docker-clean: docker-down ## Stop containers and clean up volumes/images @printf "$(BLUE)Cleaning Docker resources...$(RESET)\n" @docker-compose -f docker/docker-compose.yaml down --volumes --remove-orphans 2>/dev/null || true @docker image prune -f --filter "until=24h" 2>/dev/null || true @docker volume prune -f 2>/dev/null || true docker-cleanup: ## Remove buildx builder and cleanup @printf "$(BLUE)Cleaning up Docker buildx resources...$(RESET)\n" @./scripts/buildx-helper.sh cleanup ##@ Kubernetes Deployment deploy-dev: ## Deploy to development environment @printf "$(BLUE)Deploying to development...$(RESET)\n" @kubectl apply -k k8s-kustomize/overlays/dev deploy-prod: ## Deploy to production environment @printf "$(BLUE)Deploying to production...$(RESET)\n" @kubectl apply -k k8s-kustomize/overlays/prod undeploy-dev: ## Remove development deployment @printf "$(BLUE)Removing development deployment...$(RESET)\n" @kubectl delete -k k8s-kustomize/overlays/dev --ignore-not-found=true undeploy-prod: ## Remove production deployment @printf "$(BLUE)Removing production deployment...$(RESET)\n" @kubectl delete -k k8s-kustomize/overlays/prod --ignore-not-found=true status-dev: ## Show development deployment status @printf "$(BLUE)Development status...$(RESET)\n" @kubectl get all -n rxminder-dev -l app=rxminder 2>/dev/null || printf "$(YELLOW)No development deployment found$(RESET)\n" status-prod: ## Show production deployment status @printf "$(BLUE)Production status...$(RESET)\n" @kubectl get all -n rxminder-prod -l app=rxminder 2>/dev/null || printf "$(YELLOW)No production deployment found$(RESET)\n" diff-dev: ## Show changes for development deployment @printf "$(BLUE)Development diff...$(RESET)\n" @kubectl diff -k k8s-kustomize/overlays/dev 2>/dev/null || true diff-prod: ## Show changes for production deployment @printf "$(BLUE)Production diff...$(RESET)\n" @kubectl diff -k k8s-kustomize/overlays/prod 2>/dev/null || true validate-k8s: ## Validate Kubernetes configurations @printf "$(BLUE)Validating Kubernetes configs...$(RESET)\n" @kubectl kustomize k8s-kustomize/overlays/dev | kubectl apply --dry-run=client --validate=true -f - >/dev/null @kubectl kustomize k8s-kustomize/overlays/prod | kubectl apply --dry-run=client --validate=true -f - >/dev/null @printf "$(GREEN)Kubernetes validation passed!$(RESET)\n" ##@ Configuration generate-config: ## Generate configuration for all environments using unified config @printf "$(BLUE)Generating unified configurations...$(RESET)\n" @bun scripts/generate-unified-config.ts --all @printf "$(GREEN)Unified configurations generated!$(RESET)\n" generate-config-dev: ## Generate configuration for development environment @printf "$(BLUE)Generating development configuration...$(RESET)\n" @bun scripts/generate-unified-config.ts development @printf "$(GREEN)Development configuration generated!$(RESET)\n" generate-config-staging: ## Generate configuration for staging environment @printf "$(BLUE)Generating staging configuration...$(RESET)\n" @bun scripts/generate-unified-config.ts staging @printf "$(GREEN)Staging configuration generated!$(RESET)\n" generate-config-prod: ## Generate configuration for production environment @printf "$(BLUE)Generating production configuration...$(RESET)\n" @bun scripts/generate-unified-config.ts production @printf "$(GREEN)Production configuration generated!$(RESET)\n" validate-config: ## Validate unified configuration @printf "$(BLUE)Validating unified configuration...$(RESET)\n" @bun scripts/generate-unified-config.ts --dry-run @printf "$(GREEN)Configuration validation completed!$(RESET)\n" config-debug: ## Show current unified configuration (debug mode) @printf "$(BLUE)Current unified configuration:$(RESET)\n" @DEBUG_MODE=true bun -e "import { logConfig } from './config/unified.config.ts'; logConfig();" config-check: ## Check configuration system health and show sources @printf "$(BLUE)Configuration System Health Check:$(RESET)\n" @printf "\n$(YELLOW)1. Environment Variables (.env file):$(RESET)\n" @grep -v '^#' .env 2>/dev/null | head -10 || printf "$(YELLOW) No .env file found$(RESET)\n" @printf "\n$(YELLOW)2. Unified Config Status:$(RESET)\n" @bun -e "import { unifiedConfig, exportAsEnvVars } from './config/unified.config.ts'; console.log('✅ Unified config loaded successfully'); console.log('Environment:', unifiedConfig.app.environment); console.log('App Name:', unifiedConfig.app.name); console.log('Base URL:', unifiedConfig.app.baseUrl); console.log('Container Image:', unifiedConfig.container.imageUrl);" @printf "\n$(YELLOW)3. Generated Config Files:$(RESET)\n" @ls -la config/generated/ 2>/dev/null | grep -v '^total' || printf "$(YELLOW) No generated configs found$(RESET)\n" @printf "\n$(GREEN)Configuration system is working!$(RESET)\n" config-export: ## Export current config as environment variables @printf "$(BLUE)Exporting unified configuration as environment variables:$(RESET)\n" @bun -e "import { exportAsEnvVars } from './config/unified.config.ts'; const vars = exportAsEnvVars(); Object.entries(vars).forEach(([key, value]) => console.log(\`\${key}=\${value}\`));" ##@ Workflows start: dev ## Alias for dev (start development server) build-test: build test ## Build and run unit tests @printf "$(GREEN)Build and test completed!$(RESET)\n" deploy-dev-quick: build deploy-dev ## Build and deploy to development @printf "$(GREEN)Quick development deployment completed!$(RESET)\n" deploy-prod-quick: ## Build and deploy to production with generated secrets @printf "$(BLUE)Generating secure production secrets and deploying...$(RESET)\n" @JWT_SECRET=$$(openssl rand -base64 32) SESSION_SECRET=$$(openssl rand -base64 32) $(MAKE) build-prod @$(MAKE) deploy-prod @printf "$(GREEN)Production deployment completed with generated secrets!$(RESET)\n" deploy-prod-configured: build-prod deploy-prod ## Build and deploy to production (requires pre-configured secrets) @printf "$(GREEN)Production deployment completed with configured secrets!$(RESET)\n" deploy-demo: build ## Build and deploy demo version with development settings @printf "$(BLUE)Deploying demo version for testing...$(RESET)\n" @NODE_ENV=development docker-compose -f docker/docker-compose.yaml up -d --build 2>/dev/null || printf "$(YELLOW)Docker deployment failed, trying development K8s...$(RESET)\n" @printf "$(GREEN)Demo deployment completed! Access at http://localhost:8080$(RESET)\n" deploy-local: build ## Build and deploy locally using Docker @printf "$(BLUE)Starting local deployment with Docker...$(RESET)\n" @docker-compose -f docker/docker-compose.yaml down 2>/dev/null || true @NODE_ENV=development docker-compose -f docker/docker-compose.yaml up -d --build @printf "$(GREEN)Local deployment completed! Access at http://localhost:8080$(RESET)\n" @printf "$(BLUE)To stop: make docker-down$(RESET)\n" undeploy-all: undeploy-dev undeploy-prod docker-clean ## Remove all deployments and clean Docker @printf "$(GREEN)Complete cleanup completed!$(RESET)\n" stop-local: docker-down ## Stop local Docker deployment @printf "$(GREEN)Local deployment stopped!$(RESET)\n" ci-check: check validate-k8s ## Complete CI/CD validation pipeline @printf "$(GREEN)CI/CD checks passed!$(RESET)\n"