This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
/
Makefile
366 lines (309 loc) · 9.08 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
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
#
# To start a DCOS cluster with the defaults (OSS edition):
# make dcos
#
# To start a DCOS cluster with EE:
# DCOS_LICENSE_KEY_PATH=${HOME}/license.txt \
# DCOS_E2E_VARIANT=enterprise \
# make dcos
#
# By default the installers are kept in ./.cache which is removed
# during `make clean`. Specifying a location outside this repo for
# `DCOS_E2E_INSTALLERS_DIR` prevents redownloading:
#
# DCOS_E2E_INSTALLERS_DIR=${HOME}/dcos/installers make dcos
#
# To start a shell with the env pointing to a dcos cluster
# make cluster-env shell
THIS_PATH := $(strip $(realpath $(dir $(realpath \
$(lastword $(MAKEFILE_LIST))))))
# Default overridable varables
MLB_VERSION ?= $(shell git rev-parse --short HEAD || echo dev)
CONTAINTER_REPO ?= mesosphere-ci/marathon-lb
CONTAINER_TAG ?= $(MLB_VERSION)
DEVKIT_CONTAINTER_REPO ?= mesosphere/marathon-lb-devkit
DEVKIT_CONTAINER_TAG ?= latest
DEVKIT_CONTAINER_NAME ?= marathon-lb-devkit
DCOS_E2E_WORKSPACE_DIR ?= $(THIS_PATH)/.cache/dcos-e2e/workspace
DCOS_E2E_INSTALLERS_DIR ?= $(THIS_PATH)/.cache/dcos-e2e/installers
DCOS_E2E_CLUSTER_ID ?= marathon-lb-devkit
DCOS_E2E_CHANNEL ?= stable
DCOS_E2E_VERSION ?= 1.12.0
DCOS_E2E_VARIANT ?= oss
CLUSTER_URL ?=
PUBLIC_AGENT_IP ?=
DCOS_USERNAME ?= admin
DCOS_PASSWORD ?= admin
DCOS_VERSION ?= $(shell echo '$(DCOS_E2E_VERSION)' | cut -d. -f -2)
DOCKER_SOCKET ?= /var/run/docker.sock
DOCKER_HUB_USERNAME ?=
DOCKER_HUB_PASSWORD ?=
# Internal variables
MLB_PATH := $(THIS_PATH)
IMG := $(CONTAINTER_REPO):$(CONTAINER_TAG)
DEVKIT_IMG := $(DEVKIT_CONTAINTER_REPO):$(DEVKIT_CONTAINER_TAG)
MLB_CONTAINER_PATH := /marathon-lb
DEVKIT_VOL_ARGS := -v $(MLB_PATH):$(MLB_CONTAINER_PATH)
DOCKER_VOL_ARGS := -v $(DOCKER_SOCKET):/var/run/docker.sock
DCOS_E2E_INSTALLER_VOL := \
-v $(DCOS_E2E_INSTALLERS_DIR):$(DCOS_E2E_INSTALLERS_DIR)
DCOS_E2E_WORKSPACE_VOL := \
-v $(DCOS_E2E_WORKSPACE_DIR):$(DCOS_E2E_WORKSPACE_DIR)
DCOS_E2E_VOL_ARGS := \
$(DCOS_E2E_INSTALLER_VOL) \
$(DCOS_E2E_WORKSPACE_VOL)
#(TODO) Support overriding backend to use any backend
DCOS_E2E_BACKEND := docker
DCOS_E2E_NODE_TRANSPORT := docker-exec
JQ_FIND_CLUSTER_URL := jq -r -e '."Web UI" // empty'
JQ_FIND_PUBLIC_IP := jq -r -e '.Nodes.public_agents[0].ip_address // empty'
CLUSTER_ENV_ARGS = \
--env CLUSTER_URL="$(CLUSTER_URL)" \
--env PUBLIC_AGENT_IP="$(PUBLIC_AGENT_IP)" \
--env DCOS_USERNAME="$(DCOS_USERNAME)" \
--env DCOS_LOGIN_UNAME="$(DCOS_USERNAME)" \
--env DCOS_PASSWORD="$(DCOS_PASSWORD)" \
--env DCOS_LOGIN_PW="$(DCOS_PASSWORD)" \
--env DCOS_VERSION="$(DCOS_VERSION)" \
--env DCOS_E2E_BACKEND="$(DCOS_E2E_BACKEND)" \
--env DCOS_E2E_NODE_TRANSPORT="$(DCOS_E2E_NODE_TRANSPORT)" \
--env DCOS_E2E_CLUSTER_ID="$(DCOS_E2E_CLUSTER_ID)" \
--env DCOS_E2E_VARIANT="$(DCOS_E2E_VARIANT)" \
--env MARATHON_LB_IMAGE="$(IMG)" \
--env MARATHON_LB_VERSION="$(MLB_VERSION)"
CLUSTER_RUNNING := 0
ifneq ($(strip $(shell docker ps -q -f 'name=$(DCOS_E2E_CLUSTER_ID)')),)
CLUSTER_RUNNING := 1
endif
ifeq ($(strip $(CLUSTER_URL)),)
CLUSTER_TARGET := dcos
endif
ifeq ($(strip $(PUBLIC_AGENT_IP)),)
CLUSTER_TARGET := dcos
endif
DCOS_E2E_DOWNLOAD_SITE := https://downloads.dcos.io/dcos
ifeq ($(strip $(DCOS_E2E_VARIANT)), enterprise)
DCOS_E2E_DOWNLOAD_SITE := $(strip \
https://downloads.mesosphere.com/dcos-enterprise)
DCOS_E2E_FILE_TAG := .ee
DCOS_LICENSE_KEY_PATH ?=
DCOS_E2E_VOL_ARGS := \
$(DCOS_E2E_VOL_ARGS) \
-v $(DCOS_LICENSE_KEY_PATH):$(DCOS_LICENSE_KEY_PATH)
DCOS_E2E_ENV_ARGS := \
--env DCOS_LICENSE_KEY_PATH="$(DCOS_LICENSE_KEY_PATH)"
endif
DCOS_E2E_FILE := $(DCOS_E2E_VERSION)$(DCOS_E2E_FILE_TAG).sh
DCOS_E2E_DOWNLOAD_URL := $(DCOS_E2E_DOWNLOAD_SITE)/$(DCOS_E2E_CHANNEL)
DCOS_E2E_DOWNLOAD_URL := $(DCOS_E2E_DOWNLOAD_URL)/$(DCOS_E2E_VERSION)
DCOS_E2E_DOWNLOAD_URL := $(strip \
$(DCOS_E2E_DOWNLOAD_URL)/dcos_generate_config$(DCOS_E2E_FILE_TAG).sh)
.DEFAULT_GOAL := help
.PHONY: help
help:
@echo "Targets: "
@echo " clean"
@echo " Remove all artifacts/files/containers"
@echo ""
@echo " image, devkit"
@echo " Build the marathon-lb/devkit images"
@echo ""
@echo " dcos"
@echo " Start a dcos cluster with dcos-e2e"
@echo ""
@echo " shell"
@echo " Run /bin/bash in a devkit container"
@echo ""
@echo " test"
@echo " Run unit/integration tests"
.PHONY: clean-dcos-container
clean-dcos-container:
ifeq ($(CLUSTER_RUNNING), 1)
@echo "+ Cleaning up DCOS cluster-id $(DCOS_E2E_CLUSTER_ID)"
-@docker run \
--rm \
--tty \
--interactive \
$(DEVKIT_VOL_ARGS) \
$(DOCKER_VOL_ARGS) \
$(DCOS_E2E_VOL_ARGS) \
$(DEVKIT_IMG) \
minidcos \
$(DCOS_E2E_BACKEND) \
destroy --cluster-id $(DCOS_E2E_CLUSTER_ID)
endif
.PHONY: clean-devkit-container
clean-devkit-container:
ifneq ($(strip $(shell docker ps -q -f 'name=$(DEVKIT_CONTAINER_NAME)')),)
@echo "+ Cleaning up $(DEVKIT_CONTAINER_NAME) container"
-@docker rm \
--force \
--volumes \
$(DEVKIT_CONTAINER_NAME) > /dev/null 2>&1 || true
endif
.PHONY: clean
clean: clean-devkit-container \
clean-dcos-container
@echo "+ Remove files left behind"
@find . -type f -name '*.pyc' -delete
@find . -type f -name '.coverage.*' -delete
@find . -name ".pytest_cache" -type d -prune -exec rm -r "{}" \;
@find . -name "__pycache__" -type d -prune -exec rm -r "{}" \;
@rm -rf .cache
.PHONY: cluster-env
cluster-env: cluster-url cluster-public-ip
.PHONY: cluster-public-ip
cluster-public-ip: devkit $(CLUSTER_TARGET)
ifeq ($(strip $(PUBLIC_AGENT_IP)),)
@echo "+ Discovering Public Node IP"
$(eval PUBLIC_AGENT_IP := $(shell \
docker run \
--rm \
--tty \
--interactive \
$(DEVKIT_VOL_ARGS) \
$(DOCKER_VOL_ARGS) \
$(DCOS_E2E_VOL_ARGS) \
$(DEVKIT_IMG) \
minidcos \
$(DCOS_E2E_BACKEND) \
inspect --cluster-id $(DCOS_E2E_CLUSTER_ID) \
| $(JQ_FIND_PUBLIC_IP)))
endif
@echo "+ Public Node IP: $(PUBLIC_AGENT_IP)"
.PHONY: cluster-url
cluster-url: devkit $(CLUSTER_TARGET)
ifeq ($(strip $(CLUSTER_URL)),)
@echo "+ Discovering Cluster URL"
$(eval CLUSTER_URL := $(shell \
docker run \
--rm \
--tty \
--interactive \
$(DEVKIT_VOL_ARGS) \
$(DOCKER_VOL_ARGS) \
$(DCOS_E2E_VOL_ARGS) \
$(DEVKIT_IMG) \
minidcos \
$(DCOS_E2E_BACKEND) \
inspect --cluster-id $(DCOS_E2E_CLUSTER_ID) \
| $(JQ_FIND_CLUSTER_URL)))
endif
@echo "+ Cluster URL: $(CLUSTER_URL)"
.PHONY: devkit
devkit: image
@echo "+ Build devkit image $(DEVKIT_IMG)"
@docker build \
--rm \
--quiet \
--force-rm \
--file $(MLB_PATH)/Dockerfile.devkit \
--tag $(DEVKIT_IMG) \
$(MLB_PATH) > /dev/null 2>&1
$(DCOS_E2E_WORKSPACE_DIR):
@echo "+ Creating DCOS E2E Workspace"
@mkdir -p $(DCOS_E2E_WORKSPACE_DIR)
$(DCOS_E2E_INSTALLERS_DIR):
@echo "+ Creating DCOS E2E Installer Cache"
@mkdir -p $(DCOS_E2E_WORKSPACE_DIR)
$(DCOS_E2E_INSTALLERS_DIR)/$(DCOS_E2E_FILE): $(DCOS_E2E_INSTALLERS_DIR)
ifeq ($(strip $(DCOS_E2E_VERSION)), master)
@echo '+ Removing existing master installer'
-@rm -f [email protected] $@
endif
@echo "+ Downloading $(DCOS_E2E_VERSION)$(DCOS_E2E_FILE_TAG) installer"
@curl \
--show-error \
--location \
--fail \
--continue-at - \
--output [email protected] \
$(DCOS_E2E_DOWNLOAD_URL) \
&& mv -f [email protected] $@ 2>/dev/null \
&& touch $@
.PHONY: dcos
dcos: devkit \
$(DCOS_E2E_WORKSPACE_DIR) \
$(DCOS_E2E_INSTALLERS_DIR)/$(DCOS_E2E_FILE)
ifeq ($(CLUSTER_RUNNING), 0)
@echo "+ Starting DCOS $(DCOS_E2E_VARIANT)" \
"cluster: $(DCOS_E2E_CLUSTER_ID)"
@docker run \
--rm \
--tty \
$(DEVKIT_VOL_ARGS) \
$(DOCKER_VOL_ARGS) \
$(DCOS_E2E_VOL_ARGS) \
$(DCOS_E2E_ENV_ARGS) \
$(DEVKIT_IMG) \
minidcos \
$(DCOS_E2E_BACKEND) \
create \
--cluster-id $(DCOS_E2E_CLUSTER_ID) \
--workspace-dir $(DCOS_E2E_WORKSPACE_DIR) \
--variant $(DCOS_E2E_VARIANT) \
--wait-for-dcos \
$(DCOS_E2E_INSTALLERS_DIR)/$(DCOS_E2E_FILE)
endif
.PHONY: image
image:
@echo "+ Build container image $(IMG)"
@docker build \
--rm \
--quiet \
--force-rm \
--file $(MLB_PATH)/Dockerfile \
--tag $(IMG) \
$(MLB_PATH) > /dev/null 2>&1 || true
.PHONY: image-push
image-push: image
@echo "+ Pushing image to hub"
docker push $(IMG)
.PHONY: shell
shell: devkit
@echo "+ Running $(DEVKIT_IMG) container"
-@docker run \
--rm \
--tty \
--interactive \
$(CLUSTER_ENV_ARGS) \
$(DEVKIT_VOL_ARGS) \
$(DOCKER_VOL_ARGS) \
$(DCOS_E2E_VOL_ARGS) \
$(DCOS_E2E_ENV_ARGS) \
$(DEVKIT_IMG) \
/bin/bash -l || true
.PHONY: test-integration
test-integration: image-push devkit cluster-url cluster-public-ip
@echo "+ Integration Testng with image $(IMG)"
@docker run \
--rm \
--tty \
$(CLUSTER_ENV_ARGS) \
$(DEVKIT_VOL_ARGS) \
$(DOCKER_VOL_ARGS) \
$(DCOS_E2E_VOL_ARGS) \
$(DCOS_E2E_ENV_ARGS) \
$(DEVKIT_IMG) \
/bin/bash -c " \
cd $(MLB_CONTAINER_PATH)/ci \
&& pytest -p no:warnings -v test_marathon_lb_dcos_e2e.py \
"
.PHONY: test-unit
test-unit: devkit
@echo "+ Unit Testing with image $(DEVKIT_IMG)"
@docker run \
--rm \
--tty \
$(DEVKIT_VOL_ARGS) \
$(DEVKIT_IMG) \
/bin/bash -c " \
echo -n 'flake8...' \
&& flake8 $(MLB_CONTAINER_PATH) \
&& echo ' OK' \
&& echo -n 'nosetests' \
&& cd $(MLB_CONTAINER_PATH) \
&& nosetests --with-coverage --cover-package=. \
"
.PHONY: test
test: test-unit test-integration