-
Notifications
You must be signed in to change notification settings - Fork 22
/
Makefile
211 lines (174 loc) · 6 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
PACKAGE ?= dcos-net
VERSION ?= $(shell git describe --tags)
BASE_DIR = $(shell pwd)
ERLANG_BIN = $(shell dirname $(shell which erl))
REBAR = $(shell pwd)/rebar3
.PHONY: rel deps test
all: compile
##
## Compilation targets
##
compile:
$(REBAR) compile
clean:
$(REBAR) clean
##
## Test targets
##
check: test xref dialyzer lint cover edoc
test: ct eunit
lint:
${REBAR} as lint lint
xref:
${REBAR} as test xref
dialyzer:
${REBAR} dialyzer
eunit:
${REBAR} as test eunit --verbose
ct:
${REBAR} as test ct --verbose --readable true
cover:
${REBAR} as test cover
edoc:
${REBAR} edoc
##
## Release targets
##
rel:
${REBAR} as prod release
stage:
${REBAR} release -d
##
## Docker
##
DOCKER_IMAGE_REV = $(shell git log -n 1 --pretty=format:%h -- ${BASE_DIR}/Dockerfile)
DOCKER_IMAGE = "${PACKAGE}:${DOCKER_IMAGE_REV}"
BUILD_DIR = ${BASE_DIR}/_build
docker-image:
@if [ -z "$(shell docker image ls -q ${DOCKER_IMAGE})" ]; then \
echo "Building docker image..." >&2; \
docker build -t ${DOCKER_IMAGE} ${BASE_DIR}; \
fi
docker-%: docker-image
@mkdir -p ${BUILD_DIR}
@docker run --rm -it --privileged \
-v ${BASE_DIR}:/${PACKAGE} \
-v ${BUILD_DIR}:/root \
-w /${PACKAGE} \
${DOCKER_IMAGE} \
make $(subst docker-,,$@)
docker: docker-image
@mkdir -p ${BUILD_DIR}
@docker run --rm -it --privileged \
-v ${BASE_DIR}:/${PACKAGE} \
-v ${BUILD_DIR}:/root \
-w /${PACKAGE} \
${DOCKER_IMAGE}
##
## Dev
##
dev-install:
@ which gcc g++ make dig ip ipvsadm > /dev/null 2> /dev/null || \
sudo yum install -y make gcc gcc-c++ bind-utils iproute2 ipvsadm
dev-stop:
@ systemctl stop dcos-net.service && \
( echo "options timeout:1" && \
echo "options attempts:3" && \
echo $(shell source /opt/mesosphere/etc/dns_config && \
echo $${RESOLVERS} | \
sed -e 's/\(^\|[,]\)/\nnameserver /g') \
) > /etc/resolv.conf
dev-start:
@ systemctl start dcos-net.service
dev-shell:
@ CFLAGS="-I/opt/mesosphere/include -I/opt/mesosphere/active/libsodium/include" \
LDFLAGS="-L/opt/mesosphere/lib -L/opt/mesosphere/active/libsodium/lib -Wl,-rpath=/opt/mesosphere/active/libsodium/lib" \
$(REBAR) shell --config config/sys.config --name ${NAME} --setcookie minuteman \
--apps mnesia,dcos_dns,dcos_l4lb,dcos_overlay,dcos_rest,dcos_net,recon
console: dev-shell
dev: dev-install dev-stop
@ export ENABLE_CHECK_TIME=false && \
export $(shell \
systemctl cat dcos-net \
| sed -ne 's/EnvironmentFile=-*//p' \
| while read f; do [ -f $$f ] && echo $$f; done \
| xargs grep -h '[^=]*=') && \
systemctl cat dcos-net | sed -ne 's/ExecStartPre=//p' | tr '\n' '\0' | \
xargs -0 -n 1 /opt/mesosphere/bin/dcos-shell bash -c
@ DCOS_NET_ENV_CMD="make" \
DCOS_NET_EBIN="$(BUILD_DIR)/default/lib/dcos_net/ebin" \
/opt/mesosphere/bin/dcos-net-env console
##
## miniDC/OS
##
MINIDCOS_TRANSPORT ?= docker-exec
MINIDCOS_CUSTOM_VOLUME ?= "$(BASE_DIR):$(BASE_DIR):rw"
MINIDCOS_CLUSTER_ID ?= default
MINIDCOS_MASTERS ?= 1
MINIDCOS_AGENTS ?= 1
MINIDCOS_PUBLIC_AGENTS ?= 0
MINIDCOS_NODE ?= master_0
MINIDCOS_WEB_PORT ?= 443
MINIDCOS_INTALLER ?= dcos_generate_config.sh
ERL_AFLAGS = -kernel shell_history enabled \
-kernel shell_history_path \"$(BUILD_DIR)/.erlang-history\"
minidcos-create:
@ minidcos docker inspect \
--cluster-id $(MINIDCOS_CLUSTER_ID) \
> /dev/null 2> /dev/null || \
( minidcos docker create $(MINIDCOS_INTALLER) \
--transport $(MINIDCOS_TRANSPORT) \
--masters $(MINIDCOS_MASTERS) \
--agents $(MINIDCOS_AGENTS) \
--public-agents $(MINIDCOS_PUBLIC_AGENTS) \
--cluster-id $(MINIDCOS_CLUSTER_ID) \
--custom-volume $(MINIDCOS_CUSTOM_VOLUME) \
$(MINIDCOS_OPTS) && \
minidcos docker wait \
--transport $(MINIDCOS_TRANSPORT) \
--cluster-id $(MINIDCOS_CLUSTER_ID) \
--skip-http-checks )
minidcos-destroy:
@ docker ps \
--filter label=dcos_e2e.cluster_id=$(MINIDCOS_CLUSTER_ID) \
--filter label=dcos_e2e.web_port \
--format '{{.ID}}' \
| while read id; do [ -z "$$id" ] || docker kill $$id; done > /dev/null
@ minidcos docker destroy --cluster-id $(MINIDCOS_CLUSTER_ID)
minidcos-web: minidcos-create
@ docker ps \
--filter label=dcos_e2e.cluster_id=$(MINIDCOS_CLUSTER_ID) \
--filter label=dcos_e2e.web_port=$(MINIDCOS_WEB_PORT) \
--format '{{.ID}}' \
| while read id; do [ -z "$$id" ] || docker kill $$id; done > /dev/null
@ docker run \
--rm --detach \
--publish $(MINIDCOS_WEB_PORT):$(MINIDCOS_WEB_PORT) \
--name $(shell minidcos docker inspect --cluster-id $(MINIDCOS_CLUSTER_ID) | \
jq -r .Nodes.masters[0].docker_container_name | \
sed -e 's/-master-0/-web-$(MINIDCOS_WEB_PORT)/') \
--label dcos_e2e.cluster_id=$(MINIDCOS_CLUSTER_ID) \
--label dcos_e2e.web_port=$(MINIDCOS_WEB_PORT) \
alpine/socat TCP4-LISTEN:$(MINIDCOS_WEB_PORT),bind=0.0.0.0,reuseaddr,fork,su=nobody \
TCP4:$(shell minidcos docker inspect --cluster-id $(MINIDCOS_CLUSTER_ID) | \
jq '.Nodes | .[] | .[]' | \
jq 'select (.e2e_reference == "$(MINIDCOS_NODE)")' | \
jq -r .ip_address \
):$(MINIDCOS_WEB_PORT),bind=0.0.0.0 \
> /dev/null
open https://localhost:$(MINIDCOS_WEB_PORT)/
minidcos-shell: minidcos-create
@ minidcos docker run \
--transport $(MINIDCOS_TRANSPORT) \
--cluster-id $(MINIDCOS_CLUSTER_ID) \
--node $(MINIDCOS_NODE) \
--env ERL_AFLAGS="$(subst ",\\",$(ERL_AFLAGS))" \
-- 'cd $(BASE_DIR) && exec /opt/mesosphere/bin/dcos-shell'
minidcos-dev: minidcos-create
@ minidcos docker run \
--transport $(MINIDCOS_TRANSPORT) \
--cluster-id $(MINIDCOS_CLUSTER_ID) \
--node $(MINIDCOS_NODE) \
--env ERL_AFLAGS="$(ERL_AFLAGS)" \
-- '(which make > /dev/null 2> /dev/null || sudo yum install -y make) ' \
'&& (cd $(BASE_DIR) && exec make dev)'