forked from fabiocicerchia/nginx-lua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
270 lines (231 loc) · 10.2 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# __ __
# .-----.-----.|__|.-----.--.--.______| |.--.--.---.-.
# | | _ || || |_ _|______| || | | _ |
# |__|__|___ ||__||__|__|__.__| |__||_____|___._|
# |_____|
#
# Copyright (c) 2022 Fabio Cicerchia. https://fabiocicerchia.it. MIT License
# Repo: https://github.com/fabiocicerchia/nginx-lua
PAGER:=
DOCKERFILE_CHANGES=$(shell (git fetch origin main > /dev/null; git diff-tree --no-commit-id --name-only -r origin/main) | egrep "(nginx|tpl)/" | wc -l | tr -d ' ')
ifeq ($(DOCKERFILE_CHANGES), 0)
SKIP=YES
else
SKIP=NO
endif
ifeq ($(FORCE), YES)
SKIP=NO
endif
BUILD_CMD:=./bin/docker-build.py
PUSH_CMD:=./bin/docker-push.py
BUNDLE_CMD:=./bin/docker-bundle.py
TEST_CMD:=./bin/test.sh
SEC_CMD:=./bin/test-security.sh
META_CMD:=./bin/docker-metadata.py
META_ALL_CMD:=./bin/docker-metadata-all.py
DISTROS=almalinux alpine amazonlinux debian fedora ubuntu
PREVIOUS_TAG=$(shell git ls-remote --tags 2>&1 | awk '{print $$2}' | sort -r | head -n 1 | cut -d "/" -f3)
TAG_VER=$(shell date +'v1.%Y%m%d.%H%M%S')
CHANGELOG=$(shell make changelog)
amd64_distros=$(addprefix amd64-, $(DISTROS))
arm64_distros=$(addprefix arm64v8-, $(DISTROS))
classic_compat_distros_amd64=$(addsuffix -classic, $(amd64_distros)) $(addsuffix -compat, $(amd64_distros))
classic_compat_distros_arm64=$(addsuffix -classic, $(arm64_distros)) $(addsuffix -compat, $(arm64_distros))
build_targets_amd64=$(addprefix build-, $(classic_compat_distros_amd64))
build_targets_arm64=$(addprefix build-, $(classic_compat_distros_arm64))
build_targets=${build_targets_amd64} ${build_targets_arm64}
# CircleCI workaround
cci_arm64_distros=$(addprefix large-, $(DISTROS))
cci_amd64_distros=$(addprefix arm.medium-, $(DISTROS))
cci_arch_distros=$(cci_amd64_distros) $(cci_arm64_distros)
cci_classic_compat_distros=$(addsuffix -classic, $(cci_arch_distros)) $(addsuffix -compat, $(cci_arch_distros))
cci_build_targets=$(addprefix build-, $(cci_classic_compat_distros))
# / CircleCI workaround
test_targets=$(addprefix test-, $(DISTROS))
push_targets=$(addprefix push-, $(DISTROS))
bundle_targets=$(addprefix bundle-, $(DISTROS))
security_targets=$(addprefix test-security-, $(DISTROS))
minimal_targets=$(addprefix build-minimal-, $(DISTROS))
.PHONY: changelog
.SILENT: help changelog
default: help
################################################################################
##@ GENERIC
################################################################################
all: build-all test-all push-all ## build, test and push everything
################################################################################
# HELP
################################################################################
help: ## prints this help
echo " __ __ "
echo ".-----.-----.|__|.-----.--.--.______| |.--.--.---.-."
echo "| | _ || || |_ _|______| || | | _ |"
echo "|__|__|___ ||__||__|__|__.__| |__||_____|___._|"
echo " |_____|"
echo ""
echo "Copyright (c) 2022 Fabio Cicerchia. https://fabiocicerchia.it. MIT License"
echo "Repo: https://github.com/fabiocicerchia/nginx-lua"
echo ""
@gawk 'function fix_value(value, str) { \
padding=sprintf("%50s",""); \
ret=gensub("([^ ]+)", "\\1"padding"\n ", "g", " "value); \
ret=gensub("(^|\n)(.{53}) *", "\\1\\2\033[0m"str" \033[36m", "g", ret); \
ret=substr(ret, 3, length(ret)-16-length(str)); \
return ret; \
} \
BEGIN { \
FS = ":.*##"; \
printf "Use: make \033[36m<target>\033[0m\n"; \
} /^\$$?\(?[a-zA-Z0-9_-]+\)?:.*?##/ { \
gsub("\\$$\\(build_targets\\)", fix_value("$(build_targets)", $$2), $$1); \
gsub("\\$$\\(build_targets_amd64\\)", fix_value("$(build_targets_amd64)", $$2), $$1); \
gsub("\\$$\\(build_targets_arm64\\)", fix_value("$(build_targets_arm64)", $$2), $$1); \
gsub("\\$$\\(cci_build_targets\\)", fix_value("$(cci_build_targets)", $$2), $$1); \
gsub("\\$$\\(minimal_targets\\)", fix_value("$(minimal_targets)", $$2), $$1); \
gsub("\\$$\\(test_targets\\)", fix_value("$(test_targets)", $$2), $$1); \
gsub("\\$$\\(security_targets\\)", fix_value("$(security_targets)", $$2), $$1); \
gsub("\\$$\\(push_targets\\)", fix_value("$(push_targets)", $$2), $$1); \
gsub("\\$$\\(bundle_targets\\)", fix_value("$(bundle_targets)", $$2), $$1); \
printf " \033[36m%-50s\033[0m %s\n", $$1, $$2 \
} /^##@/ { \
printf "\n\033[1m%s\033[0m\n", substr($$0, 5) \
}' $(MAKEFILE_LIST)
################################################################################
##@ BUILD
################################################################################
build-all: build-amd64 build-arm64 ## build all dockerfiles
build-amd64: $(build_targets_amd64) ## build all distros in amd64 arch
build-arm64: $(build_targets_arm64) ## build all distros in arm64 arch
$(build_targets_amd64): ## build one distro in amd64 arch
TASK=$(@) make build-single
$(build_targets_arm64): ## build one distro in arm64/v8 arch
TASK=$(@) make build-single
$(cci_build_targets): ## build one distro in one arch (CircleCI internals)
TASK=$(@) make build-single
build-single:
ifeq ($(SKIP), YES)
echo "SKIPPING $@"
else
ARCH=$(shell echo $$TASK | cut -d"-" -f2); \
DISTRO=$(shell echo $$TASK | cut -d"-" -f3); \
COMPAT=$(shell echo $$TASK | grep "\-compat" | cut -d"-" -f4); \
echo "BUILDING $$DISTRO"; \
export DOCKER_CLI_EXPERIMENTAL=enabled; \
$(BUILD_CMD) "$$DISTRO" "$$COMPAT" "$$ARCH"; \
$(META_CMD) "$$DISTRO"
endif
################################################################################
##@ TESTING
################################################################################
test-all: $(test_targets) ## test all docker images
$(test_targets): ## test one docker image
ifeq ($(SKIP), YES)
echo "SKIPPING $@"
else
DISTRO=$(subst test-,,$(@)); \
echo "TESTING $$DISTRO"; \
$(TEST_CMD) "$$DISTRO" "amd64"
$(TEST_CMD) "$$DISTRO" "arm64"
endif
test-security: $(security_targets) ## test security all docker images
$(security_targets): ## test security one docker images
ifeq ($(SKIP), YES)
echo "SKIPPING $@"
else
DISTRO=$(subst test-security-,,$(@)); \
echo "SECURITY $$DISTRO"; \
$(SEC_CMD) "$$DISTRO"
endif
################################################################################
##@ PUSH
################################################################################
push-all: $(push_targets) ## push all docker images to docker hub
$(push_targets): ## push one docker images to docker hub
ifeq ($(SKIP), YES)
echo "SKIPPING $@"
else
DISTRO=$(subst push-,,$(@)); \
echo "PUSHING $$DISTRO"; \
$(PUSH_CMD) "$$DISTRO"
endif
################################################################################
##@ BUNDLE
################################################################################
$(bundle_targets): ## bundle multiple docker images into one
ifeq ($(SKIP), YES)
echo "SKIPPING $@"
else
DISTRO=$(subst bundle-,,$(@)); \
echo "BUNDLING $$DISTRO"; \
$(BUNDLE_CMD) "$$DISTRO" ""; \
$(BUNDLE_CMD) "$$DISTRO" "-compat"
endif
################################################################################
##@ DEPENDENCIES
################################################################################
# Ref: https://www.stereolabs.com/docs/docker/building-arm-container-on-x86/
qemu:
docker buildx create --name multiarch --use
sudo apt-get update
sudo apt-get install --force-yes qemu binfmt-support qemu-user-static # Install the qemu packages
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes # This step will execute the registering scripts
################################################################################
##@ UTILITIES
################################################################################
auto-update: generate-supported-versions generate-dockerfiles update-readme update-tags ## auto update supported versions, dockerfiles and tags
.setup_gitrepo:
git config --global user.name "fabiocicerchia"
git config --global user.email "[email protected]"
git remote set-url --push origin "https://fabiocicerchia:${GITHUB_TOKEN}@github.com/fabiocicerchia/nginx-lua.git"
auto-update-and-commit: .setup_gitrepo auto-update
git add -A || true; \
CHANGES=$(git status | grep "Changes to be committed" | wc -l | tr -d ' '); \
if [ "$$CHANGES" != "0" ]; then \
git commit -m "Automated updates"; \
git pull origin main || true; \
git push origin main; \
else \
exit 1; \
fi
auto-commit-metadata: .setup_gitrepo generate-metadata
git add -A || true; \
CHANGES=$(git status | grep "Changes to be committed" | wc -l | tr -d ' '); \
if [ "$$CHANGES" != "0" ]; then \
git commit -m "Automated metadata"; \
git pull origin main || true; \
git push origin main; \
else \
exit 1; \
fi
release: ## create a github release
wget https://github.com/tcnksm/ghr/releases/download/v0.14.0/ghr_v0.14.0_linux_amd64.tar.gz
tar xvzf ghr_v0.14.0_linux_amd64.tar.gz
IFS=$$'\n' ./ghr_v0.14.0_linux_amd64/ghr -b "$(shell make changelog)" $(TAG_VER)
generate-supported-versions: ## generate supported_versions file
./bin/generate-supported-versions.sh
generate-dockerfiles: ## generate all dockerfiles
./bin/generate-dockerfiles.py
generate-metadata: ## generate metadata for all OS docker images
for DISTRO in $(DISTROS); do \
$(META_CMD) $$DISTRO 0; \
done
generate-metadata-all: ## generate all metadata for all OS docker images
for DISTRO in $(DISTROS); do \
$(META_ALL_CMD) $$DISTRO; \
done
update-tags: ## update docker tags file
./bin/generate_tags.py | tee docs/TAGS.md
update-readme: ## update supported docker tags in readme
./bin/update-readme.sh
benchmark: ## benchmark (wip)
./bin/benchmark.sh
changelog: ## generate a changelog since previous tag
git fetch --all --tags > /dev/null
echo "## What's Changed"
git log --pretty=format:"- %B" $(PREVIOUS_TAG)..HEAD | tr '\r' '\n' | grep -Ev '^$$' > CHANGELOG
cat CHANGELOG | egrep -v "Automated (metadata|updates)" | sed -e 's/^*/-/' -e 's/"/\\"/g' -e 's/^[ \t]*//' -e 's/^-[ \t]*//' -e 's/^-[ \t]*//' -e 's/^/ - /' | awk '!x[$$0]++' | tee CHANGELOG
echo ""
echo "**Full Changelog**: https://github.com/fabiocicerchia/nginx-lua/compare/$(PREVIOUS_TAG)...$(TAG_VER)"
echo ""
echo "## Supported Versions"
cat supported_versions | sed 's/[()"]//g' | tr 'A-Z' 'a-z' | sed 's/^/ - /'