xref: /openbmc/qemu/tests/docker/Makefile.include (revision ccf20b3b)
1324027c2SFam Zheng# Makefile for Docker tests
2324027c2SFam Zheng
3324027c2SFam Zheng.PHONY: docker docker-test docker-clean docker-image docker-qemu-src
4324027c2SFam Zheng
5324027c2SFam ZhengDOCKER_SUFFIX := .docker
6324027c2SFam ZhengDOCKER_FILES_DIR := $(SRC_PATH)/tests/docker/dockerfiles
7bcaf4577SPhilippe Mathieu-DaudéDOCKER_DEPRECATED_IMAGES := debian
8272e551bSPhilippe Mathieu-Daudé# we don't run tests on intermediate images (used as base by another image)
944d5a8bfSAlex BennéeDOCKER_PARTIAL_IMAGES := debian debian8 debian9 debian10 debian-sid
10*ccf20b3bSJohn SnowDOCKER_PARTIAL_IMAGES += debian9-mxe debian-ports debian-bootstrap
11bcaf4577SPhilippe Mathieu-DaudéDOCKER_IMAGES := $(filter-out $(DOCKER_DEPRECATED_IMAGES),$(sort $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker)))))
12324027c2SFam ZhengDOCKER_TARGETS := $(patsubst %,docker-image-%,$(DOCKER_IMAGES))
13324027c2SFam Zheng# Use a global constant ccache directory to speed up repetitive builds
14324027c2SFam ZhengDOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
15324027c2SFam Zheng
16324027c2SFam ZhengDOCKER_TESTS := $(notdir $(shell \
17324027c2SFam Zheng	find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f))
18324027c2SFam Zheng
19324027c2SFam ZhengDOCKER_TOOLS := travis
20324027c2SFam Zheng
2105af039dSMarc-André LureauENGINE := auto
2205af039dSMarc-André Lureau
2305af039dSMarc-André LureauDOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py --engine $(ENGINE)
24e27cae26SAlex Bennée
25324027c2SFam ZhengTESTS ?= %
26324027c2SFam ZhengIMAGES ?= %
27324027c2SFam Zheng
28324027c2SFam ZhengCUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$)
29bc739b8eSPaolo BonziniDOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME)
30324027c2SFam Zheng
31b28ef6b9SPhilippe Mathieu-Daudé.DELETE_ON_ERROR: $(DOCKER_SRC_COPY)
32324027c2SFam Zheng$(DOCKER_SRC_COPY):
33324027c2SFam Zheng	@mkdir $@
3473fb4f1dSFam Zheng	$(if $(SRC_ARCHIVE), \
3573fb4f1dSFam Zheng		$(call quiet-command, cp "$(SRC_ARCHIVE)" $@/qemu.tar, \
3673fb4f1dSFam Zheng			"CP", "$@/qemu.tar"), \
37bc739b8eSPaolo Bonzini		$(call quiet-command, cd $(SRC_PATH) && scripts/archive-source.sh $@/qemu.tar, \
3873fb4f1dSFam Zheng			"GEN", "$@/qemu.tar"))
39324027c2SFam Zheng	$(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \
400bdb12c7SPeter Maydell		"COPY","RUNNER")
41324027c2SFam Zheng
42324027c2SFam Zhengdocker-qemu-src: $(DOCKER_SRC_COPY)
43324027c2SFam Zheng
44324027c2SFam Zhengdocker-image: ${DOCKER_TARGETS}
45324027c2SFam Zheng
46cff54773SAlex Bennée# General rule for building docker images. If we are a sub-make
47cff54773SAlex Bennée# invoked with SKIP_DOCKER_BUILD we still check the image is up to date
48cff54773SAlex Bennée# though
49cff54773SAlex Bennéeifdef SKIP_DOCKER_BUILD
50cff54773SAlex Bennéedocker-image-%: $(DOCKER_FILES_DIR)/%.docker
51cff54773SAlex Bennée	$(call quiet-command, \
52cff54773SAlex Bennée		$(DOCKER_SCRIPT) check --quiet qemu:$* $<, \
53cff54773SAlex Bennée		"CHECK", "$*")
54cff54773SAlex Bennéeelse
55324027c2SFam Zhengdocker-image-%: $(DOCKER_FILES_DIR)/%.docker
56324027c2SFam Zheng	$(call quiet-command,\
57e27cae26SAlex Bennée		$(DOCKER_SCRIPT) build qemu:$* $< \
58b7c851b2SAlex Bennée		$(if $V,,--quiet) $(if $(NOCACHE),--no-cache) \
59414a8ce5SAlex Bennée		$(if $(NOUSER),,--add-current-user) \
604c84f662SPhilippe Mathieu-Daudé		$(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\
61b7c851b2SAlex Bennée		$(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\
620bdb12c7SPeter Maydell		"BUILD","$*")
63dc338fdbSAlex Bennée
64dc338fdbSAlex Bennée# Special rule for debootstraped binfmt linux-user images
65dc338fdbSAlex Bennéedocker-binfmt-image-debian-%: $(DOCKER_FILES_DIR)/debian-bootstrap.docker
66dc338fdbSAlex Bennée	$(if $(EXECUTABLE),,\
67dc338fdbSAlex Bennée		$(error EXECUTABLE not set, debootstrap of debian-$* would fail))
68dc338fdbSAlex Bennée	$(if $(DEB_ARCH),,\
69dc338fdbSAlex Bennée		$(error DEB_ARCH not set, debootstrap of debian-$* would fail))
70dc338fdbSAlex Bennée	$(if $(DEB_TYPE),,\
71dc338fdbSAlex Bennée		$(error DEB_TYPE not set, debootstrap of debian-$* would fail))
7227963460SAlex Bennée	$(if $(wildcard $(EXECUTABLE)),						\
73dc338fdbSAlex Bennée		$(call quiet-command,						\
74dc338fdbSAlex Bennée			DEB_ARCH=$(DEB_ARCH)					\
75dc338fdbSAlex Bennée			DEB_TYPE=$(DEB_TYPE) 					\
764d26c7feSAlex Bennée			$(if $(DEB_URL),DEB_URL=$(DEB_URL),)			\
77dc338fdbSAlex Bennée			$(DOCKER_SCRIPT) build qemu:debian-$* $< 		\
78dc338fdbSAlex Bennée			$(if $V,,--quiet) $(if $(NOCACHE),--no-cache) 		\
79dc338fdbSAlex Bennée			$(if $(NOUSER),,--add-current-user) 			\
80dc338fdbSAlex Bennée			$(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))	\
81dc338fdbSAlex Bennée			$(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)), \
8219c9a18fSAlex Bennée			"BUILD","binfmt debian-$* (debootstrapped)"),		\
8319c9a18fSAlex Bennée		$(call quiet-command,						\
84d19f5fc0SAlex Bennée			$(DOCKER_SCRIPT) check --quiet qemu:debian-$* $< || 	\
85d19f5fc0SAlex Bennée			{ echo "You will need to build $(EXECUTABLE)"; exit 1;},\
8619c9a18fSAlex Bennée			"CHECK", "debian-$* exists"))
87dc338fdbSAlex Bennée
88cff54773SAlex Bennéeendif
89324027c2SFam Zheng
909d5e546aSPhilippe Mathieu-Daudé# Enforce dependencies for composite images
9167bd36beSAlex Bennéedocker-image-debian9-mxe: docker-image-debian9
92ec22b726SAlex Bennéeifeq ($(ARCH),x86_64)
9315288046SPhilippe Mathieu-Daudédocker-image-debian-amd64: docker-image-debian9
94ec22b726SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-amd64-cross
95ec22b726SAlex Bennéeelse
96ec22b726SAlex Bennéedocker-image-debian-amd64-cross: docker-image-debian10
97ec22b726SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-amd64
98ec22b726SAlex Bennéeendif
9931e205d1SPhilippe Mathieu-Daudédocker-image-debian-armel-cross: docker-image-debian9
10024044d48SPhilippe Mathieu-Daudédocker-image-debian-armhf-cross: docker-image-debian9
1014319db7bSPhilippe Mathieu-Daudédocker-image-debian-mips-cross: docker-image-debian9
1026bf77518SAlex Bennéedocker-image-debian-mipsel-cross: docker-image-debian9
103fd7b284dSPhilippe Mathieu-Daudédocker-image-debian-mips64el-cross: docker-image-debian9
1042b1c10bdSPhilippe Mathieu-Daudédocker-image-debian-ppc64el-cross: docker-image-debian9
1057d2bcf23SPhilippe Mathieu-Daudédocker-image-debian-s390x-cross: docker-image-debian9
10667bd36beSAlex Bennéedocker-image-debian-win32-cross: docker-image-debian9-mxe
10767bd36beSAlex Bennéedocker-image-debian-win64-cross: docker-image-debian9-mxe
108409c1c9cSAlex Bennée
109e5389e44SAlex Bennée# For non-x86 hosts not all cross-compilers have been packaged
110e5389e44SAlex Bennéeifneq ($(ARCH),x86_64)
111e5389e44SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-mips-cross debian-mipsel-cross debian-mips64el-cross
112e5389e44SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-ppc64el-cross
113e5389e44SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-s390x-cross
114e5389e44SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-win32-cross debian-win64-cross
115e5389e44SAlex BennéeDOCKER_PARTIAL_IMAGES += fedora travis
116e5389e44SAlex Bennéeendif
117e5389e44SAlex Bennée
118e3386c27SAlex Bennéedocker-image-debian-alpha-cross: docker-image-debian10
11918b6be43SAlex Bennéedocker-image-debian-arm64-cross: docker-image-debian10
120c268700bSAlex Bennéedocker-image-debian-hppa-cross: docker-image-debian10
12120f8b1a2SAlex Bennéedocker-image-debian-m68k-cross: docker-image-debian10
1224575a701SAlex Bennéedocker-image-debian-mips64-cross: docker-image-debian10
123ce494209SAlex Bennéedocker-image-debian-powerpc-cross: docker-image-debian10
1248a4daee5SAlex Bennéedocker-image-debian-ppc64-cross: docker-image-debian10
125c6e8f512SAlex Bennéedocker-image-debian-riscv64-cross: docker-image-debian10
126923984c5SAlex Bennéedocker-image-debian-sh4-cross: docker-image-debian10
12778d1d696SAlex Bennéedocker-image-debian-sparc64-cross: docker-image-debian10
12818b6be43SAlex Bennée
1291fddbf7cSAlex Bennéedocker-image-travis: NOUSER=1
13024e0131fSAlex Bennée
13136dc5fedSPhilippe Mathieu-Daudé# Specialist build images, sometimes very limited tools
13236dc5fedSPhilippe Mathieu-Daudédocker-image-tricore-cross: docker-image-debian9
13336dc5fedSPhilippe Mathieu-Daudé
13477b08f73SAlex Bennée# These images may be good enough for building tests but not for test builds
135ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-alpha-cross
136ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-hppa-cross
137ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-m68k-cross debian-mips64-cross
138ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-powerpc-cross debian-ppc64-cross
139ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-riscv64-cross
140ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-sh4-cross debian-sparc64-cross
141ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-tricore-cross
142ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += debian-xtensa-cross
143ac276a4bSAlex BennéeDOCKER_PARTIAL_IMAGES += fedora-i386-cross fedora-cris-cross
14477b08f73SAlex Bennée
14519c9a18fSAlex Bennée# Rules for building linux-user powered images
14619c9a18fSAlex Bennée#
14719c9a18fSAlex Bennée# These are slower than using native cross compiler setups but can
14819c9a18fSAlex Bennée# work around issues with poorly working multi-arch systems and broken
14919c9a18fSAlex Bennée# packages.
15019c9a18fSAlex Bennée
15119c9a18fSAlex Bennée# Jessie is the last supported release for powerpc, but multi-arch is
15219c9a18fSAlex Bennée# broken so we need a qemu-linux-user for this target
15319c9a18fSAlex Bennéedocker-binfmt-image-debian-powerpc-user: DEB_ARCH = powerpc
15419c9a18fSAlex Bennéedocker-binfmt-image-debian-powerpc-user: DEB_TYPE = jessie
1554d26c7feSAlex Bennéedocker-binfmt-image-debian-powerpc-user: DEB_URL = http://snapshot.debian.org/archive/debian/20180615T211437Z
15619c9a18fSAlex Bennéedocker-binfmt-image-debian-powerpc-user: EXECUTABLE = ${BUILD_DIR}/ppc-linux-user/qemu-ppc
15719c9a18fSAlex Bennéedocker-image-debian-powerpc-user-cross: docker-binfmt-image-debian-powerpc-user
15819c9a18fSAlex BennéeDOCKER_USER_IMAGES += debian-powerpc-user
15919c9a18fSAlex Bennée
160324027c2SFam Zheng# Expand all the pre-requistes for each docker image and test combination
16177b08f73SAlex Bennée$(foreach i,$(filter-out $(DOCKER_PARTIAL_IMAGES),$(DOCKER_IMAGES) $(DOCKER_DEPRECATED_IMAGES)), \
162324027c2SFam Zheng	$(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \
163324027c2SFam Zheng		$(eval .PHONY: docker-$t@$i) \
164324027c2SFam Zheng		$(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \
165324027c2SFam Zheng	) \
166324027c2SFam Zheng	$(foreach t,$(DOCKER_TESTS), \
167ff1a3902SAlex Bennée		$(eval docker-all-tests: docker-$t@$i) \
168ff1a3902SAlex Bennée		$(eval docker-$t: docker-$t@$i) \
169324027c2SFam Zheng	) \
170324027c2SFam Zheng)
171324027c2SFam Zheng
172324027c2SFam Zhengdocker:
17305af039dSMarc-André Lureau	@echo 'Build QEMU and run tests inside Docker or Podman containers'
174324027c2SFam Zheng	@echo
175324027c2SFam Zheng	@echo 'Available targets:'
176324027c2SFam Zheng	@echo
177324027c2SFam Zheng	@echo '    docker:              Print this help.'
178ff1a3902SAlex Bennée	@echo '    docker-all-tests:    Run all image/test combinations.'
17987db9018SWainer dos Santos Moschetta	@echo '    docker-TEST:         Run "TEST" on all image combinations.'
180324027c2SFam Zheng	@echo '    docker-clean:        Kill and remove residual docker testing containers.'
181324027c2SFam Zheng	@echo '    docker-TEST@IMAGE:   Run "TEST" in container "IMAGE".'
182324027c2SFam Zheng	@echo '                         Note: "TEST" is one of the listed test name,'
183324027c2SFam Zheng	@echo '                         or a script name under $$QEMU_SRC/tests/docker/;'
18487db9018SWainer dos Santos Moschetta	@echo '                         "IMAGE" is one of the listed container name.'
185324027c2SFam Zheng	@echo '    docker-image:        Build all images.'
186324027c2SFam Zheng	@echo '    docker-image-IMAGE:  Build image "IMAGE".'
18787db9018SWainer dos Santos Moschetta	@echo '    docker-run:          For manually running a "TEST" with "IMAGE".'
188324027c2SFam Zheng	@echo
189324027c2SFam Zheng	@echo 'Available container images:'
190324027c2SFam Zheng	@echo '    $(DOCKER_IMAGES)'
19119c9a18fSAlex Bennéeifneq ($(DOCKER_USER_IMAGES),)
19219c9a18fSAlex Bennée	@echo
19319c9a18fSAlex Bennée	@echo 'Available linux-user images (docker-binfmt-image-debian-%):'
19419c9a18fSAlex Bennée	@echo '    $(DOCKER_USER_IMAGES)'
19519c9a18fSAlex Bennéeendif
196324027c2SFam Zheng	@echo
197324027c2SFam Zheng	@echo 'Available tests:'
198324027c2SFam Zheng	@echo '    $(DOCKER_TESTS)'
199324027c2SFam Zheng	@echo
200324027c2SFam Zheng	@echo 'Available tools:'
201324027c2SFam Zheng	@echo '    $(DOCKER_TOOLS)'
202324027c2SFam Zheng	@echo
203324027c2SFam Zheng	@echo 'Special variables:'
204324027c2SFam Zheng	@echo '    TARGET_LIST=a,b,c    Override target list in builds.'
20535e0f959SFam Zheng	@echo '    EXTRA_CONFIGURE_OPTS="..."'
20635e0f959SFam Zheng	@echo '                         Extra configure options.'
207324027c2SFam Zheng	@echo '    IMAGES="a b c ..":   Filters which images to build or run.'
208324027c2SFam Zheng	@echo '    TESTS="x y z .."     Filters which tests to run (for docker-test).'
209324027c2SFam Zheng	@echo '    J=[0..9]*            Overrides the -jN parameter for make commands'
210324027c2SFam Zheng	@echo '                         (default is 1)'
211324027c2SFam Zheng	@echo '    DEBUG=1              Stop and drop to shell in the created container'
212324027c2SFam Zheng	@echo '                         before running the command.'
2138a2390a4SDaniel P. Berrange	@echo '    NETWORK=1            Enable virtual network interface with default backend.'
2146423795eSPhilippe Mathieu-Daudé	@echo '    NETWORK=$$BACKEND     Enable virtual network interface with $$BACKEND.'
215414a8ce5SAlex Bennée	@echo '    NOUSER               Define to disable adding current user to containers passwd.'
216324027c2SFam Zheng	@echo '    NOCACHE=1            Ignore cache when build images.'
217b7c851b2SAlex Bennée	@echo '    EXECUTABLE=<path>    Include executable in image.'
2184c84f662SPhilippe Mathieu-Daudé	@echo '    EXTRA_FILES="<path> [... <path>]"'
2194c84f662SPhilippe Mathieu-Daudé	@echo '                         Include extra files in image.'
22005af039dSMarc-André Lureau	@echo '    ENGINE=auto/docker/podman'
22105af039dSMarc-André Lureau	@echo '                         Specify which container engine to run.'
222324027c2SFam Zheng
223e86c9a64SAlex Bennée# This rule if for directly running against an arbitrary docker target.
224e86c9a64SAlex Bennée# It is called by the expanded docker targets (e.g. make
225e86c9a64SAlex Bennée# docker-test-foo@bar) which will do additional verification.
226e86c9a64SAlex Bennée#
227e86c9a64SAlex Bennée# For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64
228e86c9a64SAlex Bennée#
229e86c9a64SAlex Bennéedocker-run: docker-qemu-src
230324027c2SFam Zheng	@mkdir -p "$(DOCKER_CCACHE_DIR)"
231e86c9a64SAlex Bennée	@if test -z "$(IMAGE)" || test -z "$(TEST)"; \
232e86c9a64SAlex Bennée		then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \
233324027c2SFam Zheng	fi
234e86c9a64SAlex Bennée	$(if $(EXECUTABLE),						\
235324027c2SFam Zheng		$(call quiet-command,					\
236e27cae26SAlex Bennée			$(DOCKER_SCRIPT) update 			\
237e86c9a64SAlex Bennée			$(IMAGE) $(EXECUTABLE),				\
238e86c9a64SAlex Bennée			"  COPYING $(EXECUTABLE) to $(IMAGE)"))
239e86c9a64SAlex Bennée	$(call quiet-command,						\
240e27cae26SAlex Bennée		$(DOCKER_SCRIPT) run 					\
2412461d80eSMarc-André Lureau			$(if $(NOUSER),,--run-as-current-user) 		\
24244707491SFam Zheng			--security-opt seccomp=unconfined		\
243e86c9a64SAlex Bennée			$(if $V,,--rm) 					\
2444b2c6bc5SFam Zheng			$(if $(DEBUG),-ti,)				\
2458a2390a4SDaniel P. Berrange			$(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \
2465609c512SAlex Bennée			-e TARGET_LIST=$(subst $(SPACE),$(COMMA),$(TARGET_LIST))	\
247e86c9a64SAlex Bennée			-e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
248e86c9a64SAlex Bennée			-e V=$V -e J=$J -e DEBUG=$(DEBUG)		\
249e86c9a64SAlex Bennée			-e SHOW_ENV=$(SHOW_ENV) 			\
25036ac78e6SFam Zheng			$(if $(NOUSER),,				\
251324027c2SFam Zheng				-e CCACHE_DIR=/var/tmp/ccache 		\
252324027c2SFam Zheng				-v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \
25336ac78e6SFam Zheng			)						\
25436ac78e6SFam Zheng			-v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
255e86c9a64SAlex Bennée			$(IMAGE) 					\
256c8158513SFam Zheng			/var/tmp/qemu/run 				\
257e86c9a64SAlex Bennée			$(TEST), "  RUN $(TEST) in ${IMAGE}")
25808c3f6d5SPeter Xu	$(call quiet-command, rm -r $(DOCKER_SRC_COPY), \
25908c3f6d5SPeter Xu		"  CLEANUP $(DOCKER_SRC_COPY)")
260e86c9a64SAlex Bennée
261e86c9a64SAlex Bennée# Run targets:
262e86c9a64SAlex Bennée#
263e86c9a64SAlex Bennée# Of the form docker-TEST-FOO@IMAGE-BAR which will then be expanded into a call to "make docker-run"
264e86c9a64SAlex Bennéedocker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
265e86c9a64SAlex Bennéedocker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
266e86c9a64SAlex Bennéedocker-run-%:
267e86c9a64SAlex Bennée	@$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu:$(IMAGE)
268324027c2SFam Zheng
269324027c2SFam Zhengdocker-clean:
270e27cae26SAlex Bennée	$(call quiet-command, $(DOCKER_SCRIPT) clean)
271