Makefile 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. SHELL := bash
  20. # APISIX ARGS
  21. APISIX_VERSION ?= 3.1.0
  22. MAX_APISIX_VERSION ?= 3.1.0
  23. IMAGE_NAME = apache/apisix
  24. IMAGE_TAR_NAME = apache_apisix
  25. APISIX_DASHBOARD_VERSION ?= $(shell echo ${APISIX_DASHBOARD_VERSION:=3.0.0})
  26. APISIX_DASHBOARD_IMAGE_NAME = apache/apisix-dashboard
  27. APISIX_DASHBOARD_IMAGE_TAR_NAME = apache_apisix_dashboard
  28. # Makefile ENV
  29. ENV_OS_NAME ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
  30. ENV_APISIX_TAR_NAME ?= $(IMAGE_TAR_NAME)_$(APISIX_VERSION)
  31. ENV_APISIX_IMAGE_TAG_NAME ?= $(IMAGE_NAME):$(APISIX_VERSION)
  32. ENV_DOCKER ?= docker
  33. # Makefile basic extension function
  34. _color_red =\E[1;31m
  35. _color_green =\E[1;32m
  36. _color_yellow =\E[1;33m
  37. _color_blue =\E[1;34m
  38. _color_wipe =\E[0m
  39. define func_echo_status
  40. printf "[$(_color_blue) info $(_color_wipe)] %s\n" $(1)
  41. endef
  42. define func_echo_warn_status
  43. printf "[$(_color_yellow) info $(_color_wipe)] %s\n" $(1)
  44. endef
  45. define func_echo_success_status
  46. printf "[$(_color_green) info $(_color_wipe)] %s\n" $(1)
  47. endef
  48. # Makefile target
  49. ### build-on-centos : Build apache/apisix:xx-centos image
  50. .PHONY: build-on-centos
  51. build-on-centos:
  52. @$(call func_echo_status, "$@ -> [ Start ]")
  53. $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-centos -f ./centos/Dockerfile centos
  54. @$(call func_echo_success_status, "$@ -> [ Done ]")
  55. ### build-on-debian-dev : Build apache/apisix:xx-debian-dev image
  56. .PHONY: build-on-debian-dev
  57. build-on-debian-dev:
  58. @$(call func_echo_status, "$@ -> [ Start ]")
  59. $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-debian-dev -f ./debian-dev/Dockerfile debian-dev
  60. @$(call func_echo_success_status, "$@ -> [ Done ]")
  61. ### build-on-debian : Build apache/apisix:xx-debian image
  62. .PHONY: build-on-debian
  63. build-on-debian:
  64. @$(call func_echo_status, "$@ -> [ Start ]")
  65. $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-debian -f ./debian/Dockerfile debian
  66. @$(call func_echo_success_status, "$@ -> [ Done ]")
  67. ### push-on-alpine : Push apache/apisix:dev image
  68. .PHONY: push-multiarch-dev-on-debian
  69. push-multiarch-dev-on-debian:
  70. @$(call func_echo_status, "$@ -> [ Start ]")
  71. $(ENV_DOCKER) buildx build --network=host --push \
  72. -t $(IMAGE_NAME):dev \
  73. --platform linux/amd64,linux/arm64 \
  74. -f ./debian-dev/Dockerfile debian-dev
  75. @$(call func_echo_success_status, "$@ -> [ Done ]")
  76. ### push-multiarch-on-debian : Push apache/apisix:xx-debian image
  77. .PHONY: push-multiarch-on-debian
  78. push-multiarch-on-debian:
  79. @$(call func_echo_status, "$@ -> [ Start ]")
  80. $(ENV_DOCKER) buildx build --network=host --push \
  81. -t $(ENV_APISIX_IMAGE_TAG_NAME)-debian \
  82. --platform linux/amd64,linux/arm64 \
  83. -f ./debian/Dockerfile debian
  84. @$(call func_echo_success_status, "$@ -> [ Done ]")
  85. ### push-multiarch-on-centos : Push apache/apisix:xx-centos image
  86. .PHONY: push-multiarch-on-centos
  87. push-multiarch-on-centos:
  88. @$(call func_echo_status, "$@ -> [ Start ]")
  89. $(ENV_DOCKER) buildx build --network=host --push \
  90. -t $(ENV_APISIX_IMAGE_TAG_NAME)-centos \
  91. --platform linux/amd64,linux/arm64 \
  92. -f ./centos/Dockerfile centos
  93. @$(call func_echo_success_status, "$@ -> [ Done ]")
  94. ### push-multiarch-on-latest : Push apache/apisix:latest image
  95. .PHONY: push-multiarch-on-latest
  96. # Here we choose to check the max APISIX version instead of the patch version, so that
  97. # we can release a patch version for a non-LTS version. For example, release a version
  98. # to solve security issue.
  99. push-multiarch-on-latest:
  100. @$(call func_echo_status, "$@ -> [ Start ]")
  101. @if [ "$(shell echo "$(APISIX_VERSION) $(MAX_APISIX_VERSION)" | tr " " "\n" | sort -rV | head -n 1)" == "$(APISIX_VERSION)" ]; then \
  102. $(ENV_DOCKER) buildx build --network=host --push \
  103. -t $(IMAGE_NAME):latest \
  104. --platform linux/amd64,linux/arm64 \
  105. -f ./debian/Dockerfile debian; \
  106. fi
  107. @$(call func_echo_success_status, "$@ -> [ Done ]")
  108. ### build-all-in-one : Build All in one Docker container for Apache APISIX
  109. .PHONY: build-all-in-one
  110. build-all-in-one:
  111. @$(call func_echo_status, "$@ -> [ Start ]")
  112. $(ENV_DOCKER) build -t $(IMAGE_NAME):whole -f ./all-in-one/apisix/Dockerfile .
  113. @$(call func_echo_success_status, "$@ -> [ Done ]")
  114. ### build-dashboard-all-in-one : Build All in one Docker container for Apache APISIX-dashboard
  115. .PHONY: build-dashboard-all-in-one
  116. build-dashboard-all-in-one:
  117. @$(call func_echo_status, "$@ -> [ Start ]")
  118. $(ENV_DOCKER) build -t $(APISIX_DASHBOARD_IMAGE_NAME):whole -f ./all-in-one/apisix-dashboard/Dockerfile .
  119. @$(call func_echo_success_status, "$@ -> [ Done ]")
  120. ### save-centos-tar : tar apache/apisix:xx-centos image
  121. .PHONY: save-centos-tar
  122. save-centos-tar:
  123. @$(call func_echo_status, "$@ -> [ Start ]")
  124. mkdir -p package
  125. $(ENV_DOCKER) save -o ./package/$(ENV_APISIX_TAR_NAME)-centos.tar $(ENV_APISIX_IMAGE_TAG_NAME)-centos
  126. @$(call func_echo_success_status, "$@ -> [ Done ]")
  127. ### save-debian-tar : tar apache/apisix:xx-debian image
  128. .PHONY: save-debian-tar
  129. save-debian-tar:
  130. @$(call func_echo_status, "$@ -> [ Start ]")
  131. mkdir -p package
  132. $(ENV_DOCKER) save -o ./package/$(ENV_APISIX_TAR_NAME)-debian.tar $(ENV_APISIX_IMAGE_TAG_NAME)-debian
  133. @$(call func_echo_success_status, "$@ -> [ Done ]")
  134. ### build-dashboard-centos : Build apache/dashboard:tag image on centos
  135. .PHONY: build-dashboard-centos
  136. build-dashboard-centos:
  137. @$(call func_echo_status, "$@ -> [ Start ]")
  138. $(ENV_DOCKER) build -t $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION) \
  139. --build-arg APISIX_DASHBOARD_TAG=v$(APISIX_DASHBOARD_VERSION) \
  140. -f ./dashboard/Dockerfile.centos .
  141. @$(call func_echo_success_status, "$@ -> [ Done ]")
  142. ### build-dashboard-alpine : Build apache/dashboard:tag image on alpine
  143. .PHONY: build-dashboard-alpine
  144. build-dashboard-alpine:
  145. @$(call func_echo_status, "$@ -> [ Start ]")
  146. $(ENV_DOCKER) build -t $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION) \
  147. --build-arg APISIX_DASHBOARD_TAG=v$(APISIX_DASHBOARD_VERSION) \
  148. -f ./dashboard/Dockerfile.alpine .
  149. @$(call func_echo_success_status, "$@ -> [ Done ]")
  150. ### push-multiarch-dashboard : Build and push multiarch apache/dashboard:tag image
  151. .PHONY: push-multiarch-dashboard
  152. push-multiarch-dashboard:
  153. @$(call func_echo_status, "$@ -> [ Start ]")
  154. $(ENV_DOCKER) buildx build --push \
  155. -t $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION)-alpine \
  156. --build-arg APISIX_DASHBOARD_TAG=v$(APISIX_DASHBOARD_VERSION) \
  157. --platform linux/amd64,linux/arm64 \
  158. -f ./dashboard/Dockerfile.alpine .
  159. $(ENV_DOCKER) buildx build --push \
  160. -t $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION)-centos \
  161. --build-arg APISIX_DASHBOARD_TAG=v$(APISIX_DASHBOARD_VERSION) \
  162. --platform linux/amd64,linux/arm64 \
  163. -f ./dashboard/Dockerfile.centos .
  164. $(ENV_DOCKER) buildx build --push \
  165. -t $(APISIX_DASHBOARD_IMAGE_NAME):latest \
  166. --build-arg APISIX_DASHBOARD_TAG=v$(APISIX_DASHBOARD_VERSION) \
  167. --platform linux/amd64,linux/arm64 \
  168. -f ./dashboard/Dockerfile.centos .
  169. @$(call func_echo_success_status, "$@ -> [ Done ]")
  170. ### save-dashboard-centos-tar : tar apache/apisix-dashboard:tag image
  171. .PHONY: save-dashboard-centos-tar
  172. save-dashboard-centos-tar:
  173. @$(call func_echo_status, "$@ -> [ Start ]")
  174. mkdir -p package
  175. $(ENV_DOCKER) save -o ./package/$(APISIX_DASHBOARD_IMAGE_TAR_NAME)_$(APISIX_DASHBOARD_VERSION)-centos.tar $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION)
  176. @$(call func_echo_success_status, "$@ -> [ Done ]")
  177. ### save-dashboard-alpine-tar : tar apache/apisix-dashboard:tag image
  178. .PHONY: save-dashboard-alpine-tar
  179. save-dashboard-alpine-tar:
  180. @$(call func_echo_status, "$@ -> [ Start ]")
  181. mkdir -p package
  182. $(ENV_DOCKER) save -o ./package/$(APISIX_DASHBOARD_IMAGE_TAR_NAME)_$(APISIX_DASHBOARD_VERSION)-alpine.tar $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION)
  183. @$(call func_echo_success_status, "$@ -> [ Done ]")
  184. ### help : Show Makefile rules
  185. .PHONY: help
  186. help:
  187. @$(call func_echo_success_status, "Makefile rules:")
  188. @echo
  189. @if [ '$(ENV_OS_NAME)' = 'darwin' ]; then \
  190. 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; \
  191. else \
  192. awk '{ if(match($$0, /^\s*#{3}\s*([^:]+)\s*:\s*(.*)$$/, res)){ printf(" make %-25s : %-10s\n", res[1], res[2]) } }' Makefile; \
  193. fi
  194. @echo