-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
198 lines (160 loc) · 6.79 KB
/
Makefile
File metadata and controls
198 lines (160 loc) · 6.79 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
.PHONY: up down restart logs status backup restore backup-list backup-verify rebuild-ssg clean-ssg deploy nginx-setup build rebuild fix-permissions test lint reindex-search seo-publish-setup seo-publish-status seo-publish-logs seo-publish-restart seo-publish-stop
# ============================================================
# Docker Services
# ============================================================
up:
docker compose up -d
down:
docker compose down
restart:
docker compose restart
build:
docker compose up -d --build
rebuild:
docker compose build --no-cache
docker compose up -d
docker image prune -f
logs:
docker compose logs -f --tail 100
status:
@echo "=== Textstack Status ==="
@docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "(textstack|NAMES)"
@echo ""
@curl -sf http://localhost:8080/health > /dev/null && echo "API: healthy" || echo "API: unhealthy"
# ============================================================
# Deployment
# ============================================================
# Fix volume permissions for containers running as non-root
fix-permissions:
@echo "Fixing volume permissions..."
@mkdir -p data/textstack data/tts-cache data/explain-cache
@docker run --rm -v $$(pwd)/data/textstack:/data -v $$(pwd)/data/tts-cache:/tts -v $$(pwd)/data/explain-cache:/explain alpine sh -c 'chown -R 1000:1000 /data /tts /explain'
@echo "Done."
deploy: fix-permissions
@echo "=== Deploy ==="
git pull origin main
cd apps/web && pnpm install && VITE_API_URL=/api VITE_STORAGE_URL= VITE_CANONICAL_URL=https://textstack.app pnpm build
docker compose up -d --build
@sleep 10
@curl -sf http://localhost:8080/health && echo " API OK" || echo " API FAILED"
@curl -sf -X POST http://localhost:8080/internal/ssg/rebuild-all && echo " SSG rebuild queued" || echo " SSG rebuild queue failed (non-blocking)"
@echo "Updating nginx config..."
@PROJECT_DIR=$$(pwd) && \
sed "s|/home/vasyl/projects/onlinelib/textstack|$$PROJECT_DIR|g" \
infra/nginx/textstack.conf | sudo tee /etc/nginx/sites-available/textstack > /dev/null
sudo ln -sf /etc/nginx/sites-available/textstack /etc/nginx/sites-enabled/textstack
sudo nginx -t && sudo systemctl reload nginx
docker image prune -f
@systemctl --user restart seo-publish-poller 2>/dev/null && echo " SEO Publish poller restarted" || echo " SEO Publish poller not installed (run: make seo-publish-setup)"
@systemctl --user restart seo-backfill-poller 2>/dev/null && echo " SEO Backfill poller restarted" || echo " SEO Backfill poller not installed (run: make seo-backfill-setup)"
@echo "=== Done ==="
rebuild-ssg:
@echo "=== SSG Rebuild (atomic swap) ==="
cd apps/web && \
API_URL=http://localhost:8080 API_HOST=textstack.app CONCURRENCY=4 \
node scripts/prerender.mjs --output-dir dist/ssg-new && \
rm -rf dist/ssg-old && \
([ -d dist/ssg ] && mv dist/ssg dist/ssg-old || true) && \
mv dist/ssg-new dist/ssg && \
rm -rf dist/ssg-old
@echo "=== Done ==="
clean-ssg:
rm -rf apps/web/dist/ssg apps/web/dist/ssg-new apps/web/dist/ssg-old
@echo "SSG cleaned"
reindex-search:
docker compose exec api dotnet Api.dll reindex-search
# ============================================================
# Testing & Linting
# ============================================================
test:
dotnet test
pnpm -C apps/web test
lint:
dotnet format --verify-no-changes
# ============================================================
# Nginx Setup (one-time)
# ============================================================
# Linux (systemd)
nginx-setup:
@echo "Generating nginx config..."
@PROJECT_DIR=$$(pwd) && \
sudo sed "s|/home/vasyl/projects/onlinelib/textstack|$$PROJECT_DIR|g" \
infra/nginx/textstack.conf > /tmp/textstack.conf && \
sudo mv /tmp/textstack.conf /etc/nginx/sites-available/textstack && \
sudo ln -sf /etc/nginx/sites-available/textstack /etc/nginx/sites-enabled/ && \
sudo nginx -t && sudo systemctl reload nginx
@echo "Done."
# Mac (homebrew)
nginx-setup-mac:
@echo "Generating nginx config for Mac..."
@sed "s|/home/vasyl/projects/onlinelib/textstack|$$(pwd)|g" \
infra/nginx/textstack.conf > /opt/homebrew/etc/nginx/servers/textstack.conf
@echo "Done. Run: sudo nginx -s reload"
# ============================================================
# Database Backup/Restore
# ============================================================
BACKUP_DIR := $(HOME)/backups/textstack
backup:
@mkdir -p $(BACKUP_DIR)
@. ./.env && docker exec textstack_db_prod pg_dump -U $$POSTGRES_USER $$POSTGRES_DB | gzip > $(BACKUP_DIR)/db_$$(date +%Y-%m-%d_%H%M%S).sql.gz
@echo "Backup saved:"
@ls -lh $(BACKUP_DIR)/db_*.sql.gz | tail -1
restore:
@if [ -z "$(FILE)" ]; then \
echo "Usage: make restore FILE=$(BACKUP_DIR)/db_YYYY-MM-DD_HHMMSS.sql.gz"; \
exit 1; \
fi
@echo "Restoring from $(FILE)..."
@. ./.env && gunzip -c $(FILE) | docker exec -i textstack_db_prod psql -U $$POSTGRES_USER $$POSTGRES_DB
@echo "Done."
backup-list:
@ls -lh $(BACKUP_DIR)/*.sql.gz 2>/dev/null || echo "No backups found"
backup-verify:
@FILE="$(FILE)"; \
if [ -z "$$FILE" ]; then \
FILE=$$(ls -1t $(BACKUP_DIR)/db*.sql.gz 2>/dev/null | head -n 1); \
fi; \
if [ -z "$$FILE" ]; then \
echo "No backup found. Pass FILE=... or run 'make backup' first."; \
exit 1; \
fi; \
echo "Verifying $$FILE ..."; \
./infra/scripts/backup-verify.sh "$$FILE"
# ============================================================
# SEO Auto-Publish
# ============================================================
seo-publish-setup:
@mkdir -p ~/.config/systemd/user
@cp infra/systemd/seo-publish-poller.service ~/.config/systemd/user/
@systemctl --user daemon-reload
@systemctl --user enable seo-publish-poller
@systemctl --user start seo-publish-poller
@loginctl enable-linger $$(whoami)
@echo "SEO Auto-Publish poller installed and started."
seo-publish-status:
@systemctl --user status seo-publish-poller
seo-publish-logs:
@journalctl --user -u seo-publish-poller -f
seo-publish-restart:
@systemctl --user restart seo-publish-poller
seo-publish-stop:
@systemctl --user stop seo-publish-poller
# ============================================================
# SEO Backfill (template-driven SEO generation for Authors/Editions/Genres/Blog)
# ============================================================
seo-backfill-setup:
@mkdir -p ~/.config/systemd/user
@cp infra/systemd/seo-backfill-poller.service ~/.config/systemd/user/
@systemctl --user daemon-reload
@systemctl --user enable seo-backfill-poller
@systemctl --user start seo-backfill-poller
@loginctl enable-linger $$(whoami)
@echo "SEO Backfill poller installed and started."
seo-backfill-status:
@systemctl --user status seo-backfill-poller
seo-backfill-logs:
@journalctl --user -u seo-backfill-poller -f
seo-backfill-restart:
@systemctl --user restart seo-backfill-poller
seo-backfill-stop:
@systemctl --user stop seo-backfill-poller