Makefile 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # Makefile basic env setting
  18. .DEFAULT_GOAL := help
  19. # APISIX ARGS
  20. APISIX_VERSION ?= 2.10.3
  21. IMAGE_NAME = apache/apisix
  22. IMAGE_TAR_NAME = apache_apisix
  23. APISIX_DASHBOARD_VERSION ?= 2.10.1
  24. APISIX_DASHBOARD_IMAGE_NAME = apache/apisix-dashboard
  25. APISIX_DASHBOARD_IMAGE_TAR_NAME = apache_apisix_dashboard
  26. # Makefile ENV
  27. ENV_OS_NAME ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
  28. ENV_APISIX_TAR_NAME ?= $(IMAGE_TAR_NAME)_$(APISIX_VERSION)
  29. ENV_APISIX_IMAGE_TAG_NAME ?= $(IMAGE_NAME):$(APISIX_VERSION)
  30. ENV_DOCKER ?= docker
  31. # Makefile basic extension function
  32. _color_red =\E[1;31m
  33. _color_green =\E[1;32m
  34. _color_yellow =\E[1;33m
  35. _color_blue =\E[1;34m
  36. _color_wipe =\E[0m
  37. define func_echo_status
  38. printf "[$(_color_blue) info $(_color_wipe)] %s\n" $(1)
  39. endef
  40. define func_echo_warn_status
  41. printf "[$(_color_yellow) info $(_color_wipe)] %s\n" $(1)
  42. endef
  43. define func_echo_success_status
  44. printf "[$(_color_green) info $(_color_wipe)] %s\n" $(1)
  45. endef
  46. # Makefile target
  47. ### build-on-centos : Build apache/apisix:xx-centos image
  48. .PHONY: build-on-centos
  49. build-on-centos:
  50. @$(call func_echo_status, "$@ -> [ Start ]")
  51. $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-centos \
  52. --build-arg APISIX_VERSION=$(APISIX_VERSION) \
  53. -f ./centos/Dockerfile .
  54. @$(call func_echo_success_status, "$@ -> [ Done ]")
  55. ### build-on-alpine : Build apache/apisix:xx-alpine image
  56. .PHONY: build-on-alpine
  57. build-on-alpine:
  58. @$(call func_echo_status, "$@ -> [ Start ]")
  59. $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-alpine \
  60. --build-arg APISIX_VERSION=$(APISIX_VERSION) \
  61. -f ./alpine/Dockerfile .
  62. @$(call func_echo_success_status, "$@ -> [ Done ]")
  63. ### build-on-alpine-local : Build apache/apisix:xx-alpine-local image
  64. # Actually it is not build on certain version but on local code
  65. # Use this name (in the same patterns with others) for convenient CI
  66. .PHONY: build-on-alpine-local
  67. build-on-alpine-local:
  68. @$(call func_echo_status, "$@ -> [ Start ]")
  69. $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-alpine-local \
  70. --build-arg APISIX_PATH=${APISIX_PATH} \
  71. -f ./alpine-local/Dockerfile .
  72. @$(call func_echo_success_status, "$@ -> [ Done ]")
  73. ### push-on-centos : Push apache/apisix:xx-centos image
  74. # centos not support multiarch since it reply on x86 rpm package
  75. .PHONY: push-on-centos
  76. push-on-centos:
  77. @$(call func_echo_status, "$@ -> [ Start ]")
  78. $(ENV_DOCKER) push $(ENV_APISIX_IMAGE_TAG_NAME)-centos
  79. $(ENV_DOCKER) build -t $(IMAGE_NAME):latest \
  80. --build-arg APISIX_VERSION=$(APISIX_VERSION) \
  81. -f ./centos/Dockerfile .
  82. $(ENV_DOCKER) push $(IMAGE_NAME):latest
  83. @$(call func_echo_success_status, "$@ -> [ Done ]")
  84. ### push-on-alpine : Push apache/apisix:xx-alpine image
  85. .PHONY: push-multiarch-on-alpine
  86. push-multiarch-on-alpine:
  87. @$(call func_echo_status, "$@ -> [ Start ]")
  88. $(ENV_DOCKER) buildx build --push \
  89. -t $(ENV_APISIX_IMAGE_TAG_NAME)-alpine \
  90. --build-arg APISIX_VERSION=$(APISIX_VERSION) \
  91. --platform linux/amd64,linux/arm64 \
  92. -f ./alpine/Dockerfile .
  93. @$(call func_echo_success_status, "$@ -> [ Done ]")
  94. ### build-on-alpine-cn : Build apache/apisix:xx-alpine image (for chinese)
  95. .PHONY: build-on-alpine-cn
  96. build-on-alpine-cn:
  97. @$(call func_echo_status, "$@ -> [ Start ]")
  98. $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-alpine \
  99. --build-arg APISIX_VERSION=$(APISIX_VERSION) \
  100. --build-arg ENABLE_PROXY=true \
  101. -f alpine/Dockerfile alpine
  102. @$(call func_echo_success_status, "$@ -> [ Done ]")
  103. ### build-all-in-one : Build All in one Docker container for Apache APISIX
  104. .PHONY: build-all-in-one
  105. build-all-in-one:
  106. @$(call func_echo_status, "$@ -> [ Start ]")
  107. $(ENV_DOCKER) build -t $(IMAGE_NAME):whole \
  108. --build-arg APISIX_VERSION=$(APISIX_VERSION) \
  109. -f ./all-in-one/apisix/Dockerfile .
  110. @$(call func_echo_success_status, "$@ -> [ Done ]")
  111. ### save-centos-tar : tar apache/apisix:xx-centos image
  112. .PHONY: save-centos-tar
  113. save-centos-tar:
  114. @$(call func_echo_status, "$@ -> [ Start ]")
  115. mkdir -p package
  116. $(ENV_DOCKER) save -o ./package/$(ENV_APISIX_TAR_NAME)-centos.tar $(ENV_APISIX_IMAGE_TAG_NAME)-centos
  117. @$(call func_echo_success_status, "$@ -> [ Done ]")
  118. ### save-alpine-tar : tar apache/apisix:xx-alpine image
  119. .PHONY: save-alpine-tar
  120. save-alpine-tar:
  121. @$(call func_echo_status, "$@ -> [ Start ]")
  122. mkdir -p package
  123. $(ENV_DOCKER) save -o ./package/$(ENV_APISIX_TAR_NAME)-alpine.tar $(ENV_APISIX_IMAGE_TAG_NAME)-alpine
  124. @$(call func_echo_success_status, "$@ -> [ Done ]")
  125. ### build-dashboard-centos : Build apache/dashboard:tag image on centos
  126. .PHONY: build-dashboard-centos
  127. build-dashboard-centos:
  128. @$(call func_echo_status, "$@ -> [ Start ]")
  129. $(ENV_DOCKER) build -t $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION) -f ./dashboard/Dockerfile.centos .
  130. @$(call func_echo_success_status, "$@ -> [ Done ]")
  131. ### build-dashboard-alpine : Build apache/dashboard:tag image on alpine
  132. .PHONY: build-dashboard-alpine
  133. build-dashboard-alpine:
  134. @$(call func_echo_status, "$@ -> [ Start ]")
  135. $(ENV_DOCKER) build -t $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION) -f ./dashboard/Dockerfile.alpine .
  136. @$(call func_echo_success_status, "$@ -> [ Done ]")
  137. ### push-multiarch-dashbaord : Build and push multiarch apache/dashboard:tag image
  138. .PHONY: push-multiarch-dashbaord
  139. push-multiarch-dashbaord:
  140. @$(call func_echo_status, "$@ -> [ Start ]")
  141. $(ENV_DOCKER) buildx build --push \
  142. -t $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION)-alpine \
  143. --build-arg APISIX_DASHBOARD_VERSION=release/$(APISIX_DASHBOARD_VERSION) \
  144. --platform linux/amd64,linux/arm64 \
  145. -f ./dashboard/Dockerfile.alpine .
  146. $(ENV_DOCKER) buildx build --push \
  147. -t $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION)-centos \
  148. --build-arg APISIX_DASHBOARD_VERSION=release/$(APISIX_DASHBOARD_VERSION) \
  149. --platform linux/amd64,linux/arm64 \
  150. -f ./dashboard/Dockerfile.centos .
  151. $(ENV_DOCKER) buildx build --push \
  152. -t $(APISIX_DASHBOARD_IMAGE_NAME):latest \
  153. --build-arg APISIX_DASHBOARD_VERSION=release/$(APISIX_DASHBOARD_VERSION) \
  154. --platform linux/amd64,linux/arm64 \
  155. -f ./dashboard/Dockerfile.centos .
  156. @$(call func_echo_success_status, "$@ -> [ Done ]")
  157. ### save-dashboard-centos-tar : tar apache/apisix-dashboard:tag image
  158. .PHONY: save-dashboard-centos-tar
  159. save-dashboard-centos-tar:
  160. @$(call func_echo_status, "$@ -> [ Start ]")
  161. mkdir -p package
  162. $(ENV_DOCKER) save -o ./package/$(APISIX_DASHBOARD_IMAGE_TAR_NAME)_$(APISIX_DASHBOARD_VERSION)-centos.tar $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION)
  163. @$(call func_echo_success_status, "$@ -> [ Done ]")
  164. ### save-dashboard-alpine-tar : tar apache/apisix-dashboard:tag image
  165. .PHONY: save-dashboard-alpine-tar
  166. save-dashboard-alpine-tar:
  167. @$(call func_echo_status, "$@ -> [ Start ]")
  168. mkdir -p package
  169. $(ENV_DOCKER) save -o ./package/$(APISIX_DASHBOARD_IMAGE_TAR_NAME)_$(APISIX_DASHBOARD_VERSION)-alpine.tar $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION)
  170. @$(call func_echo_success_status, "$@ -> [ Done ]")
  171. ### help : Show Makefile rules
  172. .PHONY: help
  173. help:
  174. @$(call func_echo_success_status, "Makefile rules:")
  175. @echo
  176. @if [ '$(ENV_OS_NAME)' = 'darwin' ]; then \
  177. awk '{ if(match($$0, /^#{3}([^:]+):(.*)$$/)){ split($$0, res, ":"); gsub(/^#{3}[ ]*/, "", res[1]); _desc=$$0; gsub(/^#{3}([^:]+):[ \t]*/, "", _desc); printf(" make %-25s : %-10s\n", res[1], _desc) } }' Makefile; \
  178. else \
  179. awk '{ if(match($$0, /^\s*#{3}\s*([^:]+)\s*:\s*(.*)$$/, res)){ printf(" make %-25s : %-10s\n", res[1], res[2]) } }' Makefile; \
  180. fi
  181. @echo