-
Notifications
You must be signed in to change notification settings - Fork 228
/
Makefile
293 lines (248 loc) · 8.41 KB
/
Makefile
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
.PHONY: default banner help install build run stop restart rasa-restart rasa-stop rasa-start rasa-build seed logs ngrok pgadmin api api-stop db db-stop db-purge purge models shell-api shell-db shell-rasa shell-actions rasa-train rasa-start rasa-stop env-var
defaut: help
help:
@make banner
@echo "+------------------+"
@echo "| 🏠 CORE COMMANDS |"
@echo "+------------------+"
@echo "make install - Install and run RasaGPT"
@echo "make build - Build docker images"
@echo "make run - Run RasaGPT"
@echo "make stop - Stop RasaGPT"
@echo "make restart - Restart RasaGPT\n"
@echo "+--------------------+"
@echo "| 🌍 ADMIN INTERACES |"
@echo "+--------------------+"
@echo "make logs - View logs via Dozzle"
@echo "make ngrok - View ngrok dashboard"
@echo "make pgadmin - View pgAdmin dashboard\n"
@echo "+-----------------------+"
@echo "| 👷 DEBUGGING COMMANDS |"
@echo "+-----------------------+"
@echo "make api - Run only API server"
@echo "make models - Build Rasa models"
@echo "make purge - Remove all docker images"
@echo "make db-purge - Delete all data in database"
@echo "make db-reset - Reset database to initial state"
@echo "make shell-api - Open shell in API container"
@echo "make shell-db - Open shell in database container"
@echo "make shell-rasa - Open shell in Rasa container"
@echo "make shell-actions - Open shell in Rasa actions container\n"
banner:
@echo "\n\n-------------------------------------"
@echo "▒█▀▀█ █▀▀█ █▀▀ █▀▀█ ▒█▀▀█ ▒█▀▀█ ▀▀█▀▀"
@echo "▒█▄▄▀ █▄▄█ ▀▀█ █▄▄█ ▒█░▄▄ ▒█▄▄█ ░▒█░░"
@echo "▒█░▒█ ▀░░▀ ▀▀▀ ▀░░▀ ▒█▄▄█ ▒█░░░ ░▒█░░"
@echo "+-----------------------------------+"
@echo "| http://RasaGPT.dev by @paulpierre |"
@echo "+-----------------------------------+\n\n"
# ==========================
# 👷 INITIALIZATION COMMANDS
# ==========================
# ---------------------------------------
# Run this first to setup the environment
# ---------------------------------------
install:
@make banner
@make stop
@make env-var
@make rasa-train
@make build
@make run
@make models
@make rasa-restart
@make seed
@echo "✅ RasaGPT installed and running"
# -----------------------
# Build the docker images
# -----------------------
build:
@echo "🏗️ Building docker images ..\n"
@docker-compose -f docker-compose.yml build
# ================
# 🏠 CORE COMMANDS
# ================
# ---------------------------
# Startup all docker services
# ---------------------------
run:
@echo "🚀 Starting docker-compose.yml ..\n"
@docker-compose -f docker-compose.yml up -d
# ---------------------------
# Stop all running containers
# ---------------------------
stop:
@echo "🔍 Stopping any running containers .. \n"
@docker-compose -f docker-compose.yml down
# ----------------------
# Restart all containers
# ----------------------
restart:
@echo "🔁 Restarting docker services ..\n"
@make stop
@make run
# ----------------------
# Restart Rasa core only
# ----------------------
rasa-restart:
@echo "🤖 Restarting Rasa so it grabs credentials ..\n"
@make rasa-stop
@make rasa-start
rasa-stop:
@echo "🤖 Stopping Rasa ..\n"
@docker-compose -f docker-compose.yml stop rasa-core
rasa-start:
@echo "🤖 Starting Rasa ..\n"
@docker-compose -f docker-compose.yml up -d rasa-core
rasa-build:
@echo "🤖 Building Rasa ..\n"
@docker-compose -f docker-compose.yml build rasa-core
# -----------------------
# Seed database with data
# -----------------------
seed:
@echo "🌱 Seeding database ..\n"
@docker-compose -f docker-compose.yml exec api /app/api/wait-for-it.sh db:5432 --timeout=60 -- python3 seed.py
# =======================
# 🌍 WEB ADMIN INTERFACES
# =======================
# -------------------------
# Reverse HTTP tunnel admin
# -------------------------
ngrok:
@echo "📡 Opening ngrok agent in the browser ..\n"
@open http://localhost:4040
# ------------------------
# Postgres admin interface
# ------------------------
pgadmin:
@echo "👷♂️ Opening PG Admin in the browser ..\n"
@open http://localhost:5050
# ------------------------
# Container logs interface
# ------------------------
logs:
@echo "🔍 Opening container logs in the browser ..\n"
@open http://localhost:9999/
# =====================
# 👷 DEBUGGING COMMANDS
# =====================
# ---------------------------
# Startup just the API server
# ---------------------------
api:
@make db
@echo "🚀 Starting FastAPI and postgres ..\n"
@docker-compose -f docker-compose.yml up -d api
# ------------------------
# Startup just Postgres DB
# ------------------------
db:
@echo "🚀 Starting Postgres with pgvector ..\n"
@docker-compose -f docker-compose.yml up -d db
db-stop:
@echo " Stopping the database ..\n"
@docker-compose -f docker-compose.yml down db
db-reset:
@echo "⛔ Are you sure you want to reinitialize the database, you will lose all data? [y/N]\n"
@read confirmation; \
if [ "$$confirmation" = "y" ] || [ "$$confirmation" = "Y" ]; then \
make db-purge \
make api \
make models \
echo "✅ Database re-initialize"; \
else \
echo "Aborted."; \
fi
@echo " Resetting the database ..\n"
# -------------------------------
# Build the schema in Postgres DB
# -------------------------------
models:
@echo "💽 Building models in Postgres ..\n"
@docker-compose -f docker-compose.yml exec api /app/api/wait-for-it.sh db:5432 --timeout=60 -- python3 models.py
# -------------------------------
# Delete containers or bad images
# -------------------------------
purge:
@echo "🧹 Purging all containers and images ..\n"
@make stop
@docker system prune -a
@make install
# --------------------------------
# Delete the database mount volume
# --------------------------------
db-purge:
@echo "⛔ Are you sure you want to delete all data in the database? [y/N]\n"
@read confirmation; \
if [ "$$confirmation" = "y" ] || [ "$$confirmation" = "Y" ]; then \
echo "Deleting generated files .."; \
make stop; \
rm -rf ./mnt; \
echo "Deleted."; \
else \
echo "Aborted."; \
fi
# --------------------------------------
# Open a bash shell in the API container
# --------------------------------------
shell-api:
@echo "💻🐢 Opening a bash shell in the RasaGPT API container ..\n"
@if docker ps | grep chat_api > /dev/null; then \
docker exec -it $$(docker ps | grep chat_api | tr -d '\n' | awk '{print $$1}') /bin/bash; \
else \
echo "Container chat_api is not running"; \
fi
# ---------------------------------------
# Open a bash shell in the Rasa container
# ---------------------------------------
shell-rasa:
@echo "💻🐢 Opening a bash shell in the chat_rasa_core container ..\n"
@if docker ps | grep chat_rasa_core > /dev/null; then \
docker exec -it $$(docker ps | grep chat_rasa_core | tr -d '\n' | awk '{print $$1}') /bin/bash; \
else \
echo "Container chat_rasa_core is not running"; \
fi
# -----------------------------------------------
# Open a bash shell in the Rasa actions container
# -----------------------------------------------
shell-actions:
@echo "💻🐢 Opening a bash shell in the chat_rasa_actions container ..\n"
@if docker ps | grep chat_rasa_actions > /dev/null; then \
docker exec -it $$(docker ps | grep chat_rasa_actions | tr -d '\n' | awk '{print $$1}') /bin/bash; \
else \
echo "Container chat_rasa_actions is not running"; \
fi
# -------------------------------------------
# Open a bash shell in the Postgres container
# -------------------------------------------
shell-db:
@echo "💻🐢 Opening a bash shell in the Postgres container ..\n"
@if docker ps | grep chat_db > /dev/null; then \
docker exec -it $$(docker ps | grep chat_db | tr -d '\n' | awk '{print $$1}') /bin/bash; \
else \
echo "Container chat_db is not running"; \
fi
# ==================
# 💁 HELPER COMMANDS
# ==================
# -------------
# Check envvars
# -------------
env-var:
@echo "🔍 Checking if envvars are set ..\n";
@if ! test -e "./.env"; then \
@echo "❌ .env file not found. Please copy .env-example to .env and update values"; \
exit 1; \
else \
echo "✅ found .env\n"; \
fi
# -----------------
# Train Rasa models
# -----------------
rasa-train:
@echo "💽 Generating Rasa models ..\n"
@make rasa-start
@docker-compose -f docker-compose.yml exec rasa-core rasa train
@make rasa-stop
@echo "✅ Done\n"