-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathMakefile
More file actions
192 lines (170 loc) · 5.68 KB
/
Makefile
File metadata and controls
192 lines (170 loc) · 5.68 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
-include .env
export
.PHONY: start
start:
uv run --no-group gpu uvicorn restai.main:app --host $${RESTAI_HOST:-127.0.0.1} --port $${RESTAI_PORT:-9000} --workers $${RESTAI_WORKERS:-2}
.PHONY: database
database:
uv run --no-group gpu database.py
.PHONY: frontend
frontend:
cd frontend && npm install
cd frontend && npm run build
.PHONY: dev
dev:
RESTAI_DEV=true uvicorn restai.main:app --reload --host $${RESTAI_HOST:-127.0.0.1} --port $${RESTAI_PORT:-9000}
.PHONY: build
build:
uv build
.PHONY: install
install:
mkdir -p frontend/build
uv sync --no-group gpu
make database
make frontend
@if command -v nvidia-smi > /dev/null 2>&1 && nvidia-smi > /dev/null 2>&1; then \
echo "GPU detected, running installgpu..."; \
$(MAKE) installgpu; \
fi
@echo ""
@echo "=== Installation complete ==="
@echo ""
@read -p "Install RESTai as a systemd service? [y/N] " answer; \
if [ "$$answer" = "y" ] || [ "$$answer" = "Y" ]; then \
$(MAKE) systemd; \
fi
@read -p "Install cron jobs (sync + telegram + docker cleanup)? [y/N] " answer; \
if [ "$$answer" = "y" ] || [ "$$answer" = "Y" ]; then \
$(MAKE) cron; \
fi
.PHONY: systemd
systemd:
@RESTAI_DIR=$$(pwd); \
RESTAI_USER=$$(whoami); \
RESTAI_UV=$$(which uv); \
echo "[Unit]" > /tmp/restai.service; \
echo "Description=RESTai AI Platform" >> /tmp/restai.service; \
echo "After=network.target" >> /tmp/restai.service; \
echo "" >> /tmp/restai.service; \
echo "[Service]" >> /tmp/restai.service; \
echo "Type=simple" >> /tmp/restai.service; \
echo "User=$$RESTAI_USER" >> /tmp/restai.service; \
echo "WorkingDirectory=$$RESTAI_DIR" >> /tmp/restai.service; \
echo "EnvironmentFile=$$RESTAI_DIR/.env" >> /tmp/restai.service; \
echo "ExecStart=$$RESTAI_UV run --no-group gpu uvicorn restai.main:app --host $${RESTAI_HOST:-127.0.0.1} --port $${RESTAI_PORT:-9000} --workers $${RESTAI_WORKERS:-4}" >> /tmp/restai.service; \
echo "Restart=always" >> /tmp/restai.service; \
echo "RestartSec=5" >> /tmp/restai.service; \
echo "" >> /tmp/restai.service; \
echo "[Install]" >> /tmp/restai.service; \
echo "WantedBy=multi-user.target" >> /tmp/restai.service; \
sudo cp /tmp/restai.service /etc/systemd/system/restai.service; \
rm /tmp/restai.service; \
sudo systemctl daemon-reload; \
sudo systemctl enable restai; \
sudo systemctl start restai; \
echo ""; \
echo "RESTai systemd service installed and started."; \
echo " Status: sudo systemctl status restai"; \
echo " Logs: sudo journalctl -u restai -f"; \
echo " Stop: sudo systemctl stop restai"; \
echo " Restart: sudo systemctl restart restai"
.PHONY: installgpu
installgpu:
uv sync
make envs
uv run --no-group gpu download.py
.PHONY: envs
envs:
bash worker_envs/install.sh
.PHONY: migrate
migrate:
uv run --no-group gpu migrate.py upgrade
.PHONY: cron
cron:
@RESTAI_DIR=$$(pwd); \
CURRENT=$$(crontab -l 2>/dev/null || true); \
if echo "$$CURRENT" | grep -q "restai-sync\|restai-telegram\|restai-docker-cleanup\|restai-routines"; then \
CURRENT=$$(echo "$$CURRENT" | grep -v "restai-sync\|restai-telegram\|restai-docker-cleanup\|restai-routines"); \
echo "Removed old individual cron jobs"; \
fi; \
UV_PATH=$$(which uv); \
ENTRY="* * * * * cd $$RESTAI_DIR && $$UV_PATH run --no-group gpu python crons/runner.py >> /var/log/restai-crons.log 2>&1 # restai-crons"; \
if echo "$$CURRENT" | grep -q "restai-crons"; then \
echo "Already installed: restai-crons"; \
elif [ -z "$$CURRENT" ]; then \
CURRENT="$$ENTRY"; \
echo "Added: restai-crons"; \
else \
CURRENT="$$CURRENT"$$'\n'"$$ENTRY"; \
echo "Added: restai-crons"; \
fi; \
echo "$$CURRENT" | crontab -
@echo "Cron jobs installed:"
@crontab -l | grep restai || true
.PHONY: cron-remove
cron-remove:
@( crontab -l 2>/dev/null | grep -v "restai-crons" ) | crontab -
@echo "RESTai cron jobs removed."
.PHONY: update
update:
@echo "Fetching latest release from GitHub..."
@LATEST=$$(git ls-remote --tags --sort=-v:refname origin 'refs/tags/v*' 2>/dev/null | head -1 | sed 's/.*refs\/tags\///'); \
if [ -z "$$LATEST" ]; then \
echo "No release tags found. Pulling latest from current branch..."; \
git pull; \
else \
echo "Latest release: $$LATEST"; \
git fetch --tags; \
git checkout "$$LATEST"; \
fi
@echo "Installing dependencies..."
uv sync --no-group gpu
@echo "Running database migrations..."
$(MAKE) migrate
@echo "Building frontend..."
$(MAKE) frontend
@if command -v nvidia-smi > /dev/null 2>&1 && nvidia-smi > /dev/null 2>&1; then \
echo "GPU detected, syncing GPU deps..."; \
$(MAKE) installgpu; \
fi
@echo "Update complete."
.PHONY: docs
docs:
uv run --no-group gpu docs.py
.PHONY: version
version:
@CURRENT=$$(grep '^version' pyproject.toml | head -1 | sed 's/.*"\(.*\)"/\1/'); \
MAJOR=$$(echo $$CURRENT | cut -d. -f1); \
MINOR=$$(echo $$CURRENT | cut -d. -f2); \
PATCH=$$(echo $$CURRENT | cut -d. -f3); \
NEW_PATCH=$$((PATCH + 1)); \
NEW_VERSION="$$MAJOR.$$MINOR.$$NEW_PATCH"; \
echo "Bumping version: $$CURRENT → $$NEW_VERSION"; \
sed -i "s/^version = \"$$CURRENT\"/version = \"$$NEW_VERSION\"/" pyproject.toml; \
echo "Syncing lock file..."; \
uv sync --no-group gpu; \
echo "Committing..."; \
git add pyproject.toml uv.lock; \
git commit -m "v$$NEW_VERSION"; \
echo "Tagging v$$NEW_VERSION..."; \
git tag "v$$NEW_VERSION"; \
echo "Pushing..."; \
git push && git push --tags; \
echo "Creating GitHub release..."; \
gh release create "v$$NEW_VERSION" --title "v$$NEW_VERSION" --generate-notes; \
echo "Done: v$$NEW_VERSION released."
.PHONY: test
test:
pytest tests
.PHONY: code
code:
black app/*.py
.PHONY: clean
clean:
rm -rf frontend/build/*
.PHONY: dockershell
dockershell:
@docker run --rm -t -i -v $(shell pwd):/app restai bash
.PHONY: dockerbuild
dockerbuild:
@docker build -t restai .