forked from kreneskyp/ix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·233 lines (177 loc) · 5.99 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
DOCKER_COMPOSE=docker-compose.yml
DOCKER_REGISTRY=ghcr.io
# check for md5sum or md5 for hashing
HASHER := $(shell command -v md5sum 2> /dev/null)
ifndef HASHER
HASHER := md5 -r
endif
# APP IMAGE
DOCKERFILE=Dockerfile
DOCKER_REPOSITORY=${DOCKER_REGISTRY}/kreneskyp/ix/sandbox
HASH_FILES=requirements*.txt package.json Dockerfile
IMAGE_TAG=$(shell cat $(HASH_FILES) | ${HASHER} | cut -d ' ' -f 1)
IMAGE_URL=$(DOCKER_REPOSITORY):$(IMAGE_TAG)
IMAGE_SENTINEL=.sentinel/image
# PSQL IMAGE
DOCKERFILE_PSQL=psql.Dockerfile
DOCKER_REPOSITORY_PSQL=${DOCKER_REGISTRY}/kreneskyp/ix/postgres-pg-vector
HASH_FILES_PSQL=psql.Dockerfile
IMAGE_TAG_PSQL=$(shell cat $(HASH_FILES_PSQL) | ${HASHER} | cut -d ' ' -f 1)
IMAGE_URL_PSQL=$(DOCKER_REPOSITORY_PSQL):$(IMAGE_TAG_PSQL)
IMAGE_SENTINEL_PSQL=.sentinel/image.psql
DOCKER_COMPOSE_RUN=docker-compose run --rm web
DOCKER_COMPOSE_RUN_WITH_PORT=docker-compose run -p 8000:8000 --rm web
# set to skip build, primarily used by github workflows to skip builds when image is cached
NO_IMAGE_BUILD?=0
.PHONY: image-tag
image-tag:
@echo ${IMAGE_TAG}
.PHONY: image-url
image-url:
@echo ${IMAGE_URL}
# build existence check
.sentinel:
mkdir -p .sentinel
# Set LANGCHAIN_DEV to 1 to enable dev mode in docker build
# local copy of langchain should be checked out to ix/langchain.
# (docker desktop on windows doesn't support shares outside the project)
LANGCHAIN_DEV ?=
DOCKER_BUILD_ARGS = $(if ${LANGCHAIN_DEV},--build-arg LANGCHAIN_DEV=${LANGCHAIN_DEV},)
# inner build target for sandbox image
${IMAGE_SENTINEL}: .sentinel $(HASH_FILES)
ifneq (${NO_IMAGE_BUILD}, 1)
echo building SANDBOX ${IMAGE_URL}
docker build -t ${IMAGE_URL} -f ${DOCKERFILE} ${DOCKER_BUILD_ARGS} .
docker tag ${IMAGE_URL} ${DOCKER_REPOSITORY}:latest
touch $@
endif
# inner build target for postgres image
${IMAGE_SENTINEL_PSQL}: .sentinel $(HASH_FILES_PSQL)
ifneq (${NO_IMAGE_BUILD}, 1)
echo building POSTGRES ${IMAGE_URL_PSQL}
docker build -t ${IMAGE_URL_PSQL} -f $(DOCKERFILE_PSQL) .
docker tag ${IMAGE_URL_PSQL} ${DOCKER_REPOSITORY_PSQL}:latest
touch $@
endif
# setup target for docker-compose, add deps here to apply to all compose sessions
.PHONY: compose
compose: image
# =========================================================
# Build
# =========================================================
# dev setup - runs all initial setup steps in one go
.PHONY: dev_setup
dev_setup: image frontend migrate dev_fixtures
# build image
.PHONY: image
image: ${IMAGE_SENTINEL} ${IMAGE_SENTINEL_PSQL}
# full frontend build
.PHONY: frontend
frontend: compose npm_install graphene_to_graphql compile_relay webpack
# install npm packages
.PHONY: npm_install
npm_install: compose package.json
docker-compose run --rm web npm install
# compile javascript
.PHONY: webpack
webpack: compose
${DOCKER_COMPOSE_RUN} webpack --progress
# compile javascript in watcher mode
.PHONY: webpack-watch
webpack-watch: compose
${DOCKER_COMPOSE_RUN} webpack --progress --watch
# compile graphene graphql classes into schema.graphql for javascript
.PHONY: graphene_to_graphql
graphene_to_graphql: compose
${DOCKER_COMPOSE_RUN} ./manage.py graphql_schema --out ./frontend/schema.graphql
# compile javascript
.PHONY: compile_relay
compile_relay: compose
${DOCKER_COMPOSE_RUN} npm run relay
# =========================================================
# Run
# =========================================================
# run backend and frontend. This starts uvicorn for asgi+websockers
# and nginx to serve static files
.PHONY: server
server: compose
docker-compose up web nginx
# run django debug server, backup in case nginx ever breaks
.PHONY: runserver
runserver: compose
${DOCKER_COMPOSE_RUN_WITH_PORT} ./manage.py runserver 0.0.0.0:8000
# run worker
.PHONY: worker
worker: compose
${DOCKER_COMPOSE_RUN} celery.sh
# =========================================================
# Shells
# =========================================================
.PHONY: bash
bash: compose
${DOCKER_COMPOSE_RUN} /bin/bash
.PHONY: shell
shell: compose
${DOCKER_COMPOSE_RUN} ./manage.py shell_plus
# =========================================================
# Dev tools
# =========================================================
# shortcut to run django migrations
.PHONY: migrate
migrate: compose
${DOCKER_COMPOSE_RUN} ./manage.py migrate
# shortcut to generate django migrations
.PHONY: migrations
migrations: compose
${DOCKER_COMPOSE_RUN} ./manage.py makemigrations
# load initial data needed for dev environment
.PHONY: dev_fixtures
dev_fixtures: compose
${DOCKER_COMPOSE_RUN} ./manage.py loaddata fake_user
# load component NodeTypes
${DOCKER_COMPOSE_RUN} ./manage.py loaddata node_types
# initial agents + chains
${DOCKER_COMPOSE_RUN} ./manage.py loaddata ix_v2 code_v2 pirate_v1 wikipedia_v1 klarna_v1 bot_smith_v1
# Generate fixture for NodeTypes defined in python fixtures.
# This converts all NodeTypes present in the database into a
# Django fixture required for unit tests.
#
# This will import_langchain and then export both
# new and existing types from the table.
.PHONY: node_types_fixture
node_types_fixture: compose
${DOCKER_COMPOSE_RUN} ./manage.py import_langchain
${DOCKER_COMPOSE_RUN} ./manage.py dumpdata chains.NodeType --indent 2 > ix/chains/fixtures/node_types.json
# =========================================================
# Testing
# =========================================================
.PHONY: test
test: compose pytest
.PHONY: lint
test: compose flake8 black-check
.PHONY: format
format: black isort
.PHONY: black
black: compose
${DOCKER_COMPOSE_RUN} black .
.PHONY: black-check
black-check: compose
${DOCKER_COMPOSE_RUN} black --check .
.PHONY: flake8
flake8: compose
${DOCKER_COMPOSE_RUN} flake8 .
.PHONY: isort
isort: compose
${DOCKER_COMPOSE_RUN} isort .
.PHONY: pytest
pytest: compose
${DOCKER_COMPOSE_RUN} pytest
.PHONY: pyright
pyright: compose
${DOCKER_COMPOSE_RUN} pyright
# =========================================================
# Cleanup
# =========================================================
.PHONY: clean
clean:
rm -rf .sentinel