-
Notifications
You must be signed in to change notification settings - Fork 106
/
Makefile
105 lines (85 loc) · 4.74 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
# provide ENV=dev to use .env.dev instead of .env
ENV_LOADED :=
ifeq ($(ENV), prod)
ifneq (,$(wildcard ./.env))
include .env
export
ENV_LOADED := Loaded config from .env
endif
else
ifneq (,$(wildcard ./.env.dev))
include .env.dev
export
ENV_LOADED := Loaded config from .env.dev
endif
endif
.PHONY: help
.DEFAULT_GOAL := help
help: logo ## get a list of all the targets, and their short descriptions
@# source for the incantation: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?##"}; {printf "\033[1;38;5;214m%-12s\033[0m %s\n", $$1, $$2}'
it-all: logo document-store vector-index backend frontend ## runs automated deployment steps
frontend: slash-command ## deploy the Discord bot on Modal
MODAL_ENVIRONMENT=$(ENV) bash tasks/run_frontend_modal.sh deploy
serve-frontend: slash-command ## run the Discord bot as a hot-reloading "dev" server on Modal
MODAL_ENVIRONMENT=$(ENV) bash tasks/run_frontend_modal.sh serve
slash-command: frontend-secrets ## register the bot's slash command with Discord
@tasks/pretty_log.sh "Assumes you've set up your bot in Discord"
MODAL_ENVIRONMENT=$(ENV) modal run bot::create_slash_command
@tasks/pretty_log.sh "Slash command registered."
backend: secrets ## deploy the Q&A backend on Modal
@tasks/pretty_log.sh "Assumes you've set up the vector index, see vector-index"
MODAL_ENVIRONMENT=$(ENV) bash tasks/run_backend_modal.sh deploy
serve-backend: secrets ## run the Q&A backend as a hot-reloading "dev" server on Modal
@tasks/pretty_log.sh "Assumes you've set up the vector index, see vector-index"
MODAL_ENVIRONMENT=$(ENV) bash tasks/run_backend_modal.sh serve
cli-query: secrets ## run a query via a CLI interface
@tasks/pretty_log.sh "Assumes you've set up the vector index"
MODAL_ENVIRONMENT=$(ENV) modal run app.py::stub.cli --query "${QUERY}"
vector-index: secrets ## adds a FAISS vector index into the corpus to the application
@tasks/pretty_log.sh "Assumes you've set up the document storage, see document-store"
MODAL_ENVIRONMENT=$(ENV) modal run app.py::stub.create_vector_index --db $(MONGODB_DATABASE) --collection $(MONGODB_COLLECTION)
document-store: secrets ## creates a MongoDB collection that contains the document corpus
@tasks/pretty_log.sh "See docstore.py and the ETL notebook for details"
MODAL_ENVIRONMENT=$(ENV) tasks/run_etl.sh --drop --db $(MONGODB_DATABASE) --collection $(MONGODB_COLLECTION)
debugger: modal-auth ## starts a debugger running in a Modal container but accessible via the terminal
MODAL_ENVIRONMENT=$(ENV) modal shell app.py
frontend-secrets: modal-auth
@$(if $(value DISCORD_AUTH),, \
$(error DISCORD_AUTH is not set. Please set it before running this target.))
@$(if $(value DISCORD_PUBLIC_KEY),, \
$(error DISCORD_PUBLIC_KEY is not set. Please set it before running this target.))
MODAL_ENVIRONMENT=$(ENV) bash tasks/send_frontend_secrets_to_modal.sh
secrets: modal-auth ## pushes secrets from .env to Modal
@$(if $(value OPENAI_API_KEY),, \
$(error OPENAI_API_KEY is not set. Please set it before running this target.))
@$(if $(value MONGODB_HOST),, \
$(error MONGODB_HOST is not set. Please set it before running this target.))
@$(if $(value MONGODB_USER),, \
$(error MONGODB_USER is not set. Please set it before running this target.))
@$(if $(value MONGODB_PASSWORD),, \
$(error MONGODB_PASSWORD is not set. Please set it before running this target.))
MODAL_ENVIRONMENT=$(ENV) bash tasks/send_secrets_to_modal.sh
modal-auth: environment ## confirms authentication with Modal, using secrets from `.env` file
@tasks/pretty_log.sh "If you haven't gotten a Modal token yet, run make modal-token"
@$(if $(value MODAL_TOKEN_ID),, \
$(error MODAL_TOKEN_ID is not set. Please set it before running this target. See make modal-token.))
@$(if $(value MODAL_TOKEN_SECRET),, \
$(error MODAL_TOKEN_SECRET is not set. Please set it before running this target. See make modal-token.))
@modal token set --token-id $(MODAL_TOKEN_ID) --token-secret $(MODAL_TOKEN_SECRET)
bash tasks/setup_environment_modal.sh $(ENV)
modal-token: environment ## creates token ID and secret for authentication with modal
modal token new
@tasks/pretty_log.sh "Copy the token info from the file mentioned above into .env"
environment: ## installs required environment for deployment and corpus generation
@if [ -z "$(ENV_LOADED)" ]; then \
echo "Error: Configuration file not found" >&2; \
exit 1; \
else \
tasks/pretty_log.sh "$(ENV_LOADED)"; \
fi
python -m pip install -qqq -r requirements.txt
dev-environment: environment ## installs required environment for development
python -m pip install -qqq -r requirements-dev.txt
logo: ## prints the logo
@cat logo.txt; echo "\n"