build: add option to compile e2e.test in a container

Run `make containerized-build TARGET=e2e.test` to build the e2e.test
executable in a container. This makes it possible for environments to
only have the dependencies for the runtime installed (most notably Ceph
shared libraries) and, run the e2e tests directly.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-05-28 14:32:38 +02:00 committed by mergify[bot]
parent 44da7ffb4e
commit c0b53d3ad4
2 changed files with 25 additions and 8 deletions

3
.gitignore vendored
View File

@ -1,6 +1,9 @@
# build directory # build directory
_output _output
# e2e test executable
e2e.test
# docker build # docker build
deploy/cephcsi/image/cephcsi deploy/cephcsi/image/cephcsi

View File

@ -47,11 +47,19 @@ ifdef BASE_IMAGE
BASE_IMAGE_ARG = --build-arg BASE_IMAGE=$(BASE_IMAGE) BASE_IMAGE_ARG = --build-arg BASE_IMAGE=$(BASE_IMAGE)
endif endif
# passing TARGET=static-check on the 'make containerized-test' commandline will # passing TARGET=static-check on the 'make containerized-test' or 'make
# run the selected target instead of 'make test' in the container. Obviously # containerized-build' commandline will run the selected target instead of
# other targets can be passed as well, making it easier for developers to run # 'make test' in the container. Obviously other targets can be passed as well,
# single tests. # making it easier for developers to run single tests or build different
TARGET ?= test # executables.
#
# Defaults:
# make containerized-build TARGET=cephcsi -> runs 'make cephcsi'
# make containerized-test TARGET=test -> runs 'make test'
#
# Other options:
# make containerized-build TARGET=e2e.test -> runs 'make e2e.test'
# make containerized-test TARGET=static-check -> runs 'make static-check'
# Pass GIT_SINCE for the range of commits to test. Used with the commitlint # Pass GIT_SINCE for the range of commits to test. Used with the commitlint
# target. # target.
@ -110,10 +118,15 @@ cephcsi: check-env
if [ ! -d ./vendor ]; then (go mod tidy && go mod vendor); fi if [ ! -d ./vendor ]; then (go mod tidy && go mod vendor); fi
GOOS=linux go build -mod vendor -a -ldflags '$(LDFLAGS)' -o _output/cephcsi ./cmd/ GOOS=linux go build -mod vendor -a -ldflags '$(LDFLAGS)' -o _output/cephcsi ./cmd/
.PHONY: containerized-build containerized-test e2e.test: check-env
containerized-build: .devel-container-id go test -mod=vendor -c ./e2e
$(CONTAINER_CMD) run --rm -v $(CURDIR):/go/src/github.com/ceph/ceph-csi$(SELINUX_VOL_FLAG) $(CSI_IMAGE_NAME):devel make cephcsi
.PHONY: containerized-build containerized-test
containerized-build: TARGET = cephcsi
containerized-build: .devel-container-id
$(CONTAINER_CMD) run --rm -v $(CURDIR):/go/src/github.com/ceph/ceph-csi$(SELINUX_VOL_FLAG) $(CSI_IMAGE_NAME):devel make $(TARGET)
containerized-test: TARGET = test
containerized-test: .test-container-id containerized-test: .test-container-id
$(CONTAINER_CMD) run --rm -v $(CURDIR):/go/src/github.com/ceph/ceph-csi$(SELINUX_VOL_FLAG) $(CSI_IMAGE_NAME):test make $(TARGET) GIT_SINCE=$(GIT_SINCE) $(CONTAINER_CMD) run --rm -v $(CURDIR):/go/src/github.com/ceph/ceph-csi$(SELINUX_VOL_FLAG) $(CSI_IMAGE_NAME):test make $(TARGET) GIT_SINCE=$(GIT_SINCE)
@ -142,6 +155,7 @@ clean:
go clean -mod=vendor -r -x go clean -mod=vendor -r -x
rm -f deploy/cephcsi/image/cephcsi rm -f deploy/cephcsi/image/cephcsi
rm -f _output/cephcsi rm -f _output/cephcsi
$(RM) e2e.test
[ ! -f .devel-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):devel [ ! -f .devel-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):devel
$(RM) .devel-container-id $(RM) .devel-container-id
[ ! -f .test-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):test [ ! -f .test-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):test