-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
145 lines (130 loc) · 5.87 KB
/
Makefile
File metadata and controls
145 lines (130 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
APP_PORT ?= $(shell grep -E '^APP_PORT=' .env 2>/dev/null | cut -d= -f2 || echo 8080)
APP_URL ?= $(shell grep -E '^APP_URL=' .env 2>/dev/null | head -n1 | cut -d= -f2- | tr -d '\r' | sed -e "s/^['\"]//" -e "s/['\"]$$//" -e "s|/*$$||" -e "s|:[0-9][0-9]*$$||")
NGROK_URL ?= $(shell grep -E '^NGROK_URL=' .env 2>/dev/null | cut -d= -f2 || echo "")
NGROK_AUTHTOKEN ?= $(shell grep -E '^NGROK_AUTHTOKEN=' .env 2>/dev/null | cut -d= -f2 || echo "")
APPMAX_CLIENT_ID ?= $(shell grep -E '^APPMAX_CLIENT_ID=' .env 2>/dev/null | cut -d= -f2 || echo "")
APPMAX_CLIENT_SECRET ?= $(shell grep -E '^APPMAX_CLIENT_SECRET=' .env 2>/dev/null | cut -d= -f2 || echo "")
APPMAX_APP_ID_UUID ?= $(shell grep -E '^APPMAX_APP_ID_UUID=' .env 2>/dev/null | cut -d= -f2 || echo "")
APPMAX_APP_ID_NUMERIC ?= $(shell grep -E '^APPMAX_APP_ID_NUMERIC=' .env 2>/dev/null | cut -d= -f2 || echo "")
BASE_URL = $(APP_URL):$(APP_PORT)
HEALTH_URL = $(BASE_URL)/health
COMPOSE = docker compose -f docker-compose.yml
.PHONY: install teardown env-init generate-key up down restart logs health validate rename-module test migrate
install: env-init generate-key teardown up migrate test validate
@echo "Stack is ready."
env-init:
@if [ ! -f .env ]; then \
cp .env.example .env; \
echo "Created .env from .env.example"; \
fi
generate-key:
@key_val=$$(grep -E '^APP_KEY=' .env 2>/dev/null | cut -d= -f2 | tr -d '[:space:]'); \
if [ -z "$$key_val" ] || [ $${#key_val} -ne 32 ]; then \
new_key=$$(LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 32); \
sed -i.bak "s|^APP_KEY=.*|APP_KEY=$$new_key|" .env && rm -f .env.bak; \
echo "Generated APP_KEY"; \
else \
echo "APP_KEY already set — skipping"; \
fi
teardown:
@echo "Removing containers and volumes..."
$(COMPOSE) down -v --remove-orphans
up:
$(COMPOSE) up -d --build
down:
$(COMPOSE) down -v --remove-orphans
restart:
$(COMPOSE) restart
logs:
$(COMPOSE) logs -f
health:
@sleep 5
@for i in $$(seq 1 60); do \
if curl -sf $(HEALTH_URL) > /dev/null 2>&1; then \
exit 0; \
fi; \
sleep 3; \
done; \
echo "Healthcheck failed after 60 attempts: $(HEALTH_URL)"; exit 1
validate: health
@echo "Validating endpoints..."
@if [ -z "$(NGROK_AUTHTOKEN)" ]; then \
echo " [FAIL] NGROK_AUTHTOKEN is empty."; \
echo " Create a ngrok account at https://dashboard.ngrok.com/signup and set NGROK_AUTHTOKEN in .env"; \
exit 1; \
fi
@if [ -z "$(APPMAX_CLIENT_ID)" ]; then \
echo " [WARN] APPMAX_CLIENT_ID is empty."; \
fi
@if [ -z "$(APPMAX_CLIENT_SECRET)" ]; then \
echo " [WARN] APPMAX_CLIENT_SECRET is empty."; \
fi
@if [ -z "$(APPMAX_APP_ID_UUID)" ]; then \
echo " [WARN] APPMAX_APP_ID_UUID is empty."; \
fi
@if [ -z "$(APPMAX_APP_ID_NUMERIC)" ]; then \
echo " [WARN] APPMAX_APP_ID_NUMERIC is empty."; \
fi
@if [ -z "$(APPMAX_CLIENT_ID)" ] || [ -z "$(APPMAX_CLIENT_SECRET)" ] || [ -z "$(APPMAX_APP_ID_UUID)" ] || [ -z "$(APPMAX_APP_ID_NUMERIC)" ]; then \
echo " Appmax integration endpoints stay reachable, but install/auth flows remain partially unconfigured until these values are set in .env."; \
fi
@status=$$(curl -o /dev/null -sw '%{http_code}' $(BASE_URL)/install/start 2>/dev/null); \
if [ "$$status" -ge 500 ] || [ "$$status" -eq 000 ]; then \
echo " [FAIL] GET /install/start (HTTP $$status)"; exit 1; \
fi
@active_url=""; \
ngrok_url="$(NGROK_URL)"; \
configured_reachable=0; \
if [ -n "$$ngrok_url" ]; then \
case "$$ngrok_url" in http://*|https://*) ;; *) ngrok_url="https://$$ngrok_url" ;; esac; \
for i in $$(seq 1 20); do \
if curl -sf $$ngrok_url/health > /dev/null 2>&1; then \
configured_reachable=1; break; \
fi; \
sleep 2; \
done; \
fi; \
for i in $$(seq 1 40); do \
active_url=$$($(COMPOSE) exec -T ngrok sh -lc "wget -qO- http://127.0.0.1:4040/api/tunnels 2>/dev/null" 2>/dev/null | grep -o '"public_url":"[^"]*"' | head -1 | cut -d'"' -f4); \
if [ -n "$$active_url" ]; then \
break; \
fi; \
sleep 2; \
done; \
if [ -z "$$active_url" ]; then \
echo " [FAIL] ngrok active tunnel URL not found in ngrok API"; exit 1; \
fi; \
front_status=$$(curl -o /dev/null -sw '%{http_code}' $$active_url/ 2>/dev/null); \
if [ "$$front_status" -eq 000 ]; then \
echo " [FAIL] Frontend URL not reachable: $$active_url/"; exit 1; \
fi; \
health_status=$$(curl -o /dev/null -sw '%{http_code}' $$active_url/health 2>/dev/null); \
if [ "$$health_status" -eq 000 ]; then \
echo " [FAIL] Health URL not reachable: $$active_url/health"; exit 1; \
fi; \
install_status=$$(curl -o /dev/null -sw '%{http_code}' $$active_url/install/start -H 'Accept: text/html' 2>/dev/null); \
if [ "$$install_status" -eq 000 ]; then \
echo " [FAIL] Install URL not reachable: $$active_url/install/start"; exit 1; \
fi; \
callback_status=$$(curl -o /dev/null -sw '%{http_code}' $$active_url/integrations/appmax/callback/install 2>/dev/null); \
if [ "$$callback_status" -eq 000 ]; then \
echo " [FAIL] Callback URL not reachable: $$active_url/integrations/appmax/callback/install"; exit 1; \
fi; \
webhook_status=$$(curl -o /dev/null -sw '%{http_code}' $$active_url/webhooks/appmax -H 'Accept: text/html' 2>/dev/null); \
if [ "$$webhook_status" -eq 000 ]; then \
echo " [FAIL] Webhook URL not reachable: $$active_url/webhooks/appmax"; exit 1; \
fi; \
if [ "$$configured_reachable" -ne 0 ] && [ -n "$$ngrok_url" ] && [ "$$active_url" = "$$ngrok_url" ]; then :; fi; \
echo " Frontend URL: $$active_url/"; \
echo " Health URL: $$active_url/health"; \
echo " Install URL: $$active_url/install/start"; \
echo " Callback URL: $$active_url/integrations/appmax/callback/install"; \
echo " Webhook URL: $$active_url/webhooks/appmax"
@echo "All validations passed."
rename-module:
@bash scripts/rename-module.sh $(NEW)
test:
@echo "Running tests inside app container..."
$(COMPOSE) exec -T app sh -lc 'PATH=/usr/local/go/bin:/go/bin:$$PATH GOCACHE=/tmp/.gocache go test ./...'
migrate:
$(COMPOSE) exec app ./tmp/server artisan migrate