Makefile 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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.13.2
  21. IMAGE_NAME = apache/apisix
  22. IMAGE_TAR_NAME = apache_apisix
  23. APISIX_DASHBOARD_VERSION ?= 2.13
  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 --network=host -t $(ENV_APISIX_IMAGE_TAG_NAME)-centos -f ./centos/Dockerfile .
  52. @$(call func_echo_success_status, "$@ -> [ Done ]")
  53. ### build-on-alpine : Build apache/apisix:xx-alpine image
  54. .PHONY: build-on-alpine
  55. build-on-alpine:
  56. @$(call func_echo_status, "$@ -> [ Start ]")
  57. $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-alpine -f ./alpine/Dockerfile .
  58. @$(call func_echo_success_status, "$@ -> [ Done ]")
  59. ### build-on-debian-dev : Build apache/apisix:xx-debian-dev image
  60. .PHONY: build-on-debian-dev
  61. build-on-debian-dev:
  62. @$(call func_echo_status, "$@ -> [ Start ]")
  63. $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-debian-dev -f ./debian-dev/Dockerfile .
  64. @$(call func_echo_success_status, "$@ -> [ Done ]")
  65. ### push-on-centos : Push apache/apisix:xx-centos image
  66. # centos not support multiarch since it reply on x86 rpm package
  67. .PHONY: push-on-centos
  68. push-on-centos:
  69. @$(call func_echo_status, "$@ -> [ Start ]")
  70. $(ENV_DOCKER) push $(ENV_APISIX_IMAGE_TAG_NAME)-centos
  71. $(ENV_DOCKER) build -t $(IMAGE_NAME):latest -f ./centos/Dockerfile .
  72. $(ENV_DOCKER) push $(IMAGE_NAME):latest
  73. @$(call func_echo_success_status, "$@ -> [ Done ]")
  74. ### push-on-alpine : Push apache/apisix:xx-alpine image
  75. .PHONY: push-multiarch-on-alpine
  76. push-multiarch-on-alpine:
  77. @$(call func_echo_status, "$@ -> [ Start ]")
  78. $(ENV_DOCKER) buildx build --push \
  79. -t $(ENV_APISIX_IMAGE_TAG_NAME)-alpine \
  80. --platform linux/amd64,linux/arm64 \
  81. -f ./alpine/Dockerfile .
  82. @$(call func_echo_success_status, "$@ -> [ Done ]")
  83. ### push-on-alpine : Push apache/apisix:dev image
  84. .PHONY: push-multiarch-dev-on-debian
  85. push-multiarch-dev-on-debian:
  86. @$(call func_echo_status, "$@ -> [ Start ]")
  87. $(ENV_DOCKER) buildx build --network=host --push \
  88. -t $(IMAGE_NAME):dev \
  89. --platform linux/amd64,linux/arm64 \
  90. -f ./debian-dev/Dockerfile .
  91. @$(call func_echo_success_status, "$@ -> [ Done ]")
  92. ### build-on-alpine-cn : Build apache/apisix:xx-alpine image (for chinese)
  93. .PHONY: build-on-alpine-cn
  94. build-on-alpine-cn:
  95. @$(call func_echo_status, "$@ -> [ Start ]")
  96. $(ENV_DOCKER) build -t $(ENV_APISIX_IMAGE_TAG_NAME)-alpine --build-arg APISIX_VERSION=$(APISIX_VERSION) --build-arg ENABLE_PROXY=true -f alpine/Dockerfile alpine
  97. @$(call func_echo_success_status, "$@ -> [ Done ]")
  98. ### build-all-in-one : Build All in one Docker container for Apache APISIX
  99. .PHONY: build-all-in-one
  100. build-all-in-one:
  101. @$(call func_echo_status, "$@ -> [ Start ]")
  102. $(ENV_DOCKER) build -t $(IMAGE_NAME):whole -f ./all-in-one/apisix/Dockerfile .
  103. @$(call func_echo_success_status, "$@ -> [ Done ]")
  104. ### build-dashboard-all-in-one : Build All in one Docker container for Apache APISIX-dashboard
  105. .PHONY: build-dashboard-all-in-one
  106. build-dashboard-all-in-one:
  107. @$(call func_echo_status, "$@ -> [ Start ]")
  108. $(ENV_DOCKER) build -t $(APISIX_DASHBOARD_IMAGE_NAME):whole -f ./all-in-one/apisix-dashboard/Dockerfile .
  109. @$(call func_echo_success_status, "$@ -> [ Done ]")
  110. ### save-centos-tar : tar apache/apisix:xx-centos image
  111. .PHONY: save-centos-tar
  112. save-centos-tar:
  113. @$(call func_echo_status, "$@ -> [ Start ]")
  114. mkdir -p package
  115. $(ENV_DOCKER) save -o ./package/$(ENV_APISIX_TAR_NAME)-centos.tar $(ENV_APISIX_IMAGE_TAG_NAME)-centos
  116. @$(call func_echo_success_status, "$@ -> [ Done ]")
  117. ### save-alpine-tar : tar apache/apisix:xx-alpine image
  118. .PHONY: save-alpine-tar
  119. save-alpine-tar:
  120. @$(call func_echo_status, "$@ -> [ Start ]")
  121. mkdir -p package
  122. $(ENV_DOCKER) save -o ./package/$(ENV_APISIX_TAR_NAME)-alpine.tar $(ENV_APISIX_IMAGE_TAG_NAME)-alpine
  123. @$(call func_echo_success_status, "$@ -> [ Done ]")
  124. ### build-dashboard-centos : Build apache/dashboard:tag image on centos
  125. .PHONY: build-dashboard-centos
  126. build-dashboard-centos:
  127. @$(call func_echo_status, "$@ -> [ Start ]")
  128. $(ENV_DOCKER) build -t $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION) -f ./dashboard/Dockerfile.centos .
  129. @$(call func_echo_success_status, "$@ -> [ Done ]")
  130. ### build-dashboard-alpine : Build apache/dashboard:tag image on alpine
  131. .PHONY: build-dashboard-alpine
  132. build-dashboard-alpine:
  133. @$(call func_echo_status, "$@ -> [ Start ]")
  134. $(ENV_DOCKER) build -t $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION) -f ./dashboard/Dockerfile.alpine .
  135. @$(call func_echo_success_status, "$@ -> [ Done ]")
  136. ### push-multiarch-dashboard : Build and push multiarch apache/dashboard:tag image
  137. .PHONY: push-multiarch-dashboard
  138. push-multiarch-dashboard:
  139. @$(call func_echo_status, "$@ -> [ Start ]")
  140. $(ENV_DOCKER) buildx build --push \
  141. -t $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION)-alpine \
  142. --build-arg APISIX_DASHBOARD_VERSION=release/$(APISIX_DASHBOARD_VERSION) \
  143. --platform linux/amd64,linux/arm64 \
  144. -f ./dashboard/Dockerfile.alpine .
  145. $(ENV_DOCKER) buildx build --push \
  146. -t $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION)-centos \
  147. --build-arg APISIX_DASHBOARD_VERSION=release/$(APISIX_DASHBOARD_VERSION) \
  148. --platform linux/amd64,linux/arm64 \
  149. -f ./dashboard/Dockerfile.centos .
  150. $(ENV_DOCKER) buildx build --push \
  151. -t $(APISIX_DASHBOARD_IMAGE_NAME):latest \
  152. --build-arg APISIX_DASHBOARD_VERSION=release/$(APISIX_DASHBOARD_VERSION) \
  153. --platform linux/amd64,linux/arm64 \
  154. -f ./dashboard/Dockerfile.centos .
  155. @$(call func_echo_success_status, "$@ -> [ Done ]")
  156. ### save-dashboard-centos-tar : tar apache/apisix-dashboard:tag image
  157. .PHONY: save-dashboard-centos-tar
  158. save-dashboard-centos-tar:
  159. @$(call func_echo_status, "$@ -> [ Start ]")
  160. mkdir -p package
  161. $(ENV_DOCKER) save -o ./package/$(APISIX_DASHBOARD_IMAGE_TAR_NAME)_$(APISIX_DASHBOARD_VERSION)-centos.tar $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION)
  162. @$(call func_echo_success_status, "$@ -> [ Done ]")
  163. ### save-dashboard-alpine-tar : tar apache/apisix-dashboard:tag image
  164. .PHONY: save-dashboard-alpine-tar
  165. save-dashboard-alpine-tar:
  166. @$(call func_echo_status, "$@ -> [ Start ]")
  167. mkdir -p package
  168. $(ENV_DOCKER) save -o ./package/$(APISIX_DASHBOARD_IMAGE_TAR_NAME)_$(APISIX_DASHBOARD_VERSION)-alpine.tar $(APISIX_DASHBOARD_IMAGE_NAME):$(APISIX_DASHBOARD_VERSION)
  169. @$(call func_echo_success_status, "$@ -> [ Done ]")
  170. ### help : Show Makefile rules
  171. .PHONY: help
  172. help:
  173. @$(call func_echo_success_status, "Makefile rules:")
  174. @echo
  175. @if [ '$(ENV_OS_NAME)' = 'darwin' ]; then \
  176. 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; \
  177. else \
  178. awk '{ if(match($$0, /^\s*#{3}\s*([^:]+)\s*:\s*(.*)$$/, res)){ printf(" make %-25s : %-10s\n", res[1], res[2]) } }' Makefile; \
  179. fi
  180. @echo