-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
258 lines (207 loc) · 9.54 KB
/
Copy pathMakefile
File metadata and controls
258 lines (207 loc) · 9.54 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# =============================================================================
# Boost Data Collector – Developer Makefile
# Wraps docker compose + common Django management commands.
#
# Usage: make <target>
# make help → list all targets
# =============================================================================
SHELL := /bin/bash
COMPOSE := docker compose
APP := web
BEAT := celery_beat
MANAGE := $(COMPOSE) run --rm $(APP) python manage.py
.DEFAULT_GOAL := help
# ── Help ─────────────────────────────────────────────────────────────────────
.PHONY: help
help:
@echo ""
@echo "Usage: make <target>"
@echo ""
@echo " Stack"
@echo " build Build (or rebuild) all images"
@echo " up Clean macOS files, then start all services (detached)"
@echo " down Stop and remove containers (volumes kept)"
@echo " stop Pause all containers (fast restart)"
@echo " start Resume paused containers"
@echo " restart Stop then start all containers"
@echo " reset !! Remove containers AND volumes (wipes DB + data)"
@echo ""
@echo " Logs & status"
@echo " ps Show running containers"
@echo " health Verify DB, Redis, Celery Beat schedule, and containers"
@echo " notify Send Slack/Discord startup notification (celery_beat; optional DEPLOY_BRANCH)"
@echo " logs Follow logs for all services"
@echo " logs-web Follow logs for the web service"
@echo " logs-worker Follow logs for the Celery worker"
@echo " logs-beat Follow logs for the Celery beat"
@echo ""
@echo " Django"
@echo " migrate Apply database migrations"
@echo " makemigrations Create new migration files"
@echo " superuser Create a Django superuser"
@echo " shell Open Django shell inside the web container"
@echo " bash Open a bash shell inside the web container"
@echo " collectstatic Collect static files"
@echo ""
@echo " Testing (runs locally, not inside Docker)"
@echo " test Run full pytest suite"
@echo " test-fast Run tests, stop on first failure"
@echo " test-cov Run tests with coverage report"
@echo ""
@echo " Slack session (xoxc/xoxd token extraction)"
@echo " slack-login Start slack-chromium (noVNC http://127.0.0.1:7900)"
@echo " slack-wait-profile Wait until Slack login wrote Cookies + LevelDB"
@echo " slack-login-stop Stop slack-chromium before extract"
@echo " extract-slack-tokens Extract tokens to workspace JSON (one-shot)"
@echo " slack-tokens-reextract Stop chromium → extract JSON"
@echo " slack-tokens-refresh Login (noVNC) → wait → extract JSON"
@echo ""
@echo " Discord session (user token extraction)"
@echo " discord-login Start discord-chromium (noVNC http://127.0.0.1:7901)"
@echo " discord-wait-profile Wait until Discord login wrote Cookies + LevelDB"
@echo " discord-login-stop Stop discord-chromium before extract"
@echo " extract-discord-tokens Extract token to workspace JSON (one-shot)"
@echo " discord-tokens-reextract Stop chromium → extract JSON"
@echo " discord-tokens-refresh Login (noVNC) → wait → extract JSON"
@echo ""
@echo " Utilities"
@echo " clean-mac Remove macOS ._* resource-fork files"
@echo " clean-pyc Remove compiled Python files"
@echo " clean Run clean-mac + clean-pyc"
@echo ""
# ── Stack ─────────────────────────────────────────────────────────────────────
.PHONY: build
build: clean-mac
$(COMPOSE) build
.PHONY: up
up: clean-mac
$(COMPOSE) up -d
.PHONY: down
down:
$(COMPOSE) down
.PHONY: stop
stop:
$(COMPOSE) stop
.PHONY: start
start:
$(COMPOSE) start
.PHONY: restart
restart: stop start
.PHONY: reset
reset:
@echo "WARNING: This will delete all containers AND volumes (database, workspace, logs)."
@read -r -p "Type 'yes' to confirm: " confirm && [ "$$confirm" = "yes" ] || (echo "Aborted."; exit 1)
$(COMPOSE) down -v
# ── Logs & status ─────────────────────────────────────────────────────────────
.PHONY: ps
ps:
$(COMPOSE) ps
.PHONY: health
# HEALTH_CHECK_TOKEN comes from the web container env (env_file: .env). When set, /health/ requires Bearer auth.
health:
$(COMPOSE) exec -T $(APP) sh -c '\
if [ -n "$${HEALTH_CHECK_TOKEN:-}" ]; then \
curl -fsS -H "Authorization: Bearer $${HEALTH_CHECK_TOKEN}" http://127.0.0.1:8000/health/; \
else \
curl -fsS http://127.0.0.1:8000/health/; \
fi | python -c "import sys,json; d=json.load(sys.stdin); print(d.get(\"status\")); sys.exit(0 if d.get(\"status\")==\"healthy\" else 1)"'
$(COMPOSE) exec -T redis redis-cli ping | grep -q PONG
$(COMPOSE) ps --status running celery_worker | grep -q celery_worker
$(COMPOSE) ps --status running celery_beat | grep -q celery_beat
.PHONY: notify
notify:
$(COMPOSE) exec -T -e DEPLOY_BRANCH="$(DEPLOY_BRANCH)" $(BEAT) python manage.py send_startup_notification
.PHONY: logs
logs:
$(COMPOSE) logs -f
.PHONY: logs-web
logs-web:
$(COMPOSE) logs -f web
.PHONY: logs-worker
logs-worker:
$(COMPOSE) logs -f celery_worker
.PHONY: logs-beat
logs-beat:
$(COMPOSE) logs -f celery_beat
# ── Django ────────────────────────────────────────────────────────────────────
.PHONY: migrate
migrate:
$(MANAGE) migrate
.PHONY: makemigrations
makemigrations:
$(MANAGE) makemigrations
.PHONY: superuser
superuser:
$(MANAGE) createsuperuser
.PHONY: shell
shell:
$(MANAGE) shell
.PHONY: bash
bash:
$(COMPOSE) exec $(APP) bash
.PHONY: collectstatic
collectstatic:
$(MANAGE) collectstatic --noinput
# ── Testing (runs locally, not inside the production image) ───────────────────
.PHONY: test
test:
python -m pytest
.PHONY: test-fast
test-fast:
python -m pytest -x --tb=short
.PHONY: test-cov
test-cov:
python -m pytest --tb=short --cov=. --cov-report=term-missing
# ── Slack session ─────────────────────────────────────────────────────────────
.PHONY: slack-login slack-wait-profile slack-login-stop extract-slack-tokens \
slack-tokens-reextract slack-tokens-refresh
slack-login:
@mkdir -p workspace/slack_event_handler/chrome_profile
$(COMPOSE) --profile slack-session up -d --force-recreate slack-chromium
@echo "Open http://127.0.0.1:7900 and sign in at https://app.slack.com (wait until Slack is fully loaded)"
@command -v open >/dev/null 2>&1 && open "http://127.0.0.1:7900" || true
slack-wait-profile:
@chmod +x scripts/wait_slack_chrome_profile.sh
@./scripts/wait_slack_chrome_profile.sh
slack-login-stop:
$(COMPOSE) --profile slack-session stop slack-chromium
extract-slack-tokens: slack-login-stop
$(MANAGE) extract_slack_tokens
# Profile already exists (re-extract without opening noVNC again).
slack-tokens-reextract: extract-slack-tokens
# Login in noVNC, wait for profile files, then extract JSON.
slack-tokens-refresh: slack-login slack-wait-profile extract-slack-tokens
# ── Discord session ───────────────────────────────────────────────────────────
.PHONY: discord-login discord-wait-profile discord-login-stop extract-discord-tokens \
discord-tokens-reextract discord-tokens-refresh
discord-login:
@mkdir -p workspace/discord_activity_tracker/chrome_profile
@rm -f workspace/discord_activity_tracker/chrome_profile/SingletonLock \
workspace/discord_activity_tracker/chrome_profile/SingletonCookie \
workspace/discord_activity_tracker/chrome_profile/SingletonSocket
$(COMPOSE) --profile discord-session up -d --force-recreate discord-chromium
@echo "noVNC (password: secret) — Chrome does NOT open automatically:"
@echo " http://127.0.0.1:7901/?autoconnect=1&resize=scale&password=secret"
@echo "Right-click desktop → Web Browsing → Google Chrome → https://discord.com"
@command -v open >/dev/null 2>&1 && open "http://127.0.0.1:7901/?autoconnect=1&resize=scale&password=secret" || true
discord-wait-profile:
@chmod +x scripts/wait_discord_chrome_profile.sh
@./scripts/wait_discord_chrome_profile.sh
discord-login-stop:
$(COMPOSE) --profile discord-session stop discord-chromium
extract-discord-tokens: discord-login-stop
$(MANAGE) extract_discord_tokens
discord-tokens-reextract: extract-discord-tokens
discord-tokens-refresh: discord-login discord-wait-profile extract-discord-tokens
# ── Utilities ─────────────────────────────────────────────────────────────────
.PHONY: clean-mac
clean-mac:
@find . -name '._*' -not -path './.git/*' -delete 2>/dev/null && \
echo "Removed macOS ._* files." || true
.PHONY: clean-pyc
clean-pyc:
@find . -type f -name '*.pyc' -delete && \
find . -type d -name '__pycache__' -delete && \
echo "Removed .pyc and __pycache__."
.PHONY: clean
clean: clean-mac clean-pyc