forked from apache/apisix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
410 lines (320 loc) · 14.1 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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Makefile basic env setting
.DEFAULT_GOAL := help
# add pipefail support for default shell
SHELL := /bin/bash -o pipefail
# Project basic setting
project_name ?= apache-apisix
project_version ?= master
project_compose_ci ?= ci/pod/docker-compose.yml
project_release_name ?= $(project_name)-$(project_version)-src
# Hyperconverged Infrastructure
ENV_OS_NAME ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
ENV_OS_ARCH ?= $(shell uname -m | tr '[:upper:]' '[:lower:]')
ENV_APISIX ?= $(CURDIR)/bin/apisix
ENV_GIT ?= git
ENV_TAR ?= tar
ENV_INSTALL ?= install
ENV_DOCKER ?= docker
ENV_DOCKER_COMPOSE ?= docker-compose --project-directory $(CURDIR) -p $(project_name) -f $(project_compose_ci)
ENV_NGINX ?= $(ENV_NGINX_EXEC) -p $(CURDIR) -c $(CURDIR)/conf/nginx.conf
ENV_NGINX_EXEC := $(shell which openresty 2>/dev/null || which nginx 2>/dev/null)
ENV_OPENSSL_PREFIX ?= $(addprefix $(ENV_NGINX_PREFIX), openssl)
ENV_LUAROCKS ?= luarocks
## These variables can be injected by luarocks
ENV_INST_PREFIX ?= /usr
ENV_INST_LUADIR ?= $(ENV_INST_PREFIX)/share/lua/5.1
ENV_INST_BINDIR ?= $(ENV_INST_PREFIX)/bin
ENV_HOMEBREW_PREFIX ?= /usr/local
ifneq ($(shell whoami), root)
ENV_LUAROCKS_FLAG_LOCAL := --local
endif
ifdef ENV_LUAROCKS_SERVER
ENV_LUAROCKS_SERVER_OPT := --server $(ENV_LUAROCKS_SERVER)
endif
# Execute only in the presence of ENV_NGINX_EXEC to avoid unexpected error output
ifneq ($(ENV_NGINX_EXEC), )
ENV_NGINX_PREFIX := $(shell $(ENV_NGINX_EXEC) -V 2>&1 | grep -Eo 'prefix=(.*)/nginx\s+' | grep -Eo '/.*/')
# OpenResty 1.17.8 or higher version uses openssl111 as the openssl dirname.
ifeq ($(shell test -d $(addprefix $(ENV_NGINX_PREFIX), openssl111) && echo -n yes), yes)
ENV_OPENSSL_PREFIX := $(addprefix $(ENV_NGINX_PREFIX), openssl111)
endif
endif
# ENV patch for darwin
ifeq ($(ENV_OS_NAME), darwin)
ifeq ($(ENV_OS_ARCH), arm64)
ENV_HOMEBREW_PREFIX := /opt/homebrew
endif
# OSX archive `._` cache file
ENV_TAR := COPYFILE_DISABLE=1 $(ENV_TAR)
ENV_LUAROCKS := $(ENV_LUAROCKS) --lua-dir=$(ENV_HOMEBREW_PREFIX)/opt/[email protected]
ifeq ($(shell test -d $(ENV_HOMEBREW_PREFIX)/opt/openresty-openssl && echo -n yes), yes)
ENV_OPENSSL_PREFIX := $(ENV_HOMEBREW_PREFIX)/opt/openresty-openssl
endif
ifeq ($(shell test -d $(ENV_HOMEBREW_PREFIX)/opt/openresty-openssl111 && echo -n yes), yes)
ENV_OPENSSL_PREFIX := $(ENV_HOMEBREW_PREFIX)/opt/openresty-openssl111
endif
endif
# Makefile basic extension function
_color_red =\E[1;31m
_color_green =\E[1;32m
_color_yellow =\E[1;33m
_color_blue =\E[1;34m
_color_wipe =\E[0m
define func_echo_status
printf "[%b info %b] %s\n" "$(_color_blue)" "$(_color_wipe)" $(1)
endef
define func_echo_warn_status
printf "[%b info %b] %s\n" "$(_color_yellow)" "$(_color_wipe)" $(1)
endef
define func_echo_success_status
printf "[%b info %b] %s\n" "$(_color_green)" "$(_color_wipe)" $(1)
endef
define func_check_folder
if [[ ! -d $(1) ]]; then \
mkdir -p $(1); \
$(call func_echo_status, 'folder check -> create `$(1)`'); \
else \
$(call func_echo_success_status, 'folder check -> found `$(1)`'); \
fi
endef
# Makefile target
.PHONY: runtime
runtime:
ifeq ($(ENV_NGINX_EXEC), )
ifeq ("$(wildcard /usr/local/openresty-debug/bin/openresty)", "")
@$(call func_echo_warn_status, "WARNING: OpenResty not found. You have to install OpenResty and add the binary file to PATH before install Apache APISIX.")
exit 1
else
$(eval ENV_NGINX_EXEC := /usr/local/openresty-debug/bin/openresty)
@$(call func_echo_status, "Use openresty-debug as default runtime")
endif
endif
### help : Show Makefile rules
### If there're awk failures, please make sure
### you are using awk or gawk
.PHONY: help
help:
@$(call func_echo_success_status, "Makefile rules:")
@echo
@if [ '$(ENV_OS_NAME)' = 'darwin' ]; then \
awk '{ if(match($$0, /^#{3}([^:]+):(.*)$$/)){ split($$0, res, ":"); gsub(/^#{3}[ ]*/, "", res[1]); _desc=$$0; gsub(/^#{3}([^:]+):[ \t]*/, "", _desc); printf(" make %-15s : %-10s\n", res[1], _desc) } }' Makefile; \
else \
awk '{ if(match($$0, /^\s*#{3}\s*([^:]+)\s*:\s*(.*)$$/, res)){ printf(" make %-15s : %-10s\n", res[1], res[2]) } }' Makefile; \
fi
@echo
### deps : Installation dependencies
.PHONY: deps
deps: runtime
$(eval ENV_LUAROCKS_VER := $(shell $(ENV_LUAROCKS) --version | grep -E -o "luarocks [0-9]+."))
@if [ '$(ENV_LUAROCKS_VER)' = 'luarocks 3.' ]; then \
mkdir -p ~/.luarocks; \
$(ENV_LUAROCKS) config $(ENV_LUAROCKS_FLAG_LOCAL) variables.OPENSSL_LIBDIR $(addprefix $(ENV_OPENSSL_PREFIX), /lib); \
$(ENV_LUAROCKS) config $(ENV_LUAROCKS_FLAG_LOCAL) variables.OPENSSL_INCDIR $(addprefix $(ENV_OPENSSL_PREFIX), /include); \
$(ENV_LUAROCKS) install rockspec/apisix-master-0.rockspec --tree=deps --only-deps --local $(ENV_LUAROCKS_SERVER_OPT); \
else \
$(call func_echo_warn_status, "WARNING: You're not using LuaRocks 3.x; please add the following items to your LuaRocks config file:"); \
echo "variables = {"; \
echo " OPENSSL_LIBDIR=$(addprefix $(ENV_OPENSSL_PREFIX), /lib)"; \
echo " OPENSSL_INCDIR=$(addprefix $(ENV_OPENSSL_PREFIX), /include)"; \
echo "}"; \
$(ENV_LUAROCKS) install rockspec/apisix-master-0.rockspec --tree=deps --only-deps --local $(ENV_LUAROCKS_SERVER_OPT); \
fi
### utils : Installation tools
.PHONY: utils
utils:
ifeq ("$(wildcard utils/lj-releng)", "")
wget -P utils https://raw.githubusercontent.com/iresty/openresty-devel-utils/master/lj-releng
chmod a+x utils/lj-releng
endif
ifeq ("$(wildcard utils/reindex)", "")
wget -P utils https://raw.githubusercontent.com/iresty/openresty-devel-utils/master/reindex
chmod a+x utils/reindex
endif
### lint : Lint source code
.PHONY: lint
lint: utils
@$(call func_echo_status, "$@ -> [ Start ]")
./utils/check-lua-code-style.sh
./utils/check-test-code-style.sh
@$(call func_echo_success_status, "$@ -> [ Done ]")
### init : Initialize the runtime environment
.PHONY: init
init: runtime
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_APISIX) init
$(ENV_APISIX) init_etcd
@$(call func_echo_success_status, "$@ -> [ Done ]")
### run : Start the apisix server
.PHONY: run
run: runtime
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_APISIX) start
@$(call func_echo_success_status, "$@ -> [ Done ]")
### quit : Stop the apisix server, exit gracefully
.PHONY: quit
quit: runtime
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_APISIX) quit
@$(call func_echo_success_status, "$@ -> [ Done ]")
### stop : Stop the apisix server, exit immediately
.PHONY: stop
stop: runtime
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_APISIX) stop
@$(call func_echo_success_status, "$@ -> [ Done ]")
### verify : Verify the configuration of apisix server
.PHONY: verify
verify: runtime
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_NGINX) -t
@$(call func_echo_success_status, "$@ -> [ Done ]")
### clean : Remove generated files
.PHONY: clean
clean:
@$(call func_echo_status, "$@ -> [ Start ]")
rm -rf logs/
@$(call func_echo_success_status, "$@ -> [ Done ]")
### reload : Reload the apisix server
.PHONY: reload
reload: runtime
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_NGINX) -s reload
@$(call func_echo_success_status, "$@ -> [ Done ]")
### install : Install the apisix (only for luarocks)
.PHONY: install
install: runtime
$(ENV_INSTALL) -d /usr/local/apisix/
$(ENV_INSTALL) -d /usr/local/apisix/logs/
$(ENV_INSTALL) -d /usr/local/apisix/conf/cert
$(ENV_INSTALL) conf/mime.types /usr/local/apisix/conf/mime.types
$(ENV_INSTALL) conf/config.yaml /usr/local/apisix/conf/config.yaml
$(ENV_INSTALL) conf/config-default.yaml /usr/local/apisix/conf/config-default.yaml
$(ENV_INSTALL) conf/debug.yaml /usr/local/apisix/conf/debug.yaml
$(ENV_INSTALL) conf/cert/* /usr/local/apisix/conf/cert/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix
$(ENV_INSTALL) apisix/*.lua $(ENV_INST_LUADIR)/apisix/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/admin
$(ENV_INSTALL) apisix/admin/*.lua $(ENV_INST_LUADIR)/apisix/admin/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/balancer
$(ENV_INSTALL) apisix/balancer/*.lua $(ENV_INST_LUADIR)/apisix/balancer/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/control
$(ENV_INSTALL) apisix/control/*.lua $(ENV_INST_LUADIR)/apisix/control/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/core
$(ENV_INSTALL) apisix/core/*.lua $(ENV_INST_LUADIR)/apisix/core/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/core/dns
$(ENV_INSTALL) apisix/core/dns/*.lua $(ENV_INST_LUADIR)/apisix/core/dns
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/cli
$(ENV_INSTALL) apisix/cli/*.lua $(ENV_INST_LUADIR)/apisix/cli/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/discovery
$(ENV_INSTALL) apisix/discovery/*.lua $(ENV_INST_LUADIR)/apisix/discovery/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/http
$(ENV_INSTALL) apisix/http/*.lua $(ENV_INST_LUADIR)/apisix/http/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/http/router
$(ENV_INSTALL) apisix/http/router/*.lua $(ENV_INST_LUADIR)/apisix/http/router/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/plugins
$(ENV_INSTALL) apisix/plugins/*.lua $(ENV_INST_LUADIR)/apisix/plugins/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/plugins/ext-plugin
$(ENV_INSTALL) apisix/plugins/ext-plugin/*.lua $(ENV_INST_LUADIR)/apisix/plugins/ext-plugin/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/plugins/grpc-transcode
$(ENV_INSTALL) apisix/plugins/grpc-transcode/*.lua $(ENV_INST_LUADIR)/apisix/plugins/grpc-transcode/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/plugins/ip-restriction
$(ENV_INSTALL) apisix/plugins/ip-restriction/*.lua $(ENV_INST_LUADIR)/apisix/plugins/ip-restriction/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/plugins/limit-conn
$(ENV_INSTALL) apisix/plugins/limit-conn/*.lua $(ENV_INST_LUADIR)/apisix/plugins/limit-conn/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/plugins/limit-count
$(ENV_INSTALL) apisix/plugins/limit-count/*.lua $(ENV_INST_LUADIR)/apisix/plugins/limit-count/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/plugins/prometheus
$(ENV_INSTALL) apisix/plugins/prometheus/*.lua $(ENV_INST_LUADIR)/apisix/plugins/prometheus/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/plugins/proxy-cache
$(ENV_INSTALL) apisix/plugins/proxy-cache/*.lua $(ENV_INST_LUADIR)/apisix/plugins/proxy-cache/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/plugins/serverless
$(ENV_INSTALL) apisix/plugins/serverless/*.lua $(ENV_INST_LUADIR)/apisix/plugins/serverless/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/plugins/zipkin
$(ENV_INSTALL) apisix/plugins/zipkin/*.lua $(ENV_INST_LUADIR)/apisix/plugins/zipkin/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/ssl/router
$(ENV_INSTALL) apisix/ssl/router/*.lua $(ENV_INST_LUADIR)/apisix/ssl/router/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/stream/plugins
$(ENV_INSTALL) apisix/stream/plugins/*.lua $(ENV_INST_LUADIR)/apisix/stream/plugins/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/stream/router
$(ENV_INSTALL) apisix/stream/router/*.lua $(ENV_INST_LUADIR)/apisix/stream/router/
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/utils
$(ENV_INSTALL) apisix/utils/*.lua $(ENV_INST_LUADIR)/apisix/utils/
$(ENV_INSTALL) bin/apisix $(ENV_INST_BINDIR)/apisix
$(ENV_INSTALL) -d $(ENV_INST_LUADIR)/apisix/plugins/slslog
$(ENV_INSTALL) apisix/plugins/slslog/*.lua $(ENV_INST_LUADIR)/apisix/plugins/slslog/
### test : Run the test case
.PHONY: test
test: runtime
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_GIT) submodule update --init --recursive
prove -I../test-nginx/lib -I./ -r -s t/
@$(call func_echo_success_status, "$@ -> [ Done ]")
### license-check : Check project source code for Apache License
.PHONY: license-check
license-check:
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_DOCKER) run -it --rm -v $(CURDIR):/github/workspace apache/skywalking-eyes header check
@$(call func_echo_success_status, "$@ -> [ Done ]")
.PHONY: release-src
release-src: compress-tar
@$(call func_echo_status, "$@ -> [ Start ]")
gpg --batch --yes --armor --detach-sig $(project_release_name).tgz
shasum -a 512 $(project_release_name).tgz > $(project_release_name).tgz.sha512
$(call func_check_folder,release)
mv $(project_release_name).tgz release/$(project_release_name).tgz
mv $(project_release_name).tgz.asc release/$(project_release_name).tgz.asc
mv $(project_release_name).tgz.sha512 release/$(project_release_name).tgz.sha512
@$(call func_echo_success_status, "$@ -> [ Done ]")
.PHONY: compress-tar
compress-tar:
$(ENV_TAR) -zcvf $(project_release_name).tgz \
./apisix \
./bin \
./conf \
./rockspec/apisix-$(project_version)-*.rockspec \
./rockspec/apisix-master-0.rockspec \
LICENSE \
Makefile \
NOTICE \
*.md
### container
### ci-env-up : CI env launch
.PHONY: ci-env-up
ci-env-up:
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_DOCKER_COMPOSE) up -d
@$(call func_echo_success_status, "$@ -> [ Done ]")
### ci-env-ps : CI env ps
.PHONY: ci-env-ps
ci-env-ps:
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_DOCKER_COMPOSE) ps
@$(call func_echo_success_status, "$@ -> [ Done ]")
### ci-env-rebuild : CI env image rebuild
.PHONY: ci-env-rebuild
ci-env-rebuild:
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_DOCKER_COMPOSE) build
@$(call func_echo_success_status, "$@ -> [ Done ]")
### ci-env-down : CI env destroy
.PHONY: ci-env-down
ci-env-down:
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_DOCKER_COMPOSE) down
@$(call func_echo_success_status, "$@ -> [ Done ]")