xref: /openbmc/qemu/tests/docker/Makefile.include (revision 5dbefb87)
1324027c2SFam Zheng# Makefile for Docker tests
2324027c2SFam Zheng
36147c249SAlex Bennée.PHONY: docker docker-help docker-test docker-clean docker-image docker-qemu-src
4324027c2SFam Zheng
5660f7930SPaolo BonziniNULL :=
6660f7930SPaolo BonziniSPACE := $(NULL) #
7660f7930SPaolo BonziniCOMMA := ,
8660f7930SPaolo Bonzini
906746324SAlex BennéeHOST_ARCH = $(if $(ARCH),$(ARCH),$(shell uname -m))
1006746324SAlex Bennée
11be20302aSAlex Bennée# These variables can be set by the user to limit the set of docker
12be20302aSAlex Bennée# images and tests to a more restricted subset
13be20302aSAlex BennéeTESTS ?= %
14be20302aSAlex BennéeIMAGES ?= %
15be20302aSAlex Bennée
16324027c2SFam ZhengDOCKER_SUFFIX := .docker
17324027c2SFam ZhengDOCKER_FILES_DIR := $(SRC_PATH)/tests/docker/dockerfiles
18272e551bSPhilippe Mathieu-Daudé# we don't run tests on intermediate images (used as base by another image)
19a7181a28SAlex BennéeDOCKER_PARTIAL_IMAGES := debian10 debian11
20a7181a28SAlex Bennée# we don't directly build virtual images (they are used to build other images)
21a7181a28SAlex BennéeDOCKER_VIRTUAL_IMAGES := debian-bootstrap debian-toolchain empty
22be20302aSAlex Bennée__IMAGES := $(sort $(filter-out $(DOCKER_VIRTUAL_IMAGES), $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker)))))
23be20302aSAlex BennéeDOCKER_IMAGES := $(if $(IMAGES), $(filter $(IMAGES), $(__IMAGES)), $(__IMAGES))
24324027c2SFam ZhengDOCKER_TARGETS := $(patsubst %,docker-image-%,$(DOCKER_IMAGES))
25324027c2SFam Zheng# Use a global constant ccache directory to speed up repetitive builds
26324027c2SFam ZhengDOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
2734019198SAlex Bennéeifeq ($(HOST_ARCH),x86_64)
2834019198SAlex BennéeDOCKER_DEFAULT_REGISTRY := registry.gitlab.com/qemu-project/qemu
2934019198SAlex Bennéeendif
3034019198SAlex BennéeDOCKER_REGISTRY := $(if $(REGISTRY),$(REGISTRY),$(DOCKER_DEFAULT_REGISTRY))
31324027c2SFam Zheng
32be20302aSAlex Bennée__TESTS := $(notdir $(shell \
33324027c2SFam Zheng		find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f))
34be20302aSAlex BennéeDOCKER_TESTS := $(if $(TESTS), $(filter $(TESTS), $(__TESTS)), $(__TESTS))
35324027c2SFam Zheng
3605af039dSMarc-André LureauENGINE := auto
3705af039dSMarc-André Lureau
3805af039dSMarc-André LureauDOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py --engine $(ENGINE)
39e27cae26SAlex Bennée
40324027c2SFam ZhengCUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$)
41bc739b8eSPaolo BonziniDOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME)
42324027c2SFam Zheng
43b28ef6b9SPhilippe Mathieu-Daudé.DELETE_ON_ERROR: $(DOCKER_SRC_COPY)
44324027c2SFam Zheng$(DOCKER_SRC_COPY):
45324027c2SFam Zheng	@mkdir $@
4673fb4f1dSFam Zheng	$(if $(SRC_ARCHIVE), \
4773fb4f1dSFam Zheng		$(call quiet-command, cp "$(SRC_ARCHIVE)" $@/qemu.tar, \
4873fb4f1dSFam Zheng			"CP", "$@/qemu.tar"), \
49bc739b8eSPaolo Bonzini		$(call quiet-command, cd $(SRC_PATH) && scripts/archive-source.sh $@/qemu.tar, \
5073fb4f1dSFam Zheng			"GEN", "$@/qemu.tar"))
51324027c2SFam Zheng	$(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \
520bdb12c7SPeter Maydell		"COPY","RUNNER")
53324027c2SFam Zheng
54324027c2SFam Zhengdocker-qemu-src: $(DOCKER_SRC_COPY)
55324027c2SFam Zheng
56324027c2SFam Zhengdocker-image: ${DOCKER_TARGETS}
57324027c2SFam Zheng
58cff54773SAlex Bennée# General rule for building docker images. If we are a sub-make
59cff54773SAlex Bennée# invoked with SKIP_DOCKER_BUILD we still check the image is up to date
60cff54773SAlex Bennée# though
61cff54773SAlex Bennéeifdef SKIP_DOCKER_BUILD
62cff54773SAlex Bennéedocker-image-%: $(DOCKER_FILES_DIR)/%.docker
63cff54773SAlex Bennée	$(call quiet-command, \
64767b6bd2SAlex Bennée		$(DOCKER_SCRIPT) check --quiet qemu/$* $<, \
65cff54773SAlex Bennée		"CHECK", "$*")
66cff54773SAlex Bennéeelse
67324027c2SFam Zhengdocker-image-%: $(DOCKER_FILES_DIR)/%.docker
68324027c2SFam Zheng	$(call quiet-command,\
69767b6bd2SAlex Bennée		$(DOCKER_SCRIPT) build -t qemu/$* -f $< \
70e6f1306bSAlex Bennée		$(if $V,,--quiet) \
71e6f1306bSAlex Bennée		$(if $(NOCACHE),--no-cache, \
72e6f1306bSAlex Bennée			$(if $(DOCKER_REGISTRY),--registry $(DOCKER_REGISTRY))) \
73414a8ce5SAlex Bennée		$(if $(NOUSER),,--add-current-user) \
744c84f662SPhilippe Mathieu-Daudé		$(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\
75b7c851b2SAlex Bennée		$(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\
760bdb12c7SPeter Maydell		"BUILD","$*")
77dc338fdbSAlex Bennée
78dc338fdbSAlex Bennée# Special rule for debootstraped binfmt linux-user images
79dc338fdbSAlex Bennéedocker-binfmt-image-debian-%: $(DOCKER_FILES_DIR)/debian-bootstrap.docker
80dc338fdbSAlex Bennée	$(if $(EXECUTABLE),,\
81dc338fdbSAlex Bennée		$(error EXECUTABLE not set, debootstrap of debian-$* would fail))
82dc338fdbSAlex Bennée	$(if $(DEB_ARCH),,\
83dc338fdbSAlex Bennée		$(error DEB_ARCH not set, debootstrap of debian-$* would fail))
84dc338fdbSAlex Bennée	$(if $(DEB_TYPE),,\
85dc338fdbSAlex Bennée		$(error DEB_TYPE not set, debootstrap of debian-$* would fail))
8627963460SAlex Bennée	$(if $(wildcard $(EXECUTABLE)),						\
87dc338fdbSAlex Bennée		$(call quiet-command,						\
88dc338fdbSAlex Bennée			DEB_ARCH=$(DEB_ARCH)					\
89dc338fdbSAlex Bennée			DEB_TYPE=$(DEB_TYPE) 					\
904d26c7feSAlex Bennée			$(if $(DEB_URL),DEB_URL=$(DEB_URL),)			\
91182ec060SAlex Bennée			$(DOCKER_SCRIPT) build -t qemu/debian-$* -f $< 		\
92dc338fdbSAlex Bennée			$(if $V,,--quiet) $(if $(NOCACHE),--no-cache) 		\
93dc338fdbSAlex Bennée			$(if $(NOUSER),,--add-current-user) 			\
94dc338fdbSAlex Bennée			$(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))	\
95dc338fdbSAlex Bennée			$(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)), \
9619c9a18fSAlex Bennée			"BUILD","binfmt debian-$* (debootstrapped)"),		\
9719c9a18fSAlex Bennée		$(call quiet-command,						\
98767b6bd2SAlex Bennée			$(DOCKER_SCRIPT) check --quiet qemu/debian-$* $< || 	\
99d19f5fc0SAlex Bennée			{ echo "You will need to build $(EXECUTABLE)"; exit 1;},\
10019c9a18fSAlex Bennée			"CHECK", "debian-$* exists"))
101dc338fdbSAlex Bennée
102ddd5ed83SAlex Bennée# These are test targets
103ddd5ed83SAlex BennéeUSER_TCG_TARGETS=$(patsubst %-linux-user,qemu-%,$(filter %-linux-user,$(TARGET_DIRS)))
104ddd5ed83SAlex BennéeEXEC_COPY_TESTS=$(patsubst %,docker-exec-copy-test-%, $(USER_TCG_TARGETS))
105ddd5ed83SAlex Bennée
106ddd5ed83SAlex Bennée$(EXEC_COPY_TESTS): docker-exec-copy-test-%: $(DOCKER_FILES_DIR)/empty.docker
107ddd5ed83SAlex Bennée	$(call quiet-command,							\
108ddd5ed83SAlex Bennée		$(DOCKER_SCRIPT) build -t qemu/exec-copy-test-$* -f $< 		\
109ddd5ed83SAlex Bennée			$(if $V,,--quiet) --no-cache 				\
110ddd5ed83SAlex Bennée			--include-executable=$*					\
111ddd5ed83SAlex Bennée			--skip-binfmt,						\
112ddd5ed83SAlex Bennée			"TEST","copy $* to container")
113ddd5ed83SAlex Bennée	$(call quiet-command,							\
114ddd5ed83SAlex Bennée		$(DOCKER_SCRIPT) run qemu/exec-copy-test-$* 			\
115ddd5ed83SAlex Bennée			/$* -version > tests/docker-exec-copy-test-$*.out,	\
116ddd5ed83SAlex Bennée			"TEST","check $* works in container")
117ddd5ed83SAlex Bennée
118ddd5ed83SAlex Bennéedocker-exec-copy-test: $(EXEC_COPY_TESTS)
119ddd5ed83SAlex Bennée
120cff54773SAlex Bennéeendif
121324027c2SFam Zheng
1229d5e546aSPhilippe Mathieu-Daudé# Enforce dependencies for composite images
12306746324SAlex Bennéeifeq ($(HOST_ARCH),x86_64)
124698a71edSAlex Bennéedocker-image-debian-amd64: docker-image-debian10
125ec22b726SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-amd64-cross
126ec22b726SAlex Bennéeelse
127ec22b726SAlex Bennéedocker-image-debian-amd64-cross: docker-image-debian10
128ec22b726SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-amd64
129ec22b726SAlex Bennéeendif
130409c1c9cSAlex Bennée
131e5389e44SAlex Bennée# For non-x86 hosts not all cross-compilers have been packaged
13206746324SAlex Bennéeifneq ($(HOST_ARCH),x86_64)
133e5389e44SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-mips-cross debian-mipsel-cross debian-mips64el-cross
134e5389e44SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-ppc64el-cross
135e5389e44SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-s390x-cross
136d79f5c8bSDaniel P. BerrangéDOCKER_PARTIAL_IMAGES += fedora
137e5389e44SAlex Bennéeendif
138e5389e44SAlex Bennée
139e3386c27SAlex Bennéedocker-image-debian-alpha-cross: docker-image-debian10
14018b6be43SAlex Bennéedocker-image-debian-arm64-cross: docker-image-debian10
141698a71edSAlex Bennéedocker-image-debian-armel-cross: docker-image-debian10
142698a71edSAlex Bennéedocker-image-debian-armhf-cross: docker-image-debian10
143c268700bSAlex Bennéedocker-image-debian-hppa-cross: docker-image-debian10
14420f8b1a2SAlex Bennéedocker-image-debian-m68k-cross: docker-image-debian10
145698a71edSAlex Bennéedocker-image-debian-mips-cross: docker-image-debian10
1464575a701SAlex Bennéedocker-image-debian-mips64-cross: docker-image-debian10
147698a71edSAlex Bennéedocker-image-debian-mips64el-cross: docker-image-debian10
148698a71edSAlex Bennéedocker-image-debian-mipsel-cross: docker-image-debian10
149698a71edSAlex Bennéedocker-image-debian-ppc64el-cross: docker-image-debian10
150698a71edSAlex Bennéedocker-image-debian-s390x-cross: docker-image-debian10
151923984c5SAlex Bennéedocker-image-debian-sh4-cross: docker-image-debian10
15278d1d696SAlex Bennéedocker-image-debian-sparc64-cross: docker-image-debian10
15318b6be43SAlex Bennée
15417888749SAlex Bennée# The native build should never use the registry
15517888749SAlex Bennéedocker-image-debian-native: DOCKER_REGISTRY=
15617888749SAlex Bennée
157d47e3751SAlex Bennée# base images should not add a local user
158d47e3751SAlex Bennéedocker-image-debian10: NOUSER=1
159d47e3751SAlex Bennéedocker-image-debian11: NOUSER=1
16017888749SAlex Bennée
161*5dbefb87SAlex Bennée# alpine has no adduser
162*5dbefb87SAlex Bennéedocker-image-alpine: NOUSER=1
163*5dbefb87SAlex Bennée
164afbdf0a4SAlessandro Di Federico#
165afbdf0a4SAlessandro Di Federico# The build rule for hexagon-cross is special in so far for most of
166afbdf0a4SAlessandro Di Federico# the time we don't want to build it. While dockers caching does avoid
167afbdf0a4SAlessandro Di Federico# this most of the time sometimes we want to force the issue.
168afbdf0a4SAlessandro Di Federico#
169afbdf0a4SAlessandro Di Federicodocker-image-debian-hexagon-cross: $(DOCKER_FILES_DIR)/debian-hexagon-cross.docker
170afbdf0a4SAlessandro Di Federico	$(if $(NOCACHE), 								\
171afbdf0a4SAlessandro Di Federico		$(call quiet-command,							\
172afbdf0a4SAlessandro Di Federico			$(DOCKER_SCRIPT) build -t qemu/debian-hexagon-cross -f $< 	\
173afbdf0a4SAlessandro Di Federico			$(if $V,,--quiet) --no-cache 					\
174afbdf0a4SAlessandro Di Federico			--registry $(DOCKER_REGISTRY) --extra-files			\
175afbdf0a4SAlessandro Di Federico			$(DOCKER_FILES_DIR)/debian-hexagon-cross.docker.d/build-toolchain.sh, \
176afbdf0a4SAlessandro Di Federico			"BUILD", "debian-hexagon-cross"),				\
177afbdf0a4SAlessandro Di Federico		$(call quiet-command,							\
178afbdf0a4SAlessandro Di Federico			$(DOCKER_SCRIPT) fetch $(if $V,,--quiet)			\
179afbdf0a4SAlessandro Di Federico				qemu/debian-hexagon-cross $(DOCKER_REGISTRY),		\
180afbdf0a4SAlessandro Di Federico			"FETCH", "debian-hexagon-cross")				\
181afbdf0a4SAlessandro Di Federico		$(call quiet-command,							\
182afbdf0a4SAlessandro Di Federico			$(DOCKER_SCRIPT) update $(if $V,,--quiet) 			\
183afbdf0a4SAlessandro Di Federico				qemu/debian-hexagon-cross --add-current-user,		\
184afbdf0a4SAlessandro Di Federico			"PREPARE", "debian-hexagon-cross"))
185afbdf0a4SAlessandro Di Federico
1862eb4461aSRichard Hendersondebian-toolchain-run = \
1872eb4461aSRichard Henderson	$(if $(NOCACHE), 						\
1882eb4461aSRichard Henderson		$(call quiet-command,					\
1892eb4461aSRichard Henderson			$(DOCKER_SCRIPT) build -t qemu/$1 -f $< 	\
1902eb4461aSRichard Henderson			$(if $V,,--quiet) --no-cache 			\
1912eb4461aSRichard Henderson			--registry $(DOCKER_REGISTRY) --extra-files	\
1922eb4461aSRichard Henderson			$(DOCKER_FILES_DIR)/$1.d/build-toolchain.sh,	\
1932eb4461aSRichard Henderson			"BUILD", $1),				        \
1942eb4461aSRichard Henderson		$(call quiet-command,					\
1952eb4461aSRichard Henderson			$(DOCKER_SCRIPT) fetch $(if $V,,--quiet)	\
1962eb4461aSRichard Henderson				qemu/$1 $(DOCKER_REGISTRY),		\
1972eb4461aSRichard Henderson			"FETCH", $1)					\
1982eb4461aSRichard Henderson		$(call quiet-command,					\
1992eb4461aSRichard Henderson			$(DOCKER_SCRIPT) update $(if $V,,--quiet) 	\
2002eb4461aSRichard Henderson				qemu/$1 				\
2012eb4461aSRichard Henderson				$(if $(NOUSER),,--add-current-user) 	\
2022eb4461aSRichard Henderson			"PREPARE", $1))
2032eb4461aSRichard Hendersondebian-toolchain = $(call debian-toolchain-run,$(patsubst docker-image-%,%,$1))
2042eb4461aSRichard Henderson
205b58a4e68SRichard Hendersondocker-image-debian-microblaze-cross: $(DOCKER_FILES_DIR)/debian-toolchain.docker \
206b58a4e68SRichard Henderson    $(DOCKER_FILES_DIR)/debian-microblaze-cross.d/build-toolchain.sh
207b58a4e68SRichard Henderson	$(call debian-toolchain, $@)
208b58a4e68SRichard Henderson
2092eb4461aSRichard Hendersondocker-image-debian-nios2-cross: $(DOCKER_FILES_DIR)/debian-toolchain.docker \
2102eb4461aSRichard Henderson    $(DOCKER_FILES_DIR)/debian-nios2-cross.d/build-toolchain.sh
2112eb4461aSRichard Henderson	$(call debian-toolchain, $@)
2122eb4461aSRichard Henderson
21336dc5fedSPhilippe Mathieu-Daudé# Specialist build images, sometimes very limited tools
214cf63177eSThomas Huthdocker-image-debian-tricore-cross: docker-image-debian10
21527ebeda0SAlex Bennéedocker-image-debian-all-test-cross: docker-image-debian10
216c729a99dSAlex Bennéedocker-image-debian-arm64-test-cross: docker-image-debian11
217b58a4e68SRichard Hendersondocker-image-debian-microblaze-cross: docker-image-debian10
2182eb4461aSRichard Hendersondocker-image-debian-nios2-cross: docker-image-debian10
219cf9b6d21SMatheus Ferstdocker-image-debian-powerpc-test-cross: docker-image-debian11
22036dc5fedSPhilippe Mathieu-Daudé
22177b08f73SAlex Bennée# These images may be good enough for building tests but not for test builds
222ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-alpha-cross
223c729a99dSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-arm64-test-cross
224cf9b6d21SMatheus FerstDOCKER_PARTIAL_IMAGES += debian-powerpc-test-cross
225ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-hppa-cross
226ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-m68k-cross debian-mips64-cross
227b58a4e68SRichard HendersonDOCKER_PARTIAL_IMAGES += debian-microblaze-cross
2282eb4461aSRichard HendersonDOCKER_PARTIAL_IMAGES += debian-nios2-cross
229ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-sh4-cross debian-sparc64-cross
230ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-tricore-cross
231ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-xtensa-cross
2326a2b0fd1SRichard HendersonDOCKER_PARTIAL_IMAGES += fedora-cris-cross
23377b08f73SAlex Bennée
23419c9a18fSAlex Bennée# Rules for building linux-user powered images
23519c9a18fSAlex Bennée#
23619c9a18fSAlex Bennée# These are slower than using native cross compiler setups but can
23719c9a18fSAlex Bennée# work around issues with poorly working multi-arch systems and broken
23819c9a18fSAlex Bennée# packages.
23919c9a18fSAlex Bennée
240324027c2SFam Zheng# Expand all the pre-requistes for each docker image and test combination
241a7181a28SAlex Bennée$(foreach i,$(filter-out $(DOCKER_PARTIAL_IMAGES) $(DOCKER_VIRTUAL_IMAGES),$(DOCKER_IMAGES)), \
242d79f5c8bSDaniel P. Berrangé	$(foreach t,$(DOCKER_TESTS), \
243324027c2SFam Zheng		$(eval .PHONY: docker-$t@$i) \
244324027c2SFam Zheng		$(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \
245324027c2SFam Zheng	) \
246324027c2SFam Zheng	$(foreach t,$(DOCKER_TESTS), \
247ff1a3902SAlex Bennée		$(eval docker-all-tests: docker-$t@$i) \
248ff1a3902SAlex Bennée		$(eval docker-$t: docker-$t@$i) \
249324027c2SFam Zheng	) \
250324027c2SFam Zheng)
251324027c2SFam Zheng
252324027c2SFam Zhengdocker:
25305af039dSMarc-André Lureau	@echo 'Build QEMU and run tests inside Docker or Podman containers'
254324027c2SFam Zheng	@echo
255324027c2SFam Zheng	@echo 'Available targets:'
256324027c2SFam Zheng	@echo
257324027c2SFam Zheng	@echo '    docker:              Print this help.'
258ff1a3902SAlex Bennée	@echo '    docker-all-tests:    Run all image/test combinations.'
25987db9018SWainer dos Santos Moschetta	@echo '    docker-TEST:         Run "TEST" on all image combinations.'
260324027c2SFam Zheng	@echo '    docker-clean:        Kill and remove residual docker testing containers.'
261324027c2SFam Zheng	@echo '    docker-TEST@IMAGE:   Run "TEST" in container "IMAGE".'
262324027c2SFam Zheng	@echo '                         Note: "TEST" is one of the listed test name,'
263324027c2SFam Zheng	@echo '                         or a script name under $$QEMU_SRC/tests/docker/;'
26487db9018SWainer dos Santos Moschetta	@echo '                         "IMAGE" is one of the listed container name.'
265324027c2SFam Zheng	@echo '    docker-image:        Build all images.'
266324027c2SFam Zheng	@echo '    docker-image-IMAGE:  Build image "IMAGE".'
26787db9018SWainer dos Santos Moschetta	@echo '    docker-run:          For manually running a "TEST" with "IMAGE".'
268324027c2SFam Zheng	@echo
269324027c2SFam Zheng	@echo 'Available container images:'
270324027c2SFam Zheng	@echo '    $(DOCKER_IMAGES)'
27119c9a18fSAlex Bennéeifneq ($(DOCKER_USER_IMAGES),)
27219c9a18fSAlex Bennée	@echo
27319c9a18fSAlex Bennée	@echo 'Available linux-user images (docker-binfmt-image-debian-%):'
27419c9a18fSAlex Bennée	@echo '    $(DOCKER_USER_IMAGES)'
27519c9a18fSAlex Bennéeendif
276324027c2SFam Zheng	@echo
277324027c2SFam Zheng	@echo 'Available tests:'
278324027c2SFam Zheng	@echo '    $(DOCKER_TESTS)'
279324027c2SFam Zheng	@echo
280324027c2SFam Zheng	@echo 'Special variables:'
281324027c2SFam Zheng	@echo '    TARGET_LIST=a,b,c    Override target list in builds.'
28235e0f959SFam Zheng	@echo '    EXTRA_CONFIGURE_OPTS="..."'
28335e0f959SFam Zheng	@echo '                         Extra configure options.'
284be20302aSAlex Bennée	@echo '    IMAGES="a b c ..":   Restrict available images to subset.'
285be20302aSAlex Bennée	@echo '    TESTS="x y z .."     Restrict available tests to subset.'
286324027c2SFam Zheng	@echo '    J=[0..9]*            Overrides the -jN parameter for make commands'
287324027c2SFam Zheng	@echo '                         (default is 1)'
288324027c2SFam Zheng	@echo '    DEBUG=1              Stop and drop to shell in the created container'
289324027c2SFam Zheng	@echo '                         before running the command.'
2908a2390a4SDaniel P. Berrange	@echo '    NETWORK=1            Enable virtual network interface with default backend.'
2916423795eSPhilippe Mathieu-Daudé	@echo '    NETWORK=$$BACKEND     Enable virtual network interface with $$BACKEND.'
292dc23bbc3SPhilippe Mathieu-Daudé	@echo '    NOUSER=1             Define to disable adding current user to containers passwd.'
293324027c2SFam Zheng	@echo '    NOCACHE=1            Ignore cache when build images.'
294b7c851b2SAlex Bennée	@echo '    EXECUTABLE=<path>    Include executable in image.'
2954c84f662SPhilippe Mathieu-Daudé	@echo '    EXTRA_FILES="<path> [... <path>]"'
2964c84f662SPhilippe Mathieu-Daudé	@echo '                         Include extra files in image.'
29705af039dSMarc-André Lureau	@echo '    ENGINE=auto/docker/podman'
29805af039dSMarc-André Lureau	@echo '                         Specify which container engine to run.'
299e6f1306bSAlex Bennée	@echo '    REGISTRY=url         Cache builds from registry (default:$(DOCKER_REGISTRY))'
300324027c2SFam Zheng
3016147c249SAlex Bennéedocker-help: docker
3026147c249SAlex Bennée
303e86c9a64SAlex Bennée# This rule if for directly running against an arbitrary docker target.
304e86c9a64SAlex Bennée# It is called by the expanded docker targets (e.g. make
305e86c9a64SAlex Bennée# docker-test-foo@bar) which will do additional verification.
306e86c9a64SAlex Bennée#
307e86c9a64SAlex Bennée# For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64
308e86c9a64SAlex Bennée#
309e86c9a64SAlex Bennéedocker-run: docker-qemu-src
310324027c2SFam Zheng	@mkdir -p "$(DOCKER_CCACHE_DIR)"
311e86c9a64SAlex Bennée	@if test -z "$(IMAGE)" || test -z "$(TEST)"; \
312e86c9a64SAlex Bennée		then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \
313324027c2SFam Zheng	fi
314e86c9a64SAlex Bennée	$(if $(EXECUTABLE),						\
315324027c2SFam Zheng		$(call quiet-command,					\
316e27cae26SAlex Bennée			$(DOCKER_SCRIPT) update 			\
3178d628d07SAlex Bennée			$(IMAGE) --executable $(EXECUTABLE),		\
318e86c9a64SAlex Bennée			"  COPYING $(EXECUTABLE) to $(IMAGE)"))
319e86c9a64SAlex Bennée	$(call quiet-command,						\
320e27cae26SAlex Bennée		$(DOCKER_SCRIPT) run 					\
3212461d80eSMarc-André Lureau			$(if $(NOUSER),,--run-as-current-user) 		\
32244707491SFam Zheng			--security-opt seccomp=unconfined		\
3234b2c6bc5SFam Zheng			$(if $(DEBUG),-ti,)				\
3248a2390a4SDaniel P. Berrange			$(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \
3255609c512SAlex Bennée			-e TARGET_LIST=$(subst $(SPACE),$(COMMA),$(TARGET_LIST))	\
326e86c9a64SAlex Bennée			-e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
327e86c9a64SAlex Bennée			-e V=$V -e J=$J -e DEBUG=$(DEBUG)		\
328e86c9a64SAlex Bennée			-e SHOW_ENV=$(SHOW_ENV) 			\
32936ac78e6SFam Zheng			$(if $(NOUSER),,				\
330324027c2SFam Zheng				-e CCACHE_DIR=/var/tmp/ccache 		\
331324027c2SFam Zheng				-v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \
33236ac78e6SFam Zheng			)						\
33336ac78e6SFam Zheng			-v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
334e86c9a64SAlex Bennée			$(IMAGE) 					\
335c8158513SFam Zheng			/var/tmp/qemu/run 				\
336e86c9a64SAlex Bennée			$(TEST), "  RUN $(TEST) in ${IMAGE}")
33708c3f6d5SPeter Xu	$(call quiet-command, rm -r $(DOCKER_SRC_COPY), \
33808c3f6d5SPeter Xu		"  CLEANUP $(DOCKER_SRC_COPY)")
339e86c9a64SAlex Bennée
340e86c9a64SAlex Bennée# Run targets:
341e86c9a64SAlex Bennée#
342e86c9a64SAlex Bennée# Of the form docker-TEST-FOO@IMAGE-BAR which will then be expanded into a call to "make docker-run"
343e86c9a64SAlex Bennéedocker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
344e86c9a64SAlex Bennéedocker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
345e86c9a64SAlex Bennéedocker-run-%:
346767b6bd2SAlex Bennée	@$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu/$(IMAGE)
347324027c2SFam Zheng
348324027c2SFam Zhengdocker-clean:
349e27cae26SAlex Bennée	$(call quiet-command, $(DOCKER_SCRIPT) clean)
350