-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile.prev
407 lines (346 loc) · 13.3 KB
/
Makefile.prev
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
DOCS_REMOTE ?= origin
DEV_CONTAINER ?= funman-dev
DEV_NAME ?= funman-dev
LOCAL_REGISTRY_PORT?=5000
LOCAL_REGISTRY=localhost:$(LOCAL_REGISTRY_PORT)
SIFT_REGISTRY_ROOT=$(LOCAL_REGISTRY)/sift/
FUNMAN_BRANCH?=main
FUNMAN_BASE_PORT?=21000
ifeq (,$(wildcard .docker-as-root))
FUNMAN_SKIP_USER_ARGS=0
FUNMAN_USER=$(shell echo $$USER)
FUNMAN_DEV_DOCKERFILE=Dockerfile
else
FUNMAN_SKIP_USER_ARGS=1
FUNMAN_USER=
FUNMAN_DEV_DOCKERFILE=Dockerfile.root
endif
IBEX_NAME=funman-ibex
DREAL_NAME=funman-dreal4
DEBUG_IBEX?=no
DREAL_LOCAL_REPO?=../dreal4
FUNMAN_VERSION ?= 0.0.0
CMD_UPDATE_VERSION = sed -i -E 's/^__version__ = \"[0-9]+\.[0-9]+\.[0-9]+((a|b|rc)[0-9]*)?\"/__version__ = \"${FUNMAN_VERSION}\"/g'
SHELL_GET_TARGET_ARCH := $(shell test ! -z $(TARGET_ARCH) && echo $(TARGET_ARCH) || \
arch \
| sed s/x86_64/amd64/g \
| sed s/i386/amd64/g \
| sed s/aarch64/arm64/g \
)
TARGET_OS=linux
TARGET_TAG=$(TARGET_OS)-$(SHELL_GET_TARGET_ARCH)
IBEX_TAGGED_NAME=$(IBEX_NAME):$(TARGET_TAG)
DREAL_TAGGED_NAME=$(DREAL_NAME):$(TARGET_TAG)
DEV_TAGGED_NAME=$(DEV_NAME):$(TARGET_TAG)
DEPLOY_BASE_NAME = funman-base
DEPLOY_GIT_NAME = funman-git
DEPLOY_PYPI_NAME = funman-pypi
DEPLOY_TAGGED_BASE_NAME=$(DEPLOY_BASE_NAME):$(TARGET_TAG)
DEPLOY_TAGGED_GIT_NAME=$(DEPLOY_GIT_NAME):$(TARGET_TAG)
DEPLOY_TAGGED_PYPI_NAME=$(DEPLOY_PYPI_NAME):$(TARGET_TAG)
DEPLOY_API_NAME = funman-api-server
DEPLOY_TAGGED_API_NAME=$(DEPLOY_API_NAME):$(TARGET_TAG)
MULTIPLATFORM_TAG=multiplatform
DOCKER_HUB_PLATFORMS=linux/arm64,linux/amd64
DOCKER_HUB_ORG?=jladwigsift
DOCKER_HUB_TAG?=hackathon-1
TERARIUM_HOST_PORT?=8190
TERARIUM_API_KEY?=
TERARIUM_ENV_ARGS:= $(if $(TERARIUM_API_KEY),-e FUNMAN_API_TOKEN=$(TERARIUM_API_KEY),)
MAKE := make --no-print-directory
.PHONY: docs
docker-as-root:
touch .docker-as-root
venv:
test -d .venv || python -m venv .venv
source .venv/bin/activate && pip install -Ur requirements-dev.txt
source .venv/bin/activate && pip install -Ur requirements-dev-extras.txt
docs:
sphinx-apidoc -f -o ./docs/source ./src/funman -t ./docs/apidoc_templates --no-toc
mkdir -p ./docs/source/_static
mkdir -p ./docs/source/_templates
pyreverse \
-k \
-d ./docs/source/_static \
./src/funman
cd docs && $(MAKE) clean html
init-pages:
@if [ -n "$$(git ls-remote --exit-code $(DOCS_REMOTE) gh-pages)" ]; then echo "GitHub Pages already initialized"; exit 1; fi;
git switch --orphan gh-pages
git commit --allow-empty -m "initial pages"
git push -u $(DOCS_REMOTE) gh-pages
git checkout main
git branch -D gh-pages
deploy-pages:
mv docs/build/html www
touch www/.nojekyll
rm www/.buildinfo || true
git checkout --track $(DOCS_REMOTE)/gh-pages
rm -r docs || true
mv www docs
git add -f docs
git commit -m "update pages" || true
git push $(DOCS_REMOTE)
git checkout main
git branch -D gh-pages
local-registry:
docker start local_registry \
|| docker run -d \
--name local_registry \
--network host \
registry:2
use-docker-driver: local-registry
docker buildx use funman-builder \
|| docker buildx create \
--name funman-builder \
--use \
--driver-opt network=host
build-ibex: use-docker-driver
DOCKER_BUILDKIT=1 docker buildx build \
--output "type=docker" \
--build-arg ENABLE_DEBUG=$(DEBUG_IBEX) \
--platform $(TARGET_OS)/$(SHELL_GET_TARGET_ARCH) \
--tag $(IBEX_TAGGED_NAME) \
-f ./ibex/Dockerfile ./ibex
docker tag $(IBEX_TAGGED_NAME) $(SIFT_REGISTRY_ROOT)$(IBEX_TAGGED_NAME)
docker push $(SIFT_REGISTRY_ROOT)$(IBEX_TAGGED_NAME)
multiplatform-build-ibex: use-docker-driver
DOCKER_BUILDKIT=1 docker buildx build \
--network=host \
--output "type=registry" \
--platform linux/arm64,linux/amd64 \
--tag $(SIFT_REGISTRY_ROOT)$(IBEX_NAME):$(MULTIPLATFORM_TAG) \
-f ./ibex/Dockerfile ./ibex
build-dreal: use-docker-driver build-ibex
DOCKER_BUILDKIT=1 docker buildx build \
--output "type=docker" \
--platform $(TARGET_OS)/$(SHELL_GET_TARGET_ARCH) \
--build-arg SIFT_REGISTRY_ROOT=$(SIFT_REGISTRY_ROOT) \
-t $(DREAL_TAGGED_NAME) \
-f ./Dockerfile.dreal4 .
docker tag $(DREAL_TAGGED_NAME) $(SIFT_REGISTRY_ROOT)$(DREAL_TAGGED_NAME)
docker push $(SIFT_REGISTRY_ROOT)$(DREAL_TAGGED_NAME)
multiplatform-build-dreal: use-docker-driver multiplatform-build-ibex
DOCKER_BUILDKIT=1 docker buildx build \
--network=host \
--output "type=registry" \
--platform linux/arm64,linux/amd64 \
--build-arg SIFT_REGISTRY_ROOT=$(SIFT_REGISTRY_ROOT) \
--build-arg IBEX_TAG=$(MULTIPLATFORM_TAG) \
--tag $(SIFT_REGISTRY_ROOT)$(DREAL_NAME):$(MULTIPLATFORM_TAG) \
-f ./Dockerfile.dreal4 .
build-docker: use-docker-driver build-dreal
DOCKER_BUILDKIT=1 docker buildx build \
--output "type=docker" \
--platform $(TARGET_OS)/$(SHELL_GET_TARGET_ARCH) \
--build-arg SIFT_REGISTRY_ROOT=$(SIFT_REGISTRY_ROOT) \
$(if $(filter 0,$(FUNMAN_SKIP_USER_ARGS)), --build-arg UNAME=$(FUNMAN_USER)) \
$(if $(filter 0,$(FUNMAN_SKIP_USER_ARGS)), --build-arg UID=$$(id -u)) \
$(if $(filter 0,$(FUNMAN_SKIP_USER_ARGS)), --build-arg GID=$$(id -g)) \
-t ${DEV_TAGGED_NAME} -f ./$(FUNMAN_DEV_DOCKERFILE) .
docker tag $(DEV_TAGGED_NAME) $(SIFT_REGISTRY_ROOT)$(DEV_TAGGED_NAME)
docker push $(SIFT_REGISTRY_ROOT)$(DEV_TAGGED_NAME)
multiplatform: use-docker-driver multiplatform-build-dreal
DOCKER_BUILDKIT=1 docker buildx build \
--network=host \
--output "type=registry" \
--platform linux/arm64,linux/amd64 \
--build-arg SIFT_REGISTRY_ROOT=$(SIFT_REGISTRY_ROOT) \
--build-arg DREAL_TAG=$(MULTIPLATFORM_TAG) \
--tag $(SIFT_REGISTRY_ROOT)$(DEV_NAME):$(MULTIPLATFORM_TAG) \
-f ./Dockerfile .
build: build-docker
debug:
DEBUG_IBEX=yes make build-docker
build-deploy-base: use-docker-driver build-dreal
DOCKER_BUILDKIT=1 docker buildx build \
--output "type=docker" \
--platform $(TARGET_OS)/$(SHELL_GET_TARGET_ARCH) \
--build-arg SIFT_REGISTRY_ROOT=$(SIFT_REGISTRY_ROOT) \
-t ${DEPLOY_TAGGED_BASE_NAME} ./deploy/base
docker tag $(DEPLOY_TAGGED_BASE_NAME) $(SIFT_REGISTRY_ROOT)$(DEPLOY_TAGGED_BASE_NAME)
docker push $(SIFT_REGISTRY_ROOT)$(DEPLOY_TAGGED_BASE_NAME)
build-deploy-git: use-docker-driver build-dreal build-deploy-base
DOCKER_BUILDKIT=1 docker buildx build --no-cache \
--output "type=docker" \
--platform $(TARGET_OS)/$(SHELL_GET_TARGET_ARCH) \
--build-arg SIFT_REGISTRY_ROOT=$(SIFT_REGISTRY_ROOT) \
--build-arg FUNMAN_BRANCH=$(FUNMAN_BRANCH) \
-t ${DEPLOY_TAGGED_GIT_NAME} ./deploy/git
docker tag $(DEPLOY_TAGGED_GIT_NAME) $(SIFT_REGISTRY_ROOT)$(DEPLOY_TAGGED_GIT_NAME)
docker push $(SIFT_REGISTRY_ROOT)$(DEPLOY_TAGGED_GIT_NAME)
build-deploy-pypi: use-docker-driver build-dreal build-deploy-base
DOCKER_BUILDKIT=1 docker buildx build --no-cache \
--output "type=docker" \
--platform $(TARGET_OS)/$(SHELL_GET_TARGET_ARCH) \
--build-arg SIFT_REGISTRY_ROOT=$(SIFT_REGISTRY_ROOT) \
-t ${DEPLOY_TAGGED_PYPI_NAME} ./deploy/pypi
docker tag $(DEPLOY_TAGGED_PYPI_NAME) $(SIFT_REGISTRY_ROOT)$(DEPLOY_TAGGED_PYPI_NAME)
docker push $(SIFT_REGISTRY_ROOT)$(DEPLOY_TAGGED_PYPI_NAME)
build-deploy-api-from-git: use-docker-driver build-dreal build-deploy-git
DOCKER_BUILDKIT=1 docker buildx build --no-cache \
--output "type=docker" \
--platform $(TARGET_OS)/$(SHELL_GET_TARGET_ARCH) \
--build-arg SIFT_REGISTRY_ROOT=$(SIFT_REGISTRY_ROOT) \
--build-arg FROM_IMAGE=$(DEPLOY_GIT_NAME) \
--build-arg FUNMAN_BRANCH=$(FUNMAN_BRANCH) \
-t ${DEPLOY_TAGGED_API_NAME} ./deploy/api
docker tag $(DEPLOY_TAGGED_API_NAME) $(SIFT_REGISTRY_ROOT)$(DEPLOY_TAGGED_API_NAME)
docker push $(SIFT_REGISTRY_ROOT)$(DEPLOY_TAGGED_API_NAME)
build-deploy-api-from-pypi: use-docker-driver build-dreal build-deploy-pypi
DOCKER_BUILDKIT=1 docker buildx build --no-cache \
--output "type=docker" \
--platform $(TARGET_OS)/$(SHELL_GET_TARGET_ARCH) \
--build-arg SIFT_REGISTRY_ROOT=$(SIFT_REGISTRY_ROOT) \
--build-arg FROM_IMAGE=$(DEPLOY_PYPI_NAME) \
-t ${DEPLOY_TAGGED_API_NAME} ./deploy/api
docker tag $(DEPLOY_TAGGED_API_NAME) $(SIFT_REGISTRY_ROOT)$(DEPLOY_TAGGED_API_NAME)
docker push $(SIFT_REGISTRY_ROOT)$(DEPLOY_TAGGED_API_NAME)
run-api-server:
docker run -it --rm -p 127.0.0.1:8190:8190 $(DEPLOY_TAGGED_API_NAME)
run-docker:
@FUNMAN_HOME=$(if $(filter 0,$(FUNMAN_SKIP_USER_ARGS)),/home/$$USER,/root) \
&& if [ -e "$(DREAL_LOCAL_REPO)" ] ; then \
DREAL_LOCAL_VOLUME_CMD=-v ; \
DREAL_LOCAL_VOLUME_ARG=$$(realpath $(DREAL_LOCAL_REPO)):$$FUNMAN_HOME/dreal4:rw ; \
else \
echo "WARNING: Dreal4 repo not found at $(DREAL_LOCAL_REPO)" ; \
DREAL_LOCAL_VOLUME_CMD= ; \
DREAL_LOCAL_VOLUME_ARG= ; \
fi \
&& docker run \
-d \
-it \
--cpus=5 \
--cap-add=SYS_PTRACE \
--name ${DEV_CONTAINER} \
-p 127.0.0.1:$(FUNMAN_BASE_PORT):8888 \
-p 127.0.0.1:$$(($(FUNMAN_BASE_PORT) + 1)):8190 \
-v $$PWD:$$FUNMAN_HOME/funman:rw $$DREAL_LOCAL_VOLUME_CMD $$DREAL_LOCAL_VOLUME_ARG \
${DEV_TAGGED_NAME}
run-docker-se:
docker run \
-d \
-it \
--cpus=8 \
--name ${DEV_CONTAINER} \
-p 127.0.0.1:8888:8888 \
-v $$PWD:/home/$$USER/funman:Z \
--userns=keep-id \
${DEV_TAGGED_NAME}
delete-dev-container:
@echo "Deleting dev container:"
docker stop ${DEV_CONTAINER}
docker rm ${DEV_CONTAINER}
delete-dev-container-if-out-of-date:
@if (docker container inspect ${DEV_CONTAINER} > /dev/null 2>&1) ; then \
FUNMAN_CONTAINER_SHA=$$(docker inspect -f '{{.Image}}' ${DEV_CONTAINER}) ; \
FUNMAN_IMAGE_SHA=$$(docker images --no-trunc --quiet ${DEV_TAGGED_NAME}) ; \
if [ "$$FUNMAN_IMAGE_SHA" != "$$FUNMAN_CONTAINER_SHA" ] ; then \
echo "Dev container out of date:" ; \
echo " Container: $$FUNMAN_CONTAINER_SHA" ; \
echo " Image: $$FUNMAN_IMAGE_SHA" ; \
$(MAKE) delete-dev-container ; \
fi \
fi
launch-dev-container:
@$(MAKE) delete-dev-container-if-out-of-date
@docker container inspect ${DEV_CONTAINER} > /dev/null 2>&1 \
|| $(MAKE) run-docker TARGET_ARCH=$(SHELL_GET_TARGET_ARCH)
@test $$(docker container inspect -f '{{.State.Running}}' ${DEV_CONTAINER}) == 'true' > /dev/null 2>&1 \
|| docker start ${DEV_CONTAINER}
@docker attach ${DEV_CONTAINER}
rm-dev-container:
@docker container rm ${DEV_CONTAINER}
install-pre-commit-hooks:
@pre-commit install
format:
pycln --config pyproject.toml .
isort --settings-path pyproject.toml .
black --config pyproject.toml .
update-versions:
@test "${FUNMAN_VERSION}" != "0.0.0" || (echo "ERROR: FUNMAN_VERSION must be set" && exit 1)
@${CMD_UPDATE_VERSION} auxiliary_packages/funman_demo/src/funman_demo/_version.py
@${CMD_UPDATE_VERSION} auxiliary_packages/funman_dreal/src/funman_dreal/_version.py
@${CMD_UPDATE_VERSION} src/funman/_version.py
dist: update-versions
mkdir -p dist
mkdir -p dist.bkp
rsync -av --ignore-existing --remove-source-files dist/ dist.bkp/
python -m build --outdir ./dist .
python -m build --outdir ./dist auxiliary_packages/funman_demo
python -m build --outdir ./dist auxiliary_packages/funman_dreal
check-test-release: dist
@echo -e "\nReleasing the following packages to TestPyPI:"
@ls -1 dist | sed -e 's/^/ /'
@echo -n -e "\nAre you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
test-release: check-test-release
python3 -m twine upload --repository testpypi dist/*
check-release: dist
@echo -e "\nReleasing the following packages to PyPI:"
@ls -1 dist | sed -e 's/^/ /'
@echo -n -e "\nAre you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
release: check-release
python3 -m twine upload dist/*
# TODO simplify the targets
docker-hub:
# build ibex
DOCKER_BUILDKIT=1 docker buildx build \
--network=host \
--output "type=registry" \
--platform $(DOCKER_HUB_PLATFORMS) \
--tag $(DOCKER_HUB_ORG)/$(IBEX_NAME):$(DOCKER_HUB_TAG) \
-f ./ibex/Dockerfile ./ibex
# build dreal
DOCKER_BUILDKIT=1 docker buildx build \
--network=host \
--output "type=registry" \
--platform $(DOCKER_HUB_PLATFORMS) \
--build-arg SIFT_REGISTRY_ROOT=$(DOCKER_HUB_ORG)/ \
--build-arg IBEX_TAG=$(DOCKER_HUB_TAG) \
--tag $(DOCKER_HUB_ORG)/$(DREAL_NAME):$(DOCKER_HUB_TAG) \
-f ./Dockerfile.dreal4 .
# build funman-base
DOCKER_BUILDKIT=1 docker buildx build \
--network=host \
--output "type=registry" \
--platform $(DOCKER_HUB_PLATFORMS) \
--build-arg SIFT_REGISTRY_ROOT=$(DOCKER_HUB_ORG)/ \
--build-arg DREAL_TAG=$(DOCKER_HUB_TAG) \
--tag $(DOCKER_HUB_ORG)/$(DEPLOY_BASE_NAME):$(DOCKER_HUB_TAG) \
./deploy/base
# build funman-git
DOCKER_BUILDKIT=1 docker buildx build \
--network=host \
--output "type=registry" \
--platform $(DOCKER_HUB_PLATFORMS) \
--build-arg SIFT_REGISTRY_ROOT=$(DOCKER_HUB_ORG)/ \
--build-arg FUNMAN_BRANCH=$(FUNMAN_BRANCH) \
--build-arg FROM_TAG=$(DOCKER_HUB_TAG) \
--tag $(DOCKER_HUB_ORG)/$(DEPLOY_GIT_NAME):$(DOCKER_HUB_TAG) \
./deploy/git
# build funman-api-server
DOCKER_BUILDKIT=1 docker buildx build \
--network=host \
--output "type=registry" \
--platform $(DOCKER_HUB_PLATFORMS) \
--build-arg SIFT_REGISTRY_ROOT=$(DOCKER_HUB_ORG)/ \
--build-arg FROM_IMAGE=$(DEPLOY_GIT_NAME) \
--build-arg FROM_TAG=$(DOCKER_HUB_TAG) \
--tag $(DOCKER_HUB_ORG)/$(DEPLOY_API_NAME):$(DOCKER_HUB_TAG) \
./deploy/api
build-terarium:
docker build ./deploy/terarium
run-terarium:
docker run -it --rm \
-p 0.0.0.0:$(TERARIUM_HOST_PORT):8190 $(TERARIUM_ENV_ARGS) \
$(DOCKER_HUB_ORG)/$(DEPLOY_API_NAME):$(DOCKER_HUB_TAG)
generate-api-client:
pip install openapi-python-client
openapi-python-client --install-completion
uvicorn funman.api.api:app --host 0.0.0.0 --port 8190 &
sleep 1
openapi-python-client generate --url http://0.0.0.0:8190/openapi.json
pip install -e funman-api-client
update-api-client:
openapi-python-client update --url http://0.0.0.0:8190/openapi.json