mirror of https://github.com/ceph/go-ceph
tests: parameterize Ceph version for container build and build-tags
Pass `CEPH_VERSION=minic` (or 'luminous') on the `make test-docker` command to select building a container with a different Ceph version and running the tests in it. This passes the given CEPH_VERSION on to the `docker build` command as a --build-arg, which gets used for selecting the Ceph repository during container build. It also sets the environment variable CEPH_VERSION, which in turn is consumed by `entrypoint.sh` to set the `go build -tags ${CEPH_VERSION}` option that includes/excludes certain *.go files. See-also: https://golang.org/pkg/go/build/#hdr-Build_Constraints Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
7e3a5850f3
commit
86a3a66849
|
@ -7,7 +7,9 @@ RUN apt-get update && apt-get install -y \
|
|||
uuid-runtime \
|
||||
wget
|
||||
|
||||
ARG CEPH_REPO_URL=https://download.ceph.com/debian-nautilus/
|
||||
ARG CEPH_VERSION
|
||||
ENV CEPH_VERSION=${CEPH_VERSION:-nautilus}
|
||||
ARG CEPH_REPO_URL=https://download.ceph.com/debian-${CEPH_VERSION}/
|
||||
RUN wget -q -O- 'https://download.ceph.com/keys/release.asc' | apt-key add -
|
||||
RUN true && \
|
||||
apt-add-repository "deb ${CEPH_REPO_URL} xenial main" && \
|
||||
|
|
14
Makefile
14
Makefile
|
@ -2,6 +2,7 @@ DOCKER_CI_IMAGE = go-ceph-ci
|
|||
CONTAINER_CMD := docker
|
||||
CONTAINER_OPTS := --security-opt $(shell grep -q selinux /sys/kernel/security/lsm && echo "label=disabled" || echo "apparmor:unconfined")
|
||||
VOLUME_FLAGS :=
|
||||
CEPH_VERSION := nautilus
|
||||
|
||||
SELINUX := $(shell getenforce 2>/dev/null)
|
||||
ifeq ($(SELINUX),Enforcing)
|
||||
|
@ -9,18 +10,25 @@ ifeq ($(SELINUX),Enforcing)
|
|||
endif
|
||||
|
||||
build:
|
||||
go build -v $(shell go list ./... | grep -v /contrib)
|
||||
go build -v -tags $(CEPH_VERSION) $(shell go list ./... | grep -v /contrib)
|
||||
fmt:
|
||||
go fmt ./...
|
||||
test:
|
||||
go test -v ./...
|
||||
|
||||
test-docker: .build-docker
|
||||
test-docker: check-ceph-version .build-docker
|
||||
$(CONTAINER_CMD) run --device /dev/fuse --cap-add SYS_ADMIN $(CONTAINER_OPTS) --rm -it -v $(CURDIR):/go/src/github.com/ceph/go-ceph$(VOLUME_FLAGS) $(DOCKER_CI_IMAGE)
|
||||
|
||||
.build-docker: Dockerfile entrypoint.sh
|
||||
$(CONTAINER_CMD) build -t $(DOCKER_CI_IMAGE) .
|
||||
$(CONTAINER_CMD) build --build-arg CEPH_VERSION=$(CEPH_VERSION) -t $(DOCKER_CI_IMAGE) .
|
||||
@$(CONTAINER_CMD) inspect -f '{{.Id}}' $(DOCKER_CI_IMAGE) > .build-docker
|
||||
echo $(CEPH_VERSION) >> .build-docker
|
||||
|
||||
# check-ceph-version checks for the last used Ceph version in the container
|
||||
# image and forces a rebuild of the image in case the Ceph version changed
|
||||
.PHONY: check-ceph-version
|
||||
check-ceph-version:
|
||||
@grep -wq '$(CEPH_VERSION)' .build-docker 2>/dev/null || $(RM) .build-docker
|
||||
|
||||
check:
|
||||
# Configure project's revive checks using .revive.toml
|
||||
|
|
|
@ -8,6 +8,7 @@ COVERAGE=yes
|
|||
CPUPROFILE=no
|
||||
MEMPROFILE=no
|
||||
MICRO_OSD_PATH="/micro-osd.sh"
|
||||
BUILD_TAGS=""
|
||||
|
||||
CLI="$(getopt -o h --long test-run:,test-pkg:,pause,cpuprofile,memprofile,no-cover,micro-osd:,help -n "${0}" -- "$@")"
|
||||
eval set -- "${CLI}"
|
||||
|
@ -69,6 +70,10 @@ while true ; do
|
|||
esac
|
||||
done
|
||||
|
||||
if [ -n "${CEPH_VERSION}" ]; then
|
||||
BUILD_TAGS="-tags ${CEPH_VERSION}"
|
||||
fi
|
||||
|
||||
show() {
|
||||
echo "*** running:" "$@"
|
||||
"$@"
|
||||
|
@ -87,7 +92,8 @@ test_pkg() {
|
|||
return 0
|
||||
fi
|
||||
# disable caching of tests results
|
||||
testargs=("-count=1")
|
||||
testargs=("-count=1"\
|
||||
${BUILD_TAGS})
|
||||
if [[ ${TEST_RUN} != ALL ]]; then
|
||||
testargs+=("-run" "${TEST_RUN}")
|
||||
fi
|
||||
|
@ -112,7 +118,7 @@ test_pkg() {
|
|||
|
||||
pre_all_tests() {
|
||||
# Prepare Go code
|
||||
go get -t -v ./...
|
||||
go get -t -v ${BUILD_TAGS} ./...
|
||||
diff -u <(echo -n) <(gofmt -d -s .)
|
||||
|
||||
# TODO: Consider enabling go vet but it currently fails
|
||||
|
|
Loading…
Reference in New Issue