This repository has been archived by the owner on Oct 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
170 lines (145 loc) · 6.3 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
SHELL:=/bin/bash
NAMESPACE?=oisp
# Name for HELM deployment
NAME?=oisp
NAMESPACE_LOCUST?=locust
NAME_LOCUST?=locust
TEMPLATES_DIR?=templates
DEPLOYMENT?=debugger
DEBUGGER_POD:=$(shell kubectl -n $(NAMESPACE) get pods -o custom-columns=:metadata.name | grep debugger | head -n 1)
DASHBOARD_POD:=$(shell kubectl -n $(NAMESPACE) get pods -o custom-columns=:metadata.name | grep dashboard | head -n 1)
SELECTED_POD:=$(shell kubectl -n $(NAMESPACE) get pods -o custom-columns=:metadata.name | grep $(DEPLOYMENT) | head -n 1)
HBASE_MASTER_POD=$(shell kubectl -n $(NAMESPACE) get pods -o custom-columns=:metadata.name | grep hbase-master | head -n 1)
TEST_REPO?=https://github.com/Open-IoT-Service-Platform/platform-launcher.git
TEST_BRANCH?=develop
# Deployment with kubectl
# -----------------------------------------------------------------------------
# Use these functions if you do not have HELM running on your cluster,
# otherwise, deploying the charts is the recommended method
## .docker-cred: Remove this file if you need to update docker credentials
##
.docker-cred:
@$(call msg, "(Re)creating docker credential secret.")
@kubectl create namespace $(NAMESPACE) 2>/dev/null || echo Namespace $(NAMESPACE) already exists
@kubectl -n $(NAMESPACE) delete secret dockercred 2>/dev/null ||:
@read -p "Docker username:" DOCKER_USERNAME; \
read -p "Docker e-mail:" DOCKER_EMAIL; \
read -s -p "Docker password:" DOCKER_PASSWORD; \
echo -e "\nTesting login"; \
docker login -u $$DOCKER_USERNAME -p $$DOCKER_PASSWORD 2>/dev/null|| exit 1; \
kubectl -n $(NAMESPACE) create secret docker-registry dockercred --docker-username=$$DOCKER_USERNAME --docker-password=$$DOCKER_PASSWORD --docker-email=$$DOCKER_EMAIL;
@touch $@
## clean: Remove all k8s resources by deleting namespace
##
clean:
@$(call msg, "Removing workspace $(NAMESPACE)")
-kubectl delete namespace $(NAMESPACE)
rm -f .docker-cred
check-docker-cred-env:
@if [ "$$DOCKERUSER" = "" ]; then \
echo "DOCKERUSER env var is undefined"; exit 1; \
fi
@if [ "$$DOCKERPASS" = "" ]; then \
echo "DOCKERPASS env var is undefined"; exit 1; \
fi
## deploy-oisp-test: Deploy repository as HELM chart,
## create an ethereal address, and make sure there is
## a debugger container.
##
deploy-oisp-test: check-docker-cred-env
node ./util/ethereal.js util/ethereal_creds;
. util/ethereal_creds && \
helm install . --name $(NAME) --namespace $(NAMESPACE) \
--set imageCredentials.username="$$DOCKERUSER" \
--set imageCredentials.password="$$DOCKERPASS" \
--set smtp.host="$$SMTP_HOST" \
--set smtp.port="$$SMTP_PORT" \
--set smtp.username="$$SMTP_USERNAME" \
--set smtp.password="$$SMTP_PASSWORD" \
--set imap.host="$$IMAP_HOST" \
--set imap.port="$$IMAP_PORT" \
--set imap.username="$$IMAP_USERNAME" \
--set imap.password="$$IMAP_PASSWORD" \
--set numberReplicas.debugger=1;
## deploy-oisp: Deploy repository as HELM chart
##
deploy-oisp: check-docker-cred-env
@helm install . --name $(NAME) --namespace $(NAMESPACE) \
--set imageCredentials.username="$$DOCKERUSER" \
--set imageCredentials.password="$$DOCKERPASS";
## undeploy-oisp: Remove OISP deployment by HELM chart
##
undeploy-oisp:
helm del $(NAME) --purge
kubectl delete namespace $(NAMESPACE)
# Utils
# ---------------------------------------------------------------------
## open-shell: Open a shell to a random pod in DEPLOYMENT.
## By default thi will try to open a shell to a debugger pod.
##
open-shell:
@$(call msg, "Opening shell to pod: $(DEBUGGER_POD)")
kubectl -n $(NAMESPACE) exec -it $(SELECTED_POD) /bin/bash
## reset-db: Reset database via admin tool in frontend
##
reset-db:
kubectl -n $(NAMESPACE) exec $(DASHBOARD_POD) --container dashboard -- node admin resetDB
## add-test-user: Add a test user via admin tool in frontend
##
add-test-user:
for i in $(shell seq 1 1); do kubectl -n $(NAMESPACE) exec $(DASHBOARD_POD) -c dashboard -- node admin addUser user$${i}@example.com password admin; done;
## prepare-tests: Pull the latest repo in the debugger pod
## This has no permanent effect as the pod on which the tests
## are prepared is mortal
prepare-tests:
kubectl -n $(NAMESPACE) exec $(DEBUGGER_POD) -c debugger -- /bin/bash -c "rm -rf *"
kubectl -n $(NAMESPACE) exec $(DEBUGGER_POD) -c debugger -- /bin/bash -c "rm -rf .* || true"
kubectl -n $(NAMESPACE) exec $(DEBUGGER_POD) -c debugger -- \
git clone $(TEST_REPO) -b $(TEST_BRANCH) .
## test: Run tests
## Platform launcher will be cloned from TEST_REPO, branch TEST_BRANCH will be used
## Assumes that the platform is already deployed
##
test: prepare-tests
kubectl -n $(NAMESPACE) exec $(DEBUGGER_POD) -c debugger \
-- /bin/bash -c "cp setup-environment.example.sh setup-environment.sh && cd tests && make test TESTING_PLATFORM=kubernetes TERM=xterm"
## proxy: Run kubectl proxy and port-forwarding of various pods
##
proxy:
-kubectl proxy &
-kubectl -n $(NAMESPACE) port-forward $(HBASE_MASTER_POD) 16010:16010
## help: Show this help message
##
help:
@grep "^##" Makefile | cut -c4-
## wait-until-ready: Wait until the platform is up and running
## As of now, this is assumed if all dashboard and backend containers
## are ready.
##
wait-until-ready:
@printf "\nWaiting for pending ";
@while kubectl -n oisp get pods | grep Pending >> /dev/null; \
do printf "."; sleep 5; done;
@printf "Waiting for backend ";
@while kubectl -n oisp get pods -l=app=backend -o \
jsonpath="{.items[*].status.containerStatuses[*].ready}" | grep false >> /dev/null; \
do printf "."; sleep 5; done;
@printf "\nWaiting for frontend ";
@while kubectl -n oisp get pods -l=app=dashboard -o \
jsonpath="{.items[*].status.containerStatuses[*].ready}" | grep false >> /dev/null; \
do printf "."; sleep 5; done;
@printf "\nWaiting for mqtt server";
@while kubectl -n oisp get pods -l=app=mqtt-server -o \
jsonpath="{.items[*].status.containerStatuses[*].ready}" | grep false >> /dev/null; \
do printf "."; sleep 5; done;
@echo
#---------------------------------------------------------------------------------------------------
# helper functions
#---------------------------------------------------------------------------------------------------
define msg
tput setaf 2 && \
for i in $(shell seq 1 120 ); do echo -n "-"; done; echo "" && \
echo -e "\t"$1 && \
for i in $(shell seq 1 120 ); do echo -n "-"; done; echo "" && \
tput sgr0
endef