on master help sign in
LXC: utils/makefile.lxc (inital) add /.lxcenv.mk to contaiiners

Get LXC environment when building make targets. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commit86e79488aab3ff434c6682a9464ba2eee49158e9 authorMarkus Heiser <markus.heiser@darmarit.de> dateSun 15 Mar 2020, 17:01 (7 years ago) parent26b8565
7 files changed+99−43
Makefile+4−7 utils/lxc-searx.env+11 utils/lxc.sh+28−24 utils/makefile.include+13−1 utils/makefile.lxc+29 utils/makefile.python+7−6 utils/makefile.sphinx+7−5
Makefile+4−7
@@ -1,15 +1,12 @@
11# -*- coding: utf-8; mode: makefile-gmake -*-
22.DEFAULT_GOAL=help
33include ./.config.mk
4+include utils/makefile.include
45
56PYOBJECTS = searx
67DOC = docs
78PY_SETUP_EXTRAS ?= \[test\]
89
9−PYDIST=./dist/py
10−PYBUILD=./build/py
11−
12−include utils/makefile.include
1310include utils/makefile.python
1411include utils/makefile.sphinx
1512
@@ -32,9 +29,9 @@ help:
3229 @echo ' GIT_URL = $(GIT_URL)'
3330 @echo ' DOCS_URL = $(DOCS_URL)'
3431 @echo ''
35− @$(MAKE) -s -f utils/makefile.include make-help
32+ @$(MAKE) -e -s -f utils/makefile.include make-help
3633 @echo ''
37− @$(MAKE) -s -f utils/makefile.python python-help
34+ @$(MAKE) -e -s -f utils/makefile.python python-help
3835
3936PHONY += install
4037install: pyenvinstall
@@ -43,7 +40,7 @@ PHONY += uninstall
4340uninstall: pyenvuninstall
4441
4542PHONY += clean
46−clean: pyclean
43+clean: pyclean docs-clean
4744 $(call cmd,common_clean)
4845
4946PHONY += run
utils/lxc-searx.env+11
@@ -32,6 +32,7 @@ lxc_set_suite_env() {
3232 export MORTY_LISTEN="0.0.0.0:3000"
3333}
3434
35+lxc_suite_install_info="suite includes searx, morty & filtron"
3536lxc_suite_install() {
3637 (
3738 lxc_set_suite_env
@@ -46,6 +47,16 @@ lxc_suite_install() {
4647 )
4748}
4849
50+lxc_suite_prepare_buildhost() {
51+ (
52+ lxc_set_suite_env
53+ export FORCE_TIMEOUT=0
54+ "${LXC_REPO_ROOT}/utils/searx.sh" install buildhost
55+ rst_title "buildhost installation finished ($(hostname))" part
56+ echo
57+ )
58+}
59+
4960lxc_suite_info() {
5061 (
5162 lxc_set_suite_env
utils/lxc.sh+28−24
@@ -104,7 +104,8 @@ cmd
104104 -- run command '...' in all containers of the LXC suite
105105 :<name>: run command '...' in container <name>
106106install
107− :suite: install LXC suite, includes morty & filtron
107+ :suite: install LXC suite; ${lxc_suite_install_info}
108+ :buildhost: prepare LXC; buildhost
108109
109110EOF
110111 usage_images
@@ -224,12 +225,7 @@ main() {
224225 sudo_or_exit
225226 shift
226227 case $1 in
227− --)
228− shift
229− for name in "${CONTAINERS[@]}"; do
230− lxc_exec_cmd "${name}" "$@"
231− done
232− ;;
228+ --) shift; lxc_exec "$@" ;;
233229 ${LXC_HOST_PREFIX}-*)
234230 ! lxc_exists "$1" && usage_containers "unknown container: $1" && exit 42
235231 local name=$1
@@ -242,13 +238,15 @@ main() {
242238 install)
243239 sudo_or_exit
244240 case $2 in
245− suite) install_suite ;;
241+ suite) lxc_exec "${LXC_REPO_ROOT}/utils/lxc.sh" __install suite;;
242+ buildhost) lxc_exec "${LXC_REPO_ROOT}/utils/lxc.sh" __install buildhost;;
246243 *) usage "$_usage"; exit 42 ;;
247244 esac
248245 ;;
249246 __install)
250247 case $2 in
251248 suite) lxc_suite_install ;;
249+ buildhost) lxc_suite_prepare_buildhost ;;
252250 esac
253251 ;;
254252 doc)
@@ -263,7 +261,6 @@ main() {
263261
264262build_instances() {
265263 rst_title "Build LXC instances"
266− echo
267264 lxc_copy_images_localy
268265 echo
269266 rst_title "build containers" section
@@ -360,18 +357,6 @@ show_suite(){
360357 done
361358}
362359
363−install_suite() {
364− for i in "${CONTAINERS[@]}"; do
365− if ! lxc_exists "$i"; then
366− warn_msg "container ${_BBlue}$i${_creset} does not yet exists"
367− else
368− info_msg "[${_BBlue}${i}${_creset}] ${_BGreen}${LXC_REPO_ROOT}/utils/lxc.sh install suite${_creset}"
369− lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __install suite \
370− | prefix_stdout "[${_BBlue}${i}${_creset}] "
371− fi
372− done
373−}
374−
375360lxc_cmd() {
376361 for i in "${CONTAINERS[@]}"; do
377362 if ! lxc_exists "$i"; then
@@ -389,14 +374,23 @@ lxc_exec_cmd() {
389374 shift
390375 exit_val=
391376 info_msg "[${_BBlue}${name}${_creset}] ${_BGreen}${*}${_creset}"
392− lxc exec --cwd "${LXC_REPO_ROOT}" "${name}" -- bash -c "$*"
377+ lxc exec -t --cwd "${LXC_REPO_ROOT}" "${name}" -- bash -c "$*"
393378 exit_val=$?
394379 if [[ $exit_val -ne 0 ]]; then
395380 warn_msg "[${_BBlue}${name}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}"
396381 else
397382 info_msg "[${_BBlue}${name}${_creset}] exit code (${exit_val}) from ${_BGreen}${*}${_creset}"
398383 fi
399− echo
384+}
385+
386+lxc_exec() {
387+ for i in "${CONTAINERS[@]}"; do
388+ if ! lxc_exists "$i"; then
389+ warn_msg "container ${_BBlue}$i${_creset} does not yet exists"
390+ else
391+ lxc_exec_cmd "${i}" "$@" | prefix_stdout "[${_BBlue}${i}${_creset}] "
392+ fi
393+ done
400394}
401395
402396lxc_init_containers() {
@@ -449,7 +443,17 @@ lxc_boilerplate_containers() {
449443 boilerplate_script="${image_name}_boilerplate"
450444 boilerplate_script="${!boilerplate_script}"
451445
452− info_msg "[${_BBlue}${container_name}${_creset}] install boilerplate"
446+ info_msg "[${_BBlue}${container_name}${_creset}] install /.lxcenv.mk .."
447+ if lxc start -q "${container_name}" &>/dev/null; then
448+ sleep 5 # guest needs some time to come up and get an IP
449+ fi
450+ cat <<EOF | lxc exec "${container_name}" -- bash | prefix_stdout "[${_BBlue}${container_name}${_creset}] "
451+rm -f "/.lxcenv.mk"
452+ln -s "${LXC_REPO_ROOT}/utils/makefile.lxc" "/.lxcenv.mk"
453+ls -l "/.lxcenv.mk"
454+EOF
455+
456+ info_msg "[${_BBlue}${container_name}${_creset}] install boilerplate .."
453457 if lxc start -q "${container_name}" &>/dev/null; then
454458 sleep 5 # guest needs some time to come up and get an IP
455459 fi
utils/makefile.include+13−1
@@ -1,12 +1,23 @@
11# -*- coding: utf-8; mode: makefile-gmake -*-
22
3+ifeq (,$(wildcard /.lxcenv.mk))
4+PHONY += lxc-activate
5+lxc-activate:
6+ @$(MAKE) -s -f /share/searx/utils/makefile.lxc lxc-activate
7+else
8+ include /.lxcenv.mk
9+endif
10+
11+ifeq (,$(wildcard /.lxcenv.mk))
312make-help:
13+else
14+make-help: lxc-help
15+endif
416 @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
517 @echo ' make V=2 [targets] 2 => give reason for rebuild of target'
618
719quiet_cmd_common_clean = CLEAN $@
820 cmd_common_clean = \
9− rm -rf tests/build ;\
1021 find . -name '*.orig' -exec rm -f {} + ;\
1122 find . -name '*.rej' -exec rm -f {} + ;\
1223 find . -name '*~' -exec rm -f {} + ;\
@@ -126,3 +137,4 @@ echo-cmd = $(if $($(quiet)cmd_$(1)),echo '$(call escsq,$($(quiet)cmd_$(1)))$(ech
126137# printing commands
127138cmd = @$(echo-cmd) $(cmd_$(1))
128139
140+.PHONY: $(PHONY)
utils/makefile.lxcnew file+29
@@ -0,0 +1,29 @@
1+# -*- coding: utf-8; mode: makefile-gmake -*-
2+#
3+# LXC environment
4+# ===============
5+#
6+# To activate/deactivate LXC makefile environment in a container, set/unset link
7+# from root '/.lxcenv.mk' to *this* file::
8+#
9+# sudo make ./utils/makefile.lxc lxc-activate
10+# sudo make ./utils/makefile.lxc lxc-deactivate
11+
12+LXC_ENV_FOLDER=/lxc-$(shell hostname)
13+
14+lxc-help::
15+ @echo 'LXC: running in container LXC_ENV_FOLDER=$(LXC_ENV_FOLDER)'
16+
17+# If not activated, serve target 'lxc-activate' ..
18+ifeq (,$(wildcard /.lxcenv.mk))
19+PHONY += lxc-activate
20+lxc-activate:
21+ ln -s "$(abspath $(lastword $(MAKEFILE_LIST)))" "/.lxcenv.mk"
22+else
23+# .. and if activated, serve target 'lxc-deactivate'.
24+PHONY += lxc-deactivate
25+lxc-deactivate:
26+ rm /.lxcenv.mk
27+endif
28+
29+.PHONY: $(PHONY)
utils/makefile.python+7−6
@@ -5,11 +5,12 @@ PYOBJECTS ?=
55
66SITE_PYTHON ?=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))site-python
77export PYTHONPATH := $(SITE_PYTHON):$$PYTHONPATH
8+export PY_ENV PYDIST PYBUILD
89
910# folder where the python distribution takes place
10−PYDIST ?= ./py_dist
11+PYDIST = ./dist$(LXC_ENV_FOLDER)
1112# folder where the python intermediate build files take place
12−PYBUILD ?= ./py_build
13+PYBUILD = ./build$(LXC_ENV_FOLDER)
1314# python version to use
1415PY ?=3
1516PYTHON ?= python$(PY)
@@ -27,7 +28,7 @@ TEST_FOLDER ?= ./tests
2728TEST ?= .
2829
2930VTENV_OPTS ?=
30−PY_ENV = ./local/py$(PY)
31+PY_ENV = ./local$(LXC_ENV_FOLDER)/py$(PY)
3132PY_ENV_BIN = $(PY_ENV)/bin
3233PY_ENV_ACT = . $(PY_ENV_BIN)/activate
3334
@@ -45,7 +46,7 @@ python-help::
4546 @echo ' pylint - run pylint *linting*'
4647 @echo ' pytest - run *tox* test on python objects'
4748 @echo ' pydebug - run tests within a PDB debug session'
48− @echo ' pybuild - build python packages'
49+ @echo ' pybuild - build python packages ($(PYDIST) $(PYBUILD))'
4950 @echo ' pyclean - clean intermediate python objects'
5051 @echo ' targets using system users environment:'
5152 @echo ' py[un]install - [un]install python objects in editable mode'
@@ -169,7 +170,7 @@ quiet_cmd_pybuild = BUILD $@
169170quiet_cmd_pyclean = CLEAN $@
170171# remove 'build' folder since bdist_wheel does not care the --bdist-dir
171172 cmd_pyclean = \
172− rm -rf $(PYDIST) $(PYBUILD) ./local ./.tox *.egg-info ;\
173+ rm -rf $(PYDIST) $(PYBUILD) $(PY_ENV) ./.tox *.egg-info ;\
173174 find . -name '*.pyc' -exec rm -f {} + ;\
174175 find . -name '*.pyo' -exec rm -f {} + ;\
175176 find . -name __pycache__ -exec rm -rf {} +
@@ -241,7 +242,7 @@ pyenv-uninstall: $(PY_ENV)
241242
242243# runs python interpreter from ./local/py<N>/bin/python
243244pyenv-python: pyenv-install
244− cd ./local; ../$(PY_ENV_BIN)/python -i
245+ $(PY_ENV_BIN)/python -i
245246
246247# With 'dependency_links=' setuptools supports dependencies on packages hosted
247248# on other reposetories then PyPi, see "Packages Not On PyPI" [1]. The big
utils/makefile.sphinx+7−5
@@ -1,17 +1,19 @@
11# -*- coding: utf-8; mode: makefile-gmake -*-
22
3+export DOCS_FOLDER DOCS_BUILD DOCS_DIST BOOKS_FOLDER BOOKS_DIST
4+
35# You can set these variables from the command line.
46SPHINXOPTS ?=
57SPHINXBUILD ?= $(PY_ENV_BIN)/sphinx-build
68SPHINX_CONF ?= conf.py
79
8−DOCS_FOLDER ?= docs
9−DOCS_BUILD ?= build/docs
10−DOCS_DIST ?= dist/docs
10+DOCS_FOLDER = docs$(LXC_ENV_FOLDER)
11+DOCS_BUILD = build/docs$(LXC_ENV_FOLDER)
12+DOCS_DIST = dist/docs$(LXC_ENV_FOLDER)
1113GH_PAGES ?= gh-pages
1214
13−BOOKS_FOLDER ?= docs
14−BOOKS_DIST ?= dist/books
15+BOOKS_FOLDER = docs$(LXC_ENV_FOLDER)
16+BOOKS_DIST = dist/books$(LXC_ENV_FOLDER)
1517
1618ifeq ($(KBUILD_VERBOSE),1)
1719 SPHINX_VERBOSE = "-v"