-
Notifications
You must be signed in to change notification settings - Fork 25
/
Makefile
216 lines (173 loc) · 5.86 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
IMAGE_REGISTRY ?= quay.io/sustainable_computing_io
IMAGE_NAME := kepler_model_server
IMAGE_VERSION ?= v$(shell cat VERSION)
KEPLER_IMAGE_NAME := kepler
KEPLER_IMAGE_VERSION ?= release-0.7.11
IMAGE ?= $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_VERSION)
KEPLER_IMAGE ?= $(IMAGE_REGISTRY)/$(KEPLER_IMAGE_NAME):$(KEPLER_IMAGE_VERSION)
BASE_IMAGE ?= $(IMAGE_REGISTRY)/$(IMAGE_NAME)_base:$(IMAGE_VERSION)
TEST_IMAGE := $(IMAGE)-test
CTR_CMD ?= docker
PYTHON := python3.10
DOCKERFILES_PATH := ./dockerfiles
MODEL_PATH := ${PWD}/tests/models
.PHONY: fmt
fmt:
@hatch fmt -f
.PHONY: lint
lint:
@hatch run pymarkdownlnt scan -r .
@hatch run yamllint -c ./.yamllint.yaml --strict .
.PHONY: build
build:
$(CTR_CMD) build -t $(IMAGE) -f $(DOCKERFILES_PATH)/Dockerfile .
.PHONY: build-base
build-base:
$(CTR_CMD) build -t $(BASE_IMAGE) -f $(DOCKERFILES_PATH)/Dockerfile.base .
.PHONY: build-test-nobase
build-test-nobase:
$(CTR_CMD) build -t $(TEST_IMAGE) -f $(DOCKERFILES_PATH)/Dockerfile.test-nobase .
.PHONY: build-test
build-test:
$(CTR_CMD) build -t $(TEST_IMAGE) -f $(DOCKERFILES_PATH)/Dockerfile.test .
.PHONY: push
push:
$(CTR_CMD) push $(IMAGE)
.PHONY: push-base
push-base:
$(CTR_CMD) push $(BASE_IMAGE)
.PHONY: push-test
push-test:
$(CTR_CMD) push $(TEST_IMAGE)
exec-test:
$(CTR_CMD) run --platform linux/amd64 -it $(TEST_IMAGE) /bin/bash
test-pipeline:
mkdir -p ${MODEL_PATH}
$(CTR_CMD) run --rm --platform linux/amd64 \
-v ${MODEL_PATH}:/mnt/models -i \
$(TEST_IMAGE) \
hatch run test -vvv -s ./tests/pipeline_test.py
# test collector --> estimator
run-estimator:
$(CTR_CMD) run --rm -d --platform linux/amd64 \
-e "MODEL_TOPURL=http://localhost:8110" \
-v ${MODEL_PATH}:/mnt/models \
-p 8100:8100 \
--name estimator \
$(TEST_IMAGE) \
/bin/bash -c "$(PYTHON) tests/http_server.py & sleep 5 && estimator --log-level debug"
run-estimator-with-test-spec:
$(CTR_CMD) run --rm -d --platform linux/amd64 \
--name estimator \
$(TEST_IMAGE) \
/bin/bash -c "estimator --machine-spec tests/data/machine/spec.json --log-level debug"
run-collector-client:
$(CTR_CMD) exec estimator /bin/bash -c \
"while [ ! -S "/tmp/estimator.sock" ]; do \
sleep 1; \
done; \
hatch run test -vvv -s ./tests/estimator_power_request_test.py"
clean-estimator:
@$(CTR_CMD) logs estimator
@$(CTR_CMD) stop estimator
@$(CTR_CMD) rm estimator || true
test-estimator: run-estimator run-collector-client clean-estimator
run-model-server:
$(CTR_CMD) run --rm -d --platform linux/amd64 \
-e "MODEL_TOPURL=http://localhost:8110" \
-v ${MODEL_PATH}:/mnt/models \
-p 8100:8100 \
--name model-server $(TEST_IMAGE) \
/bin/bash -c "$(PYTHON) tests/http_server.py & sleep 10 && model-server --log-level debug"; \
while ! $(CTR_CMD) logs model-server 2>&1 | grep -q 'Running on all'; do \
echo "... waiting for model-server to serve"; sleep 5; \
done
run-estimator-client:
$(CTR_CMD) exec model-server \
hatch run test -vvv -s ./tests/estimator_model_request_test.py
clean-model-server:
@$(CTR_CMD) logs model-server
@$(CTR_CMD) stop model-server
@$(CTR_CMD) rm model-server || true
test-model-server: \
run-model-server \
run-estimator-client \
clean-model-server
# test offline trainer
run-offline-trainer:
$(CTR_CMD) run -d --rm --platform linux/amd64 \
-p 8102:8102 \
--name offline-trainer \
$(TEST_IMAGE) \
offline-trainer
sleep 5
run-offline-trainer-client:
$(CTR_CMD) exec offline-trainer \
hatch run test -vvv -s ./tests/offline_trainer_test.py
clean-offline-trainer:
@$(CTR_CMD) stop offline-trainer
test-offline-trainer: \
run-offline-trainer \
run-offline-trainer-client \
clean-offline-trainer
# test model server select
create-container-net:
@$(CTR_CMD) network create kepler-model-server-test
run-model-server-with-db:
$(CTR_CMD) run -d --platform linux/amd64 \
--network kepler-model-server-test \
-p 8100:8100 \
--name model-server $(TEST_IMAGE) \
model-server
while ! $(CTR_CMD) logs model-server 2>&1 | grep -q 'Running on all'; do \
echo "... waiting for model-server to serve"; sleep 5; \
done
run-estimator-with-model-server:
$(CTR_CMD) run -d --platform linux/amd64 \
--network kepler-model-server-test \
-e "MODEL_SERVER_ENABLE=true" \
-e "MODEL_SERVER_URL=http://model-server:8100" \
--name estimator $(TEST_IMAGE) \
/bin/bash -c "estimator --machine-spec tests/data/machine/spec.json"
clean-container-net:
@$(CTR_CMD) network rm kepler-model-server-test
run-select-client:
$(CTR_CMD) exec model-server \
hatch run test -vvv -s ./tests/model_select_test.py
test-model-server-select: create-container-net run-model-server-with-db run-select-client clean-model-server clean-container-net
test-model-server-estimator-select: create-container-net run-model-server-with-db run-estimator-with-model-server run-collector-client clean-estimator clean-model-server clean-container-net
test: \
build-test \
test-pipeline \
test-estimator \
test-model-server \
test-offline-trainer \
test-model-server-select \
test-model-server-estimator-select
# set image
set-image:
@cd ./manifests/base && kustomize edit set image kepler_model_server=$(IMAGE)
@cd ./manifests/server && kustomize edit set image kepler_model_server=$(IMAGE)
@cd ./manifests/kepler && kustomize edit set image kepler=$(KEPLER_IMAGE)
# deploy
_deploy:
@$(MAKE) set-image
@kustomize build ./manifests/base|kubectl apply -f -
# print
_print:
@$(MAKE) set-image
@kustomize build ./manifests/base|cat
cleanup:
kustomize build manifests/base|kubectl delete -f -
deploy:
@chmod +x ./manifests/set.sh
@./manifests/set.sh "${OPTS}"
@$(MAKE) _deploy
manifest:
@chmod +x ./manifests/set.sh
@./manifests/set.sh "${OPTS}"
@$(MAKE) _print
patch-power-request-client:
kubectl patch ds kepler-exporter -n kepler --patch-file ./manifests/test/power-request-client.yaml
patch-model-request-client:
kubectl patch ds kepler-exporter -n kepler --patch-file ./manifests/test/model-request-client.yaml