forked from kubevirt/kubevirt.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
225 lines (199 loc) · 8.83 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
# COLORS
RED := $(shell tput -Txterm setaf 1)
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
VIOLET := $(shell tput -Txterm setaf 5)
AQUA := $(shell tput -Txterm setaf 6)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
SELINUX := $(shell [ -x /usr/sbin/getenforce ] && /usr/sbin/getenforce)
TARGET_MAX_CHAR_NUM=20
## Show help
help:
@echo ''
@echo 'Makefile for website jekyll application'
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Env Variables:'
@printf " ${YELLOW}CONTAINER_ENGINE${RESET}\tSet container engine, [*podman*, docker]\n"
@printf " ${YELLOW}BUILD_ENGINE${RESET}\t\tSet build engine, [*podman*, buildah, docker]\n"
@printf " ${YELLOW}SELINUX_ENABLED${RESET}\tEnable SELinux on containers, [False, True] Will attempt autodetection if unset.\n"
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET}\t${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
envvar:
ifndef BUILD_ENGINE
@$(eval export BUILD_ENGINE=podman build . -t)
else
ifeq ($(shell test "${BUILD_ENGINE}" == "podman" || test "${BUILD_ENGINE}" == "podman build . -t" && printf true), true)
@$(eval export BUILD_ENGINE=podman build . -t)
else ifeq ($(shell test "${BUILD_ENGINE}" == "buildah" || test "${BUILD_ENGINE}" == "buildah build-using-dockerfile -t" && printf "true"), true)
@$(eval export BUILD_ENGINE=buildah build-using-dockerfile -t)
else ifeq ($(shell test "${BUILD_ENGINE}" == "docker" || test "${BUILD_ENGINE}" == "docker build . -t" && printf "true"), true)
@$(eval export BUILD_ENGINE=docker build . -t)
else
@echo ${BUILD_ENGINE}
@echo "Invalid value for BUILD_ENGINE ... exiting"
endif
endif
ifndef CONTAINER_ENGINE
@$(eval CONTAINER_ENGINE=podman)
else
ifeq ($(shell test "$(CONTAINER_ENGINE)" = "podman" && printf true), true)
@$(eval export CONTAINER_ENGINE=podman)
else ifeq ($(shell test "$(CONTAINER_ENGINE)" = "docker" && printf "true"), true)
@$(eval export CONTAINER_ENGINE=docker)
else
@echo ${CONTAINER_ENGINE}
@echo "Invalid value for CONTAINER_ENGINE ... exiting"
endif
endif
ifndef DEBUG
@$(eval export DEBUG=@)
else
ifeq ($(shell test "$(DEBUG)" = True -o \
"$(DEBUG)" = true && printf "true"), true)
@$(eval export DEBUG=)
else
@$(eval export DEBUG=@)
endif
endif
ifdef SELINUX_ENABLED
ifeq ($(shell test "$(SELINUX_ENABLED)" = True -o \
"$(SELINUX_ENABLED)" = true && printf "true"), true)
@$(eval export SELINUX_ENABLED=,Z)
else
@$(eval export SELINUX_ENABLED='')
endif
else
ifeq ($(SELINUX), Enforcing)
@$(eval export SELINUX_ENABLED=,Z)
endif
endif
@echo
ifndef IMGTAG
@$(eval export IMGTAG=localhost/kubevirt-kubevirt.github.io)
else
ifeq ($(shell test $IMGTAG > /dev/null 2>&1 && printf "true"), true)
@echo WARN: Using IMGTAG=$$IMGTAG
@echo
else
@$(eval export IMGTAG=localhost/kubevirt-kubevirt.github.io)
endif
endif
## Build site. This target should only be used by Netlify and Prow
build: envvar
@echo "${GREEN}Makefile: Build jekyll site${RESET}"
# which $(RUBY)
scripts/update_changelog.sh
rake
touch _site/.nojekyll
## Build image localhost/kubevirt-kubevirt.github.io
build_img: | envvar
@echo "${GREEN}Makefile: Building Image ${RESET}"
${DEBUG}if [ ! -e "./Dockerfile" ]; then \
IMAGE="`echo $${IMGTAG} | sed -e s#\'##g -e s#localhost\/## -e s#:latest##`"; \
if [ "`curl https://raw.githubusercontent.com/kubevirt/project-infra/master/images/kubevirt-kubevirt.github.io/Dockerfile -o ./Dockerfile -w '%{http_code}\n' -s`" != "200" ]; then \
echo "curl Dockerfile failed... exitting!"; \
exit 2; \
else \
REMOTE=1; \
fi; \
else \
IMAGE="`echo $${TAG} | sed -e s#\'##g -e s#localhost\/## -e s#:latest##`"; \
echo "DOCKERFILE file: ./Dockerfile"; \
echo "Be sure to add changes to upstream: kubevirt/project-infra/master/images/${IMGTAG}/Dockerfile"; \
echo; \
fi; \
${CONTAINER_ENGINE} rmi ${IMGTAG} 2> /dev/null || echo -n; \
${BUILD_ENGINE} ${IMGTAG}; \
if [ "$${REMOTE}" ]; then rm -f Dockerfile > /dev/null 2>&1; fi
## Check external, internal links and links/selectors to userguide on website content
check_links: | envvar stop
@echo -n "${GREEN}Makefile: Check external and internal links${RESET}"
${DEBUG}${CONTAINER_ENGINE} run -it --rm --name website --net=host -v ${PWD}:/srv/:ro${SELINUX_ENABLED} -v /dev/null:/srv/Gemfile.lock --mount type=tmpfs,destination=/srv/_site --mount type=tmpfs,destination=/srv/.jekyll-cache ${IMGTAG} /bin/bash -c 'cd /srv; rake -- -u'
@echo
@echo
@echo "${GREEN}Makefile: Check url selectors to user-guide${RESET}"
#BEGIN BIG SHELL SCRIPT
${DEBUG}${CONTAINER_ENGINE} run -it --rm --name website --net=host -v ${PWD}:/srv:ro${SELINUX_ENABLED} -v /dev/null:/srv/Gemfile.lock --mount type=tmpfs,destination=/srv/_site --mount type=tmpfs,destination=/srv/.jekyll-cache ${IMGTAG} /bin/bash -c 'cd /srv; rake --trace links:userguide_selectors' | sed -n -e '/HTML-Proofer finished successfully./,$$p' | grep -v 'HTML-Proofer finished successfully.' > links 2> /dev/null; \
${CONTAINER_ENGINE} run -it --rm --name website --net=host -v ${PWD}:/srv:ro${SELINUX_ENABLED} --mount type=tmpfs,destination=/srv/_site --workdir=/srv ${IMGTAG} /bin/bash -c \
"for i in \`cat ./links\`; do \
echo -n 'File: ' && echo \"\$${i}\" | cut -d',' -f 2; \
echo -n 'Link: ' && echo \"\$${i}\" | cut -d',' -f 1; \
OPENSSL_CONF=/etc/ssl casperjs test --concise --arg=\"\$${i}\" /src/check_selectors.js; \
if [ \"\$$?\" != 0 ]; then break; fi; \
echo; \
done" > RETVAL; \
echo && cat RETVAL; \
if `egrep "FAIL 1 test executed" RETVAL > /dev/null`; then rm -rf RETVAL links && exit 2; \
else \
rm -rf RETVAL links; \
echo "Complete!"; \
fi
#END BIG SHELL SCRIPT
## Check markdown linting
check_lint: | envvar stop
@echo "${GREEN}Makefile: Linting Markdown files using ${LINT_IMAGE}${RESET}"
${DEBUG}${CONTAINER_ENGINE} run -it --rm --name website --net=host -v ${PWD}:/srv/:ro${SELINUX_ENABLED} -v /dev/null:/srv/Gemfile.lock --mount type=tmpfs,destination=/srv/_site --mount type=tmpfs,destination=/srv/.jekyll-cache --workdir=/srv ${IMGTAG} /bin/bash -c 'markdownlint -c .markdownlint.yaml -i .markdownlintignore **/*.md'
@echo
## Check spelling on content
check_spelling: | envvar stop
@echo "${GREEN}Makefile: Check spelling on site content${RESET}"
${DEBUG}if [ ! -e "./yaspeller.json" ]; then \
echo "${WHITE}Downloading Dictionary file: https://raw.githubusercontent.com/kubevirt/project-infra/master/images/yaspeller/.yaspeller.json${RESET}"; \
if ! `curl -fs https://raw.githubusercontent.com/kubevirt/project-infra/master/images/yaspeller/.yaspeller.json -o yaspeller.json`; then \
echo "${RED}ERROR: Unable to curl yaspeller dictionary file${RESET}"; \
exit 2; \
else \
echo "${WHITE}yaspeller updated ${RESET}"; \
echo; \
REMOTE=1; \
fi; \
else \
echo "YASPELLER file: ./yaspeller.json"; \
echo "Be sure to add changes to upstream: kubevirt/project-infra/master/images/yaspeller/.yaspeller.json"; \
echo; \
fi; \
export IFS=$$'\n'; \
if `cat ./yaspeller.json 2>&1 | jq > /dev/null 2>&1`; then \
for i in `${CONTAINER_ENGINE} run -it --rm --name yaspeller -v ${PWD}:/srv:ro${SELINUX_ENABLED} -v /dev/null:/srv/Gemfile.lock -v ./yaspeller.json:/srv/yaspeller.json:ro${SELINUX_ENABLED} ${IMGTAG} /bin/bash -c 'echo; yaspeller -c /srv/yaspeller.json --only-errors --ignore-tags iframe,img,code,kbd,object,samp,script,style,var /srv'`; do \
if [[ "$${i}" =~ "✗" ]]; then \
RETVAL=2; \
fi; \
echo "$${i}" | sed -e 's/\/srv\//\.\//g'; \
done; \
else \
echo "${RED}ERROR: yaspeller dictionary file does not exist or is invalid json${RESET}"; \
RETVAL=1; \
fi; \
if [ "$${REMOTE}" ]; then \
rm -rf yaspeller.json > /dev/null 2>&1; \
fi; \
if [ "$${RETVAL}" ]; then exit 2; else echo "Complete!"; fi
## Run site. App available @ http://0.0.0.0:4000
run: | envvar stop
@echo "${GREEN}Makefile: Run site${RESET}"
for i in .jekyll-cache _site Gemfile.lock; do rm -rf ./"$${i}" 2> /dev/null; echo -n; done
${CONTAINER_ENGINE} run -d --name website --net=host -v ${PWD}:/srv:ro${SELINUX_ENABLED} -v /dev/null:/srv/Gemfile.lock:rw${SELINUX_ENABLED} --mount type=tmpfs,destination=/srv/_site --mount type=tmpfs,destination=/srv/.jekyll-cache --workdir=/srv ${IMGTAG} /bin/bash -c "jekyll serve --host=0.0.0.0 --trace --force_polling --future"
@echo
## Container status
status: | envvar
@echo "${GREEN}Makefile: Check container status${RESET}"
${CONTAINER_ENGINE} ps
@echo
## Stop running container
stop: | envvar
@echo "${GREEN}Makefile: Stop running container${RESET}"
${CONTAINER_ENGINE} rm -f website 2> /dev/null; echo
@echo -n