This repository has been archived by the owner on Jan 11, 2025. It is now read-only.
forked from fabiocicerchia/nginx-lua
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
225 lines (190 loc) · 7.71 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
# __ __
# .-----.-----.|__|.-----.--.--.______| |.--.--.---.-.
# | | _ || || |_ _|______| || | | _ |
# |__|__|___ ||__||__|__|__.__| |__||_____|___._|
# |_____|
#
# Copyright (c) 2020 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=1
else
SKIP=0
endif
ifeq ($(FORCE), 1)
SKIP=0
endif
BUILD_CMD:=./bin/docker-build.sh
PUSH_CMD:=./bin/docker-push.sh
TEST_CMD:=./bin/test.sh
SEC_CMD:=./bin/test-security.sh
META_CMD:=./bin/docker-metadata.sh
DISTROS=alpine amazonlinux centos 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)
build_targets=$(addprefix build-, $(DISTROS))
test_targets=$(addprefix test-, $(DISTROS))
push_targets=$(addprefix push-, $(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) 2020 Fabio Cicerchia. https://fabiocicerchia.it. MIT License"
echo "Repo: https://github.com/fabiocicerchia/nginx-lua"
echo ""
@gawk 'function fix_value(value, str) { \
padding=sprintf("%30s",""); \
ret=gensub("([^ ]+)", "\\1"padding"\n ", "g", " "value); \
ret=gensub("(^|\n)(.{33}) *", "\\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-Z_-]+\)?:.*?##/ { \
gsub("\\$$\\(build_targets\\)", fix_value("$(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); \
printf " \033[36m%-30s\033[0m %s\n", $$1, $$2 \
} /^##@/ { \
printf "\n\033[1m%s\033[0m\n", substr($$0, 5) \
}' $(MAKEFILE_LIST)
################################################################################
##@ BUILD
################################################################################
build-all: $(build_targets) ## build all dockerfiles
$(build_targets): ## build one distro
ifeq ($(SKIP), 1)
echo SKIPPING $@
else
DISTRO=$(subst build-,,$(@)); \
echo BUILDING $$DISTRO; \
$(BUILD_CMD) $$DISTRO 1; \
$(META_CMD) $$DISTRO 1
endif
################################################################################
##@ BUILD MINIMAL
################################################################################
build-minimal-all: $(minimal_targets) ## build all dockerfiles (minimal)
$(minimal_targets): ## build one distro (minimal)
ifeq ($(SKIP), 1)
echo SKIPPING $@
else
DISTRO=$(subst build-minimal-,,$(@)); \
echo BUILDING $$DISTRO; \
$(BUILD_CMD) $$DISTRO 1 0
endif
################################################################################
##@ TESTING
################################################################################
test-all: $(test_targets) ## test all docker images
$(test_targets): ## test one docker image
ifeq ($(SKIP), 1)
echo SKIPPING $@
else
DISTRO=$(subst test-,,$(@)); \
echo TESTING $$DISTRO; \
$(TEST_CMD) $$DISTRO 1
endif
test-security: $(security_targets) ## test security all docker images
$(security_targets): ## test security one docker images
ifeq ($(SKIP), 1)
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), 1)
echo SKIPPING $@
else
DISTRO=$(subst push-,,$(@)); \
echo PUSHING $$DISTRO; \
$(PUSH_CMD) $$DISTRO 1
endif
################################################################################
##@ 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:${GH_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
tag: .setup_gitrepo ## create a git tag
git tag $(TAG_VER) -a -m "$(TAG_VER)"
git push origin --tags
release: ## create a github release
echo '{"tag_name": "${TAG_VER}", "target_commitish": "main", "name": "${TAG_VER}", "body": "' > BODY.json
make changelog >> BODY.json
echo '", "draft": false, "prerelease": false}' >> BODY.json
cat BODY.json | sed -e ':a' -e 'N' -e '$$!ba' -e 's/\n/\\n/g' | tee BODY.json
curl --data-binary @BODY.json \
"https://api.github.com/repos/fabiocicerchia/nginx-lua/releases?access_token=${GH_TOKEN}"
generate-supported-versions: ## generate supported_versions file
./bin/generate-supported-versions.sh
generate-dockerfiles: ## generate all dockerfiles
./bin/generate-dockerfiles.sh
generate-metadata: ## generate all metadata for docker images
for DISTRO in $(DISTROS); do \
$(META_CMD) $$DISTRO 0; \
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 "Changes:"
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 "Supported Versions:"
cat supported_versions | sed 's/[()"]//g' | tr 'A-Z' 'a-z' | sed 's/^/ - /'