Skip to content
55 changes: 44 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,39 @@ CAT_CMD=$(if $(filter $(OS),Windows_NT),type,cat)
VERSION_FILE=./CONTROLLER_VERSION
RELEASE_VER=v$(shell $(CAT_CMD) $(VERSION_FILE))
CURRENT_DIR=$(shell pwd)
GIT_BRANCH=$(git symbolic-ref --short HEAD 2>&1 | grep -v fatal)
GIT_BRANCH:=$(shell git symbolic-ref --short HEAD 2>&1 | grep -v fatal)
# Reset branch name if this a Travis CI environment
ifneq ($(strip $(TRAVIS_BRANCH)),)
GIT_BRANCH:=${TRAVIS_BRANCH}
endif

TAG:=$(shell echo "")
# Check for git repository id sent by Travis-CI
ifneq ($(strip $(git_repository_id)),)
TAG:=${TAG}${git_repository_id}-
endif

# Check for current branch name
ifneq ($(strip $(GIT_BRANCH)),)
TAG:=${TAG}${GIT_BRANCH}-
endif
TAG:=${TAG}${RELEASE_VER}

.PHONY: print-global-variables

mcad-controller: init generate-code
$(info Compiling controller)
CGO_ENABLED=0 GOARCH=amd64 go build -o ${BIN_DIR}/mcad-controller ./cmd/kar-controllers/

print-global-variables:
$(info "---")
$(info "MAKE GLOBAL VARIABLES:")
$(info " "BIN_DIR="$(BIN_DIR)")
$(info " "GIT_BRANCH="$(GIT_BRANCH)")
$(info " "RELEASE_VER="$(RELEASE_VER)")
$(info " "TAG="$(TAG)")
$(info "---")

verify: generate-code
# hack/verify-gofmt.sh
# hack/verify-golint.sh
Expand All @@ -17,19 +44,25 @@ verify: generate-code
init:
mkdir -p ${BIN_DIR}

verify-tag-name: print-global-variables
# Check for invalid tag name
t=${TAG} && [ $${#t} -le 128 ] || { echo "Target name $$t has 128 or more chars"; false; }

generate-code:
$(info Compiling deepcopy-gen...)
go build -o ${BIN_DIR}/deepcopy-gen ./cmd/deepcopy-gen/
$(info Generating deepcopy...)
${BIN_DIR}/deepcopy-gen -i ./pkg/apis/controller/v1alpha1/ -O zz_generated.deepcopy

images:
images: verify-tag-name
$(info List executable directory)
$(info repo id: ${git_repository_id})
$(info branch: ${GIT_BRANCH})
ls -l ${CURRENT_DIR}/_output/bin
$(info Build the docker image)
docker build --quiet --no-cache --tag mcad-controller:${RELEASE_VER} -f ${CURRENT_DIR}/deployment/Dockerfile.both ${CURRENT_DIR}/_output/bin
docker build --quiet --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/deployment/Dockerfile.both ${CURRENT_DIR}/_output/bin

push-images:
push-images: verify-tag-name
ifeq ($(strip $(dockerhub_repository)),)
$(info No registry information provide. To push images to a docker registry please set)
$(info environment variables: dockerhub_repository, dockerhub_token, and dockerhub_id. Environment)
Expand All @@ -38,22 +71,22 @@ else
$(info Log into dockerhub)
docker login -u ${dockerhub_id} --password ${dockerhub_token}
$(info Tag the latest image)
docker tag mcad-controller:${RELEASE_VER} ${dockerhub_repository}/mcad-controller:${RELEASE_VER}
docker tag mcad-controller:${TAG} ${dockerhub_repository}/mcad-controller:${TAG}
$(info Push the docker image to registry)
docker push ${dockerhub_repository}/mcad-controller:${RELEASE_VER}
docker push ${dockerhub_repository}/mcad-controller:${TAG}
endif

run-test:
$(info Running unit tests...)
hack/make-rules/test.sh $(WHAT) $(TESTS)

run-e2e: mcad-controller
run-e2e: mcad-controller verify-tag-name
ifeq ($(strip $(dockerhub_repository)),)
echo "Running e2e with MCAD local image: mcad-controller ${RELEASE_VER} IfNotPresent."
hack/run-e2e-kind.sh mcad-controller ${RELEASE_VER} IfNotPresent
echo "Running e2e with MCAD local image: mcad-controller ${TAG} IfNotPresent."
hack/run-e2e-kind.sh mcad-controller ${TAG} IfNotPresent
else
echo "Running e2e with MCAD registry image image: ${dockerhub_repository}/mcad-controller ${RELEASE_VER}."
hack/run-e2e-kind.sh ${dockerhub_repository}/mcad-controller ${RELEASE_VER}
echo "Running e2e with MCAD registry image image: ${dockerhub_repository}/mcad-controller ${TAG}."
hack/run-e2e-kind.sh ${dockerhub_repository}/mcad-controller ${TAG}
endif

coverage:
Expand Down
2 changes: 1 addition & 1 deletion hack/run-e2e-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function kube-test-env-up {
echo "Installing Helm Client..."
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > install-helm.sh
chmod u+x install-helm.sh
./install-helm.sh --version v2.16.3
./install-helm.sh --version v2.17.0

# Start Helm Server
echo "Installing Helm Server..."
Expand Down