|
| 1 | +.PHONY: start stop restart status smoke clean help |
| 2 | + |
| 3 | +.DEFAULT_GOAL := help |
| 4 | + |
| 5 | +PROJECT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) |
| 6 | +PID_DIR := tmp/pids |
| 7 | +PID_FILE := $(PID_DIR)/everydocs.pid |
| 8 | +LOG_DIR := log |
| 9 | + |
| 10 | +help: |
| 11 | + @echo "EveryDocs Core - Make Commands" |
| 12 | + @echo "==============================================" |
| 13 | + @echo "" |
| 14 | + @echo "Commands:" |
| 15 | + @echo " start - Start the EveryDocs server" |
| 16 | + @echo " stop - Stop the EveryDocs server" |
| 17 | + @echo " restart - Restart the EveryDocs server" |
| 18 | + @echo " status - Check server status" |
| 19 | + @echo " smoke - Run non-interactive smoke test (for CI)" |
| 20 | + @echo " test - Run Rails tests" |
| 21 | + @echo " logs - Tail the server logs" |
| 22 | + @echo " clean-logs - Clean log files" |
| 23 | + @echo " help - Show this help message" |
| 24 | + @echo "" |
| 25 | + @echo "Environment Variables (can be set in .env file):" |
| 26 | + @echo " RAILS_ENV - Rails environment (default: production)" |
| 27 | + @echo " PORT - Server port (default: 5678)" |
| 28 | + @echo " SECRET_KEY_BASE - Rails secret key (required)" |
| 29 | + @echo " MYSQL_PASSWORD - Database password (required)" |
| 30 | + @echo "" |
| 31 | + @echo "Examples:" |
| 32 | + @echo " make start" |
| 33 | + @echo " make stop" |
| 34 | + @echo " make restart" |
| 35 | + @echo " make smoke" |
| 36 | + @echo "" |
| 37 | + |
| 38 | +start: |
| 39 | + @echo "Starting EveryDocs Core..." |
| 40 | + @cd $(PROJECT_DIR) && ./start-app.sh |
| 41 | + |
| 42 | +stop: |
| 43 | + @echo "Stopping EveryDocs Core..." |
| 44 | + @cd $(PROJECT_DIR) && ./stop-app.sh |
| 45 | + |
| 46 | +restart: stop start |
| 47 | + |
| 48 | +status: |
| 49 | + @cd $(PROJECT_DIR) && ./status.sh |
| 50 | + |
| 51 | +logs: |
| 52 | + @echo "Tailing logs (Ctrl+C to exit)..." |
| 53 | + @tail -f $(LOG_DIR)/everydocs.log $(LOG_DIR)/everydocs.error.log 2>/dev/null || echo "Log files not found yet" |
| 54 | + |
| 55 | +logs-error: |
| 56 | + @echo "Tailing error logs (Ctrl+C to exit)..." |
| 57 | + @tail -f $(LOG_DIR)/everydocs.error.log 2>/dev/null || echo "Error log file not found yet" |
| 58 | + |
| 59 | +clean-logs: |
| 60 | + @echo "Cleaning log files..." |
| 61 | + @rm -f $(LOG_DIR)/everydocs.log $(LOG_DIR)/everydocs.error.log |
| 62 | + @echo "Log files cleaned" |
| 63 | + |
| 64 | +test: |
| 65 | + @echo "Running Rails tests..." |
| 66 | + @cd $(PROJECT_DIR) && rails test RAILS_ENV=test |
| 67 | + |
| 68 | +test-controllers: |
| 69 | + @echo "Running controller tests..." |
| 70 | + @cd $(PROJECT_DIR) && rails test test/controllers/ RAILS_ENV=test |
| 71 | + |
| 72 | +db-migrate: |
| 73 | + @echo "Running database migrations..." |
| 74 | + @cd $(PROJECT_DIR) && rails db:migrate |
| 75 | + |
| 76 | +db-migrate-test: |
| 77 | + @echo "Running database migrations (test env)..." |
| 78 | + @cd $(PROJECT_DIR) && rails db:migrate RAILS_ENV=test |
| 79 | + |
| 80 | +smoke: |
| 81 | + @echo "==============================================" |
| 82 | + @echo "EveryDocs Core - Non-Interactive Smoke Test" |
| 83 | + @echo "==============================================" |
| 84 | + @echo "" |
| 85 | + @echo "Phase 1: Checking prerequisites..." |
| 86 | + @cd $(PROJECT_DIR) && if [ ! -f .env ]; then \ |
| 87 | + echo " ERROR: .env file not found"; \ |
| 88 | + echo " Create one from .env.example: cp .env.example .env"; \ |
| 89 | + exit 1; \ |
| 90 | + else \ |
| 91 | + echo " ✓ .env file exists"; \ |
| 92 | + fi |
| 93 | + @cd $(PROJECT_DIR) && if grep -q "your_secret_key_base_here" .env 2>/dev/null; then \ |
| 94 | + echo " ERROR: SECRET_KEY_BASE not set in .env"; \ |
| 95 | + echo " Generate one with: openssl rand -hex 64"; \ |
| 96 | + exit 1; \ |
| 97 | + else \ |
| 98 | + echo " ✓ SECRET_KEY_BASE appears to be set"; \ |
| 99 | + fi |
| 100 | + @echo "" |
| 101 | + |
| 102 | + @echo "Phase 2: Checking required commands..." |
| 103 | + @which ruby >/dev/null 2>&1 && echo " ✓ ruby" || (echo " ✗ ruby (required)" && exit 1) |
| 104 | + @which bundle >/dev/null 2>&1 && echo " ✓ bundle" || (echo " ✗ bundle (required)" && exit 1) |
| 105 | + @which rails >/dev/null 2>&1 && echo " ✓ rails" || (echo " ✗ rails (required)" && exit 1) |
| 106 | + @echo "" |
| 107 | + |
| 108 | + @echo "Phase 3: Checking bundle dependencies..." |
| 109 | + @cd $(PROJECT_DIR) && bundle check 2>/dev/null && echo " ✓ Dependencies satisfied" || (echo " ✗ Dependencies missing. Run: bundle install" && exit 1) |
| 110 | + @echo "" |
| 111 | + |
| 112 | + @echo "Phase 4: Checking test setup..." |
| 113 | + @cd $(PROJECT_DIR) && rails db:migrate RAILS_ENV=test 2>&1 | tail -1 |
| 114 | + @echo "" |
| 115 | + |
| 116 | + @echo "Phase 5: Running basic tests..." |
| 117 | + @cd $(PROJECT_DIR) && rails test RAILS_ENV=test 2>&1 |
| 118 | + @echo "" |
| 119 | + |
| 120 | + @echo "==============================================" |
| 121 | + @echo "Smoke Test Completed" |
| 122 | + @echo "==============================================" |
0 commit comments