You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/10/13 01:02:15 UTC
[apisix] branch master updated: refactor: spilt Makefile change
from PR (#5205)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 6e65bc2 refactor: spilt Makefile change from PR (#5205)
6e65bc2 is described below
commit 6e65bc2a732ee5fcf9d2479aa4f83a868000d702
Author: leslie <59...@users.noreply.github.com>
AuthorDate: Wed Oct 13 09:02:09 2021 +0800
refactor: spilt Makefile change from PR (#5205)
---
Makefile | 242 +++++++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 181 insertions(+), 61 deletions(-)
diff --git a/Makefile b/Makefile
index 9a9bdab..d172357 100644
--- a/Makefile
+++ b/Makefile
@@ -15,13 +15,43 @@
# 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 ?= latest
+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_DOCKER ?= docker
+ENV_DOCKER_COMPOSE ?= docker-compose --project-directory $(CURDIR) -p $(project_name) -f $(project_compose_ci)
+ENV_NGINX ?= nginx -p $(CURDIR) -c $(CURDIR)/conf/nginx.conf
+
+
+# OSX archive `._` cache file
+ifeq ($(ENV_OS_NAME), darwin)
+ ENV_TAR ?= COPYFILE_DISABLE=1 tar
+else
+ ENV_TAR ?= tar
+endif
+
+
+# OLD VAR
INST_PREFIX ?= /usr
INST_LIBDIR ?= $(INST_PREFIX)/lib64/lua/5.1
INST_LUADIR ?= $(INST_PREFIX)/share/lua/5.1
INST_BINDIR ?= /usr/bin
INSTALL ?= install
-UNAME ?= $(shell uname)
-UNAME_MACHINE ?= $(shell uname -m)
OR_EXEC ?= $(shell which openresty || which nginx)
LUAROCKS ?= luarocks
LUAROCKS_VER ?= $(shell luarocks --version | grep -E -o "luarocks [0-9]+.")
@@ -34,17 +64,17 @@ ifeq ($(shell test -d $(addprefix $(OR_PREFIX), openssl111) && echo -n yes), yes
OPENSSL_PREFIX=$(addprefix $(OR_PREFIX), openssl111)
endif
-ifeq ($(UNAME), Darwin)
-ifeq ($(UNAME_MACHINE), arm64)
- HOMEBREW_PREFIX=/opt/homebrew
-endif
-LUAROCKS=luarocks --lua-dir=$(HOMEBREW_PREFIX)/opt/lua@5.1
-ifeq ($(shell test -d $(HOMEBREW_PREFIX)/opt/openresty-openssl && echo yes), yes)
- OPENSSL_PREFIX=$(HOMEBREW_PREFIX)/opt/openresty-openssl
-endif
-ifeq ($(shell test -d $(HOMEBREW_PREFIX)/opt/openresty-openssl111 && echo yes), yes)
- OPENSSL_PREFIX=$(HOMEBREW_PREFIX)/opt/openresty-openssl111
-endif
+ifeq ($(ENV_OS_NAME), darwin)
+ ifeq ($(ENV_OS_ARCH), arm64)
+ HOMEBREW_PREFIX=/opt/homebrew
+ endif
+ LUAROCKS=luarocks --lua-dir=$(HOMEBREW_PREFIX)/opt/lua@5.1
+ ifeq ($(shell test -d $(HOMEBREW_PREFIX)/opt/openresty-openssl && echo yes), yes)
+ OPENSSL_PREFIX=$(HOMEBREW_PREFIX)/opt/openresty-openssl
+ endif
+ ifeq ($(shell test -d $(HOMEBREW_PREFIX)/opt/openresty-openssl111 && echo yes), yes)
+ OPENSSL_PREFIX=$(HOMEBREW_PREFIX)/opt/openresty-openssl111
+ endif
endif
LUAROCKS_SERVER_OPT =
@@ -52,13 +82,43 @@ ifneq ($(LUAROCKS_SERVER), )
LUAROCKS_SERVER_OPT = --server ${LUAROCKS_SERVER}
endif
-SHELL := /bin/bash -o pipefail
-VERSION ?= latest
-RELEASE_SRC = apache-apisix-${VERSION}-src
+# 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
-.PHONY: default
-default:
+
+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 ($(OR_EXEC), )
ifeq ("$(wildcard /usr/local/openresty-debug/bin/openresty)", "")
@echo "WARNING: OpenResty not found. You have to install OpenResty and add the binary file to PATH before install Apache APISIX."
@@ -68,19 +128,23 @@ else
endif
endif
-LUAJIT_DIR ?= $(shell ${OR_EXEC} -V 2>&1 | grep prefix | grep -Eo 'prefix=(.*)/nginx\s+--' | grep -Eo '/.*/')luajit
-### help: Show Makefile rules
+### help : Show Makefile rules
.PHONY: help
-help: default
- @echo Makefile rules:
+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
- @grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /'
-### deps: Installation dependencies
+### deps : Installation dependencies
.PHONY: deps
-deps: default
+deps: runtime
ifeq ($(LUAROCKS_VER),luarocks 3.)
mkdir -p ~/.luarocks
ifeq ($(shell whoami),root)
@@ -97,11 +161,11 @@ else
@echo " OPENSSL_LIBDIR=$(addprefix $(OPENSSL_PREFIX), /lib)"
@echo " OPENSSL_INCDIR=$(addprefix $(OPENSSL_PREFIX), /include)"
@echo "}"
- luarocks install rockspec/apisix-master-0.rockspec --tree=deps --only-deps --local $(LUAROCKS_SERVER_OPT)
+ $(LUAROCKS) install rockspec/apisix-master-0.rockspec --tree=deps --only-deps --local $(LUAROCKS_SERVER_OPT)
endif
-### utils: Installation tools
+### utils : Installation tools
.PHONY: utils
utils:
ifeq ("$(wildcard utils/lj-releng)", "")
@@ -114,59 +178,75 @@ ifeq ("$(wildcard utils/reindex)", "")
endif
-### lint: Lint source code
+### 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
+### init : Initialize the runtime environment
.PHONY: init
-init: default
- ./bin/apisix init
- ./bin/apisix init_etcd
+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
+### run : Start the apisix server
.PHONY: run
-run: default
- ./bin/apisix start
+run: runtime
+ @$(call func_echo_status, "$@ -> [ Start ]")
+ $(ENV_APISIX) start
+ @$(call func_echo_success_status, "$@ -> [ Done ]")
-### quit: Stop the apisix server, exit gracefully
+### quit : Stop the apisix server, exit gracefully
.PHONY: quit
-quit: default
- ./bin/apisix quit
+quit: runtime
+ @$(call func_echo_status, "$@ -> [ Start ]")
+ $(ENV_APISIX) quit
+ @$(call func_echo_success_status, "$@ -> [ Done ]")
-### stop: Stop the apisix server, exit immediately
+### stop : Stop the apisix server, exit immediately
.PHONY: stop
-stop: default
- ./bin/apisix stop
+stop: runtime
+ @$(call func_echo_status, "$@ -> [ Start ]")
+ $(ENV_APISIX) stop
+ @$(call func_echo_success_status, "$@ -> [ Done ]")
-### verify: Verify the configuration of apisix server
+### verify : Verify the configuration of apisix server
.PHONY: verify
-verify: default
- $(OR_EXEC) -p $$PWD/ -c $$PWD/conf/nginx.conf -t
+verify: runtime
+ @$(call func_echo_status, "$@ -> [ Start ]")
+ $(ENV_NGINX) -t
+ @$(call func_echo_success_status, "$@ -> [ Done ]")
-### clean: Remove generated files
+### 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
+### reload : Reload the apisix server
.PHONY: reload
-reload: default
- $(OR_EXEC) -p $$PWD/ -c $$PWD/conf/nginx.conf -s 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)
+### install : Install the apisix (only for luarocks)
.PHONY: install
-install: default
+install: runtime
$(INSTALL) -d /usr/local/apisix/
$(INSTALL) -d /usr/local/apisix/logs/
$(INSTALL) -d /usr/local/apisix/conf/cert
@@ -252,36 +332,76 @@ install: default
$(INSTALL) apisix/plugins/slslog/*.lua $(INST_LUADIR)/apisix/plugins/slslog/
-### test: Run the test case
+### test : Run the test case
.PHONY: test
test:
- git submodule update --init --recursive
+ @$(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 Lua source code for Apache License
+
+### license-check : Check project source code for Apache License
.PHONY: license-check
license-check:
- docker run -it --rm -v $(shell pwd):/github/workspace apache/skywalking-eyes header 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
- gpg --batch --yes --armor --detach-sig $(RELEASE_SRC).tgz
- shasum -a 512 $(RELEASE_SRC).tgz > $(RELEASE_SRC).tgz.sha512
+ gpg --batch --yes --armor --detach-sig $(project_release_name).tgz
+ shasum -a 512 $(project_release_name).tgz > $(project_release_name).tgz.sha512
mkdir -p release
- mv $(RELEASE_SRC).tgz release/$(RELEASE_SRC).tgz
- mv $(RELEASE_SRC).tgz.asc release/$(RELEASE_SRC).tgz.asc
- mv $(RELEASE_SRC).tgz.sha512 release/$(RELEASE_SRC).tgz.sha512
+ 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
+
.PHONY: compress-tar
compress-tar:
- tar -zcvf $(RELEASE_SRC).tgz \
+ $(ENV_TAR) -zcvf $(project_release_name).tgz \
./apisix \
./bin \
./conf \
- ./rockspec/apisix-$(VERSION)-*.rockspec \
+ ./rockspec/apisix-$(project_version)-*.rockspec \
./rockspec/apisix-master-0.rockspec \
LICENSE \
Makefile \
NOTICE \
*.md
+
+
+### container
+### ci-env-up : launch ci env
+.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 : destroy ci env
+.PHONY: ci-env-down
+ci-env-down:
+ @$(call func_echo_status, "$@ -> [ Start ]")
+ $(ENV_DOCKER_COMPOSE) down
+ @$(call func_echo_success_status, "$@ -> [ Done ]")