Skip to content

Commit c1b4bfa

Browse files
feat: enhancement and minor optimization in Makefile (openresty#61)
1 parent f6683f8 commit c1b4bfa

File tree

1 file changed

+22
-33
lines changed

1 file changed

+22
-33
lines changed

Makefile

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,43 @@ image_base="centos"
2323
image_tag="7"
2424
iteration=0
2525

26-
# todo: optimize the code, too much duplicate code now.
26+
### function for building rpm
27+
define build_rpm
28+
docker build -t apache/$(1):$(version) --build-arg checkout_v=$(checkout) \
29+
-f ./dockerfiles/Dockerfile.$(2).rpm .
30+
endef
31+
32+
define package_rpm
33+
docker build -t apache/$(1)-packaged:$(version) \
34+
--build-arg VERSION=$(version) \
35+
--build-arg ITERATION=$(iteration) \
36+
--build-arg PACKAGE_VERSION=$(version) \
37+
-f ./dockerfiles/Dockerfile.package.$(1) .
38+
docker run -d --rm --name output --net="host" apache/$(1)-packaged:$(version)
39+
docker cp output:/output ${PWD}
40+
docker stop output
41+
docker system prune -a -f
42+
endef
2743

2844
### build apisix:
2945
.PHONY: build-apisix-rpm
3046
build-apisix-rpm:
31-
docker build -t apache/apisix:$(version) --build-arg checkout_v=$(checkout) \
32-
-f ./dockerfiles/Dockerfile.apisix.rpm .
47+
$(call build_rpm,apisix,apisix)
3348

3449
### build rpm for apisix:
3550
.PHONY: package-apisix-rpm
3651
package-apisix-rpm:
37-
docker build -t apache/apisix-packaged:$(version) \
38-
--build-arg VERSION=$(version) \
39-
--build-arg ITERATION=$(iteration) \
40-
--build-arg PACKAGE_VERSION=$(version) \
41-
-f ./dockerfiles/Dockerfile.package.apisix .
42-
docker run -d --rm --name output --net="host" apache/apisix-packaged:$(version)
43-
docker cp output:/output ${PWD}
44-
docker stop output
45-
docker system prune -a -f
52+
$(call package_rpm,apisix)
4653

4754
### build dashboard:
4855
.PHONY: build-dashboard-rpm
4956
build-dashboard-rpm:
50-
docker build -t apache/apisix-dashboard:$(version) --build-arg checkout_v=$(checkout) \
51-
-f ./dockerfiles/Dockerfile.dashboard.rpm .
57+
$(call build_rpm,apisix-dashboard,dashboard)
5258

5359
### build rpm for apisix dashboard:
5460
.PHONY: package-dashboard-rpm
5561
package-dashboard-rpm:
56-
docker build -t apache/apisix-dashboard-packaged:$(version) \
57-
--build-arg VERSION=$(version) \
58-
--build-arg ITERATION=$(iteration) \
59-
--build-arg PACKAGE_VERSION=$(version) \
60-
-f ./dockerfiles/Dockerfile.package.apisix-dashboard .
61-
docker run -d --rm --name output --net="host" apache/apisix-dashboard-packaged:$(version)
62-
docker cp output:/output ${PWD}
63-
docker stop output
64-
docker system prune -a -f
62+
$(call package_rpm,apisix-dashboard)
6563

6664
### build apisix-openresty:
6765
.PHONY: build-apisix-openresty-rpm
@@ -72,16 +70,7 @@ build-apisix-openresty-rpm:
7270
### build rpm for apisix-openresty:
7371
.PHONY: package-apisix-openresty-rpm
7472
package-apisix-openresty-rpm:
75-
docker build -t apache/apisix-openresty-packaged:$(version) \
76-
--build-arg VERSION=$(version) \
77-
--build-arg ITERATION=$(iteration) \
78-
--build-arg PACKAGE_VERSION=$(version) \
79-
-f ./dockerfiles/Dockerfile.package.apisix-openresty .
80-
docker run -d --rm --name output --net="host" apache/apisix-openresty-packaged:$(version)
81-
docker cp output:/output ${PWD}
82-
docker stop output
83-
docker system prune -a -f
84-
73+
$(call package_rpm,apisix-openresty)
8574

8675
### build fpm for packaging:
8776
.PHONY: build-fpm

0 commit comments

Comments
 (0)