forked from kubevirt/user-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
229 lines (202 loc) · 7.35 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
.PHONY: help envvar \
check_links check_spelling \
build build_img \
status run stop
# 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)
TARGET_MAX_CHAR_NUM=20
PYTHON ?= python3
PIP ?= pip3
LOCAL_SERVER_PORT ?= 8000
## Show help
help:
@echo ''
@echo 'Makefile for user-guide mkdocs 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]\n"
@printf " ${YELLOW}LOCAL_SERVER_PORT${RESET}\tPort on which the local mkdocs server will run, [*8000*]\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
endif
@echo
ifndef IMGTAG
@$(eval export IMGTAG=localhost/kubevirt-user-guide)
else
ifeq ($(shell test $IMGTAG > /dev/null 2>&1 && printf "true"), true)
@echo WARN: Using IMGTAG=$$IMGTAG
@echo
else
@$(eval export IMGTAG=localhost/kubevirt-user-guide)
endif
endif
## Build site. This target should only be used by Netlify and Prow
build: envvar
@echo "${GREEN}Makefile: Build mkdocs site${RESET}"
$(PYTHON) -m venv /tmp/venv
. /tmp/venv/bin/activate
$(PIP) install mkdocs mkdocs-awesome-pages-plugin mkdocs-htmlproofer-plugin mkdocs-material
@echo
@echo '*** BEGIN cat mkdocs.yml ***'
@cat mkdocs.yml
@echo '*** END cat mkdocs.yml ***'
mkdocs build -f mkdocs.yml -d site
## Build image localhost/kubevirt-user-guide
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##`"; \
echo "Downloading Dockerfile file: https://raw.githubusercontent.com/kubevirt/project-infra/main/images/kubevirt-user-guide/Dockerfile"; \
if ! `curl -f -s https://raw.githubusercontent.com/kubevirt/project-infra/main/images/kubevirt-user-guide/Dockerfile -o ./Dockerfile`; then \
echo "${RED}ERROR: Unable to curl Dockerfile... exiting!${RESET}"; \
exit 2; \
else \
echo "${WHITE}Dockerfile file updated${RESET}"; \
echo; \
REMOTE=1; \
fi; \
else \
IMAGE="`echo $${TAG} | sed -e s#\'##g -e s#localhost\/## -e s#:latest##`"; \
echo "Using Dockerfile file: ./Dockerfile"; \
echo "Be sure to add changes to upstream: kubevirt/project-infra/main/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 and internal links
check_links: | envvar stop
@echo "${GREEN}Makefile: Check external and internal links${RESET}"
${DEBUG}export IFS=$$'\n'; \
${CONTAINER_ENGINE} run \
-it \
--rm \
--name userguide \
-v ${PWD}:/srv:ro${SELINUX_ENABLED} \
-v /dev/null:/srv/Gemfile.lock \
--mount type=tmpfs,destination=/srv/site \
--workdir=/srv \
${IMGTAG} \
/bin/bash -c 'rake -- -u'
@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/main/images/yaspeller/.yaspeller.json${RESET}"; \
if ! `curl -f -s https://raw.githubusercontent.com/kubevirt/project-infra/main/images/yaspeller/.yaspeller.json -o yaspeller.json`; then \
echo "${RED}ERROR: Unable to curl yaspeller dictionary file... exiting!${RESET}"; \
exit 2; \
else \
echo "${WHITE}Dictionary file updated${RESET}"; \
echo; \
REMOTE=1; \
fi; \
else \
echo "YASPELLER file: ./yaspeller.json"; \
echo "Be sure to add changes to upstream: kubevirt/project-infra/main/images/yaspeller/.yaspeller.json"; \
echo; \
fi; \
if `jq -C . yaspeller.json > /dev/null 2>&1`; then \
${CONTAINER_ENGINE} run \
-it \
--rm \
--name userguide \
-v ${PWD}:/srv:ro${SELINUX_ENABLED} \
-v ${PWD}/yaspeller.json:/srv/yaspeller.json:ro${SELINUX_ENABLED} \
--workdir=/srv ${IMGTAG} \
/bin/bash -c 'yaspeller -c /srv/yaspeller.json --only-errors --ignore-tags iframe,img,code,kbd,object,samp,script,style,var /srv' | sed -e 's/\/srv/./g'; \
else \
echo "${RED}ERROR: yaspeller dictionary file does not exist or is invalid json ${RESET}"; \
exit 1; \
fi; \
if [ "$${REMOTE}" ]; then rm -f yaspeller.json > /dev/null 2>&1; fi
## Run site. App available @ http://0.0.0.0:8000
run: | envvar stop
@echo "${GREEN}Makefile: Run site${RESET}"
${CONTAINER_ENGINE} run \
-d \
--name userguide \
-p ${LOCAL_SERVER_PORT}:8000 \
-v ${PWD}:/srv:ro${SELINUX_ENABLED} \
-v /dev/null:/srv/Gemfile.lock:rw \
--mount type=tmpfs,destination=/srv/site \
${IMGTAG} \
/bin/bash -c "mkdocs build -f /srv/mkdocs.yml && mkdocs serve -f /srv/mkdocs.yml -a 0.0.0.0:8000"
@echo
@echo "${AQUA}Makefile: Server now running at [http://localhost:$(LOCAL_SERVER_PORT)]${RESET}"
@echo
## Container status
status: | envvar
@echo "${GREEN}Makefile: Check image status${RESET}"
${CONTAINER_ENGINE} ps
@echo
## Stop site
stop: | envvar
@echo "${GREEN}Makefile: Stop site${RESET}"
${CONTAINER_ENGINE} rm -f userguide 2> /dev/null; echo
@echo -n