From 60a8e879e59bf7d5888708a0d1d63bd318e91230 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Sat, 18 Apr 2020 16:55:23 +0200 Subject: [PATCH] ci: add make target for containerized tests `make containerized-test` has been added as a make target. This runs the 'make test' target in a container. All test dependencies are installed in the container once, and the container is kept around for running `make containerized-test` subsequently. The test container is based on Fedora:latest so that all test tools get easily installed and are available in a recent version. The production container is based on the Ceph container which has CentOS as Operating System and therefor a more stable (too old) toolset. Signed-off-by: Niels de Vos --- Makefile | 16 +++++++++++++-- scripts/Dockerfile.test | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 scripts/Dockerfile.test diff --git a/Makefile b/Makefile index 99d9a9dc6..57b112b46 100644 --- a/Makefile +++ b/Makefile @@ -71,19 +71,29 @@ cephcsi: if [ ! -d ./vendor ]; then (go mod tidy && go mod vendor); fi GOOS=linux GOARCH=$(GOARCH) go build -mod vendor -a -ldflags '$(LDFLAGS)' -o _output/cephcsi ./cmd/ -.PHONY: containerized-build +.PHONY: containerized-build containerized-test containerized-build: .devel-container-id $(CONTAINER_CMD) run --rm -v $(PWD):/go/src/github.com/ceph/ceph-csi$(SELINUX_VOL_FLAG) $(CSI_IMAGE_NAME):devel make -C /go/src/github.com/ceph/ceph-csi cephcsi +containerized-test: .test-container-id + $(CONTAINER_CMD) run --rm -v $(PWD):/go/src/github.com/ceph/ceph-csi$(SELINUX_VOL_FLAG) $(CSI_IMAGE_NAME):test make test + # create a (cached) container image with dependencied for building cephcsi .devel-container-id: scripts/Dockerfile.devel [ ! -f .devel-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):devel $(CONTAINER_CMD) build -t $(CSI_IMAGE_NAME):devel -f ./scripts/Dockerfile.devel . $(CONTAINER_CMD) inspect -f '{{.Id}}' $(CSI_IMAGE_NAME):devel > .devel-container-id +# create a (cached) container image with dependencied for testing cephcsi +.test-container-id: scripts/Dockerfile.test + [ ! -f .test-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):test + $(CONTAINER_CMD) build -t $(CSI_IMAGE_NAME):test -f ./scripts/Dockerfile.test . + $(CONTAINER_CMD) inspect -f '{{.Id}}' $(CSI_IMAGE_NAME):test > .test-container-id + image-cephcsi: $(CONTAINER_CMD) build -t $(CSI_IMAGE) -f deploy/cephcsi/image/Dockerfile . --build-arg GOLANG_VERSION=1.13.8 --build-arg CSI_IMAGE_NAME=$(CSI_IMAGE_NAME) --build-arg CSI_IMAGE_VERSION=$(CSI_IMAGE_VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg GO_ARCH=$(GOARCH) $(BASE_IMAGE_ARG) + push-image-cephcsi: image-cephcsi $(CONTAINER_CMD) tag $(CSI_IMAGE) $(CSI_IMAGE)-$(GOARCH) $(CONTAINER_CMD) push $(CSI_IMAGE)-$(GOARCH) @@ -91,8 +101,10 @@ push-image-cephcsi: image-cephcsi if [ $(GOARCH) = amd64 ]; then $(CONTAINER_CMD) push $(CSI_IMAGE); fi clean: - go clean -r -x + go clean -mod=vendor -r -x rm -f deploy/cephcsi/image/cephcsi rm -f _output/cephcsi [ ! -f .devel-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):devel $(RM) .devel-container-id + [ ! -f .test-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):test + $(RM) .test-container-id diff --git a/scripts/Dockerfile.test b/scripts/Dockerfile.test new file mode 100644 index 000000000..d34694139 --- /dev/null +++ b/scripts/Dockerfile.test @@ -0,0 +1,43 @@ +# Container image for running the Ceph-CSI tests +# +# This container is based on Fedora so that recent versions of tools can easily +# be installed. +# +# Production containers are based one ceph/ceph:latest, which use CentOS as +# Operating System, so generated binaries and versions of dependencies may be a +# little different. +# + +FROM fedora:latest + +ARG GOLANGCI_VERSION=v1.21.0 +ARG GOSEC_VERSION=2.0.0 +ARG GOPATH=/go + +ENV \ + GOPATH=${GOPATH} \ + GO111MODULE=on \ + PATH="${GOPATH}/bin:${PATH}" + + +RUN dnf -y install \ + git \ + make \ + golang \ + gcc \ + librados-devel \ + librbd-devel \ + rubygems \ + ShellCheck \ + yamllint \ + && dnf -y update \ + && dnf -y clean all \ + && gem install mdl \ + && curl -sf "https://install.goreleaser.com/github.com/golangci/golangci-lint.sh" \ + | bash -s -- -b ${GOPATH}/bin "${GOLANGCI_VERSION}" \ + && curl -sfL "https://raw.githubusercontent.com/securego/gosec/master/install.sh" \ + | sh -s -- -b $GOPATH/bin "${GOSEC_VERSION}" \ + && curl -L https://git.io/get_helm.sh | bash \ + && true + +WORKDIR /go/src/github.com/ceph/ceph-csi