-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMakefile
More file actions
197 lines (164 loc) · 5.7 KB
/
Copy pathMakefile
File metadata and controls
197 lines (164 loc) · 5.7 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
# Makefile for common lenny operations
container ?= lenny_api
# Default target
.PHONY: all
all: start
.PHONY: configure
configure:
@bash docker/configure.sh
# Succeed if lenny is up, else fail
.PHONY: ifup
ifup:
@docker ps -q -f name=$(container) > /dev/null || { \
echo "[!] $(container) is not running. Aborting."; \
exit 1; \
}
# Preload books (pass an optional number to limit)
# e.g. make preload items=5
.PHONY: preload
preload: ifup
@bash docker/utils/preload.sh $(items)
# Start a public tunnel (e.g., via cloudflared)
.PHONY: tunnel
tunnel:
@bash docker/utils/tunnel.sh --start
@bash docker/utils/lenny.sh --rebuild-reader
# Start a public tunnel (e.g., via cloudflared)
.PHONY: untunnel
untunnel:
@bash docker/utils/tunnel.sh --stop
# Teardown all containers, volumes, and orphans for a clean slate
.PHONY: teardown
teardown:
docker compose down --volumes --remove-orphans
# Remove the orphaned pre-Garage MinIO container + volume, once you've
# verified the migrated Garage bucket has everything (see `make update`).
# Opt-in, run manually — never done automatically.
.PHONY: cleanup-old-s3
cleanup-old-s3:
@docker rm -f lenny_s3 lenny_s3_migration_source 2>/dev/null || true
@docker volume rm lenny_s3_data 2>/dev/null || true
@docker rmi minio/minio:latest minio/mc:latest 2>/dev/null || true
@echo "Old MinIO container, volume, and images removed."
.PHONY: log
log:
@docker compose logs -f
# WARNING: wipes database volume and all data.
.PHONY: resetdb
resetdb:
@docker compose -p lenny down -v
.PHONY: start
start:
@bash docker/utils/lenny.sh --start
.PHONY: restart
restart:
@bash docker/utils/lenny.sh --restart
# Build and start containers (uses cache)
# WARNING: wipes database volume. Use 'make redeploy' to preserve data.
.PHONY: build
build:
@bash docker/utils/lenny.sh --build
# Rebuild and start containers (recreate with no cache)
# WARNING: wipes database volume. Use 'make redeploy' to preserve data.
.PHONY: rebuild
rebuild:
@bash docker/utils/lenny.sh --rebuild
# Rebuild API image and apply migrations WITHOUT wiping data (safe for updates)
# Use this when pulling new code changes, migrations, or dependency updates.
.PHONY: redeploy
redeploy:
@bash docker/utils/lenny.sh --redeploy
.PHONY: stop
stop:
@bash docker/utils/lenny.sh --stop
@$(MAKE) untunnel
.PHONY: addbook
addbook:
@if [ -z "$(olid)" ] || [ -z "$(filepath)" ]; then \
echo "Error: Missing required arguments."; \
echo "Usage: make addbook olid=OL123456M filepath=/path/to/book.epub [encrypted=true]"; \
exit 1; \
fi
@bash docker/utils/addbook.sh --olid $(olid) --filepath $(filepath) $(if $(filter true,$(encrypted)),--encrypted,)
.PHONY: url
url:
@TUNNEL_URL=$$(grep -aEo 'https://[a-zA-Z0-9.-]+\.(trycloudflare|cfargotunnel)\.com' cloudflared.log 2>/dev/null | head -n1); \
if [ -z "$$TUNNEL_URL" ]; then \
echo "[!] No tunnel URL found. Run 'make tunnel' first."; \
exit 1; \
fi; \
OPDS_URL="$$TUNNEL_URL/v1/api/opds"; \
ENCODED_OPDS=$$(python3 -c "import urllib.parse; print(urllib.parse.quote('$$OPDS_URL', safe=''))"); \
READER_URL="https://reader.archive.org/?opds=$$ENCODED_OPDS"; \
echo "[+] OPDS Feed: $$OPDS_URL"; \
echo "[+] Reader URL: $$READER_URL"
# Update to latest version
.PHONY: update
update:
@bash docker/utils/update.sh
# Remove dangling images and cap build cache to free disk/memory.
# Safe: never touches running containers, named volumes, or DB data.
# Run manually after updates or whenever disk usage is high.
.PHONY: prune
prune:
@echo "Pruning dangling images..."
@docker image prune -f
@echo "Capping build cache to 2 GB..."
@docker builder prune -f --reserved-space=2gb
@echo "Done."
# Log in to archive.org/openlibrary.org and store IA S3 keys in .env.
# Idempotent — safe to re-run. Use to log in, re-login with a different account,
# or recover from a failed lending setup.
.PHONY: ol-login
ol-login: ifup
@bash docker/utils/ol_configure.sh
# Log out of archive.org — clears IA S3 keys from .env and disables lending.
.PHONY: ol-logout
ol-logout: ifup
@bash docker/utils/ol_logout.sh
# Run environment diagnostics
.PHONY: doctor
doctor:
@bash docker/utils/doctor.sh
# Database Migrations
# Run pending migrations inside container
.PHONY: migrate
migrate: ifup
@docker exec $(container) alembic upgrade head
# Show current migration status
.PHONY: migrate-status
migrate-status: ifup
@docker exec $(container) alembic current
@docker exec $(container) alembic history
# Generate a new migration from model changes (developers only)
# Usage: make migration msg="add pkce tables"
.PHONY: migration
migration: ifup
@if [ -z "$(msg)" ]; then \
echo "Error: Missing migration message."; \
echo "Usage: make migration msg=\"describe your changes\""; \
exit 1; \
fi
@docker exec $(container) alembic revision --autogenerate -m "$(msg)"
# Rollback last migration (use with caution)
.PHONY: migrate-rollback
migrate-rollback: ifup
@echo "WARNING: This will rollback the last migration."
@echo "Press Ctrl+C to cancel, or Enter to continue..."
@read _
@docker exec $(container) alembic downgrade -1
# Stamp current DB as up-to-date (for existing databases adopting Alembic)
.PHONY: migrate-stamp
migrate-stamp: ifup
@docker exec $(container) alembic stamp head
@echo "Database stamped as up-to-date."
# Squash all migrations into a new baseline (major releases only)
# Usage: make squash-migrations
.PHONY: squash-migrations
squash-migrations: ifup
@echo "WARNING: This will squash all migrations into a new baseline."
@echo "Only do this on major releases. Press Ctrl+C to cancel, or Enter to continue..."
@read _
@rm -f alembic/versions/*.py
@docker exec $(container) alembic revision --autogenerate -m "squashed baseline"
@echo "New baseline created. Existing databases must run: make migrate-stamp"