-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
106 lines (80 loc) · 4.31 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
DC=docker
UNAME_S := $(shell uname -s)
NAME=ml-py-stevedore
## Google cloud deployment values
PROJECT=
REGION=
ORGANIZATION=
BILLING=
.PHONY: help
help: ## *:・゚✧*:・゚✧ This help *:・゚✧*:・゚✧
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m[ \033[36m%-16s \033[33m]\033[0m %s\n", $$1, $$2}'
-: ## === Local Development ===
local-run: local-stop local-build ## Start Docker service
$(DC) run -d -p 8000:8000 --rm --name $(NAME) $(NAME)
$(DC) logs -f $(NAME)
local-run-alternative: local-stop local-build ## Start Docker service with alternative model
$(DC) run -d -p 8000:8000 --rm --name $(NAME) -v $$(pwd)/alternative_model:/service/model $(NAME)
$(DC) logs -f $(NAME)
local-build: ## Build container for running
$(DC) build -t $(NAME) .
local-shell: ## Run shell in container for debugging
$(DC) run --rm -ti $(NAME) bash -l
local-stop: ## Stop all services
$(DC) stop -t 0 $(NAME) || true
local-test-curl: ## Test service with curl
curl -f -s -D /dev/stderr http://localhost:8000/health/live || echo Failed; echo
curl -f -s -D /dev/stderr http://localhost:8000/readyz || echo Failed; echo
curl -f -s -D /dev/stderr -X GET http://localhost:8000/health/ready/?model=test_logreg1 || echo Failed; echo
curl -f -s -D /dev/stderr -X GET http://localhost:8000/version/?model=test_logreg1 || echo Failed; echo
curl -f -s -D /dev/stderr http://localhost:8000/docs >/dev/null || echo Failed; echo
curl -f -s -D /dev/stderr http://localhost:8000/health/uptime || echo Failed; echo
curl -f -s -D /dev/stderr -X 'POST' \
'http://localhost:8000/predict/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{ "predictor": "test_logreg1", "payload": [[1,2,3]]}' || echo Failed; echo
local-test-curl-alternative: ## Test service with curl when using alternative model
curl -f -s -D /dev/stderr http://localhost:8000/health/live || echo Failed; echo;
curl -f -s -D /dev/stderr http://localhost:8000/readyz || echo Failed; echo;
curl -f -s -D /dev/stderr -X GET http://localhost:8000/health/ready/?model=test_logreg3 || echo Failed; echo;
curl -f -s -D /dev/stderr -X GET http://localhost:8000/version/?model=test_logreg3 || echo Failed; echo;
curl -f -s -D /dev/stderr http://localhost:8000/docs >/dev/null || echo Failed; echo;
curl -f -s -D /dev/stderr http://localhost:8000/health/uptime || echo Failed; echo;
curl -f -s -D /dev/stderr -X 'POST' \
'http://localhost:8000/predict/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{ "predictor": "test_logreg3", "payload": [[0,0,0],[10,10,10]]}' || echo Failed; echo
local-pytest: local-build ## Run testcases in container
$(DC) run --rm --name $(NAME)-test \
--entrypoint /service/pytest.sh \
$(NAME)
local-pytest-alternative: local-build ## Run testcases in container
$(DC) run --rm --name $(NAME)-test -v $$(pwd)/alternative_model:/service/model \
--entrypoint /service/pytest.sh \
$(NAME)
-: ## === Cloud Deploy ===
## Google
g-create-project: ## Create project
gcloud projects create $(PROJECT) --enable-cloud-apis --organization=$(ORGANIZATION)
gcloud alpha billing projects link $(PROJECT) --billing-account=$(BILLING)
gcloud --project=$(PROJECT) services enable cloudbuild.googleapis.com
g-build-image: ## Submit to google cloud
gcloud --project=$(PROJECT) builds submit --tag gcr.io/$(PROJECT)/$(NAME):latest --timeout=2h
g-deploy-service: ## Submit to google cloud
gcloud --project=$(PROJECT) run deploy $(NAME) --image=gcr.io/$(PROJECT)/$(NAME):latest --region=$(REGION) --port=8000
g-test-service: ## send test file
bash -x -e -c "\
URL=$$( gcloud --project=$(PROJECT) run services describe $(NAME) --region=$(REGION) --format=json | jq .status.url ); \
curl -f -s -D /dev/stderr \$$URL/health/live ; echo; \
curl -f -s -D /dev/stderr \$$URL/readyz; echo; \
curl -f -s -D /dev/stderr -X GET \$$URL/health/ready/?model=test_logreg1; echo; \
curl -f -s -D /dev/stderr -X GET \$$URL/version/?model=test_logreg1 ; echo; \
"
g-delete-service: ## Stop service
gcloud --project=$(PROJECT) run services delete $(NAME) --region=$(REGION)
g-delete-image: ## Stop service
gcloud --project=$(PROJECT) container images delete gcr.io/$(PROJECT)/$(NAME) --force-delete-tags
g-delete-project: ## Delete project
gcloud projects delete $(PROJECT)