1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00
kube-arangodb/Makefile

309 lines
8.4 KiB
Makefile
Raw Normal View History

2018-02-09 10:11:33 +00:00
PROJECT := arangodb_operator
SCRIPTDIR := $(shell pwd)
ROOTDIR := $(shell cd $(SCRIPTDIR) && pwd)
VERSION := $(shell cat $(ROOTDIR)/VERSION)
VERSION_MAJOR_MINOR_PATCH := $(shell echo $(VERSION) | cut -f 1 -d '+')
VERSION_MAJOR_MINOR := $(shell echo $(VERSION_MAJOR_MINOR_PATCH) | cut -f 1,2 -d '.')
VERSION_MAJOR := $(shell echo $(VERSION_MAJOR_MINOR) | cut -f 1 -d '.')
COMMIT := $(shell git rev-parse --short HEAD)
DOCKERCLI := $(shell which docker)
GOBUILDDIR := $(SCRIPTDIR)/.gobuild
SRCDIR := $(SCRIPTDIR)
BINDIR := $(ROOTDIR)/bin
VENDORDIR := $(ROOTDIR)/deps
2018-02-09 10:11:33 +00:00
ORGPATH := github.com/arangodb
ORGDIR := $(GOBUILDDIR)/src/$(ORGPATH)
REPONAME := k8s-operator
REPODIR := $(ORGDIR)/$(REPONAME)
REPOPATH := $(ORGPATH)/$(REPONAME)
GOPATH := $(GOBUILDDIR)
2018-02-19 15:11:32 +00:00
GOVERSION := 1.10.0-alpine
2018-02-09 10:11:33 +00:00
PULSAR := $(GOBUILDDIR)/bin/pulsar$(shell go env GOEXE)
2018-02-20 08:49:01 +00:00
DOCKERFILE := Dockerfile
DOCKERTESTFILE := Dockerfile.test
2018-02-09 10:11:33 +00:00
2018-03-12 11:18:50 +00:00
ifndef LOCALONLY
2018-03-12 12:28:19 +00:00
PUSHIMAGES := 1
2018-03-12 11:18:50 +00:00
IMAGESHA256 := true
else
IMAGESHA256 := false
endif
2018-02-20 17:53:33 +00:00
ifdef IMAGETAG
2018-03-12 11:18:50 +00:00
IMAGESUFFIX := :$(IMAGETAG)
else
IMAGESUFFIX := :dev
endif
ifndef MANIFESTPATH
MANIFESTPATH := manifests/arango-operator-dev.yaml
endif
ifndef DEPLOYMENTNAMESPACE
DEPLOYMENTNAMESPACE := default
2018-02-20 17:53:33 +00:00
endif
ifndef OPERATORIMAGE
OPERATORIMAGE := $(DOCKERNAMESPACE)/arangodb-operator$(IMAGESUFFIX)
endif
ifndef TESTIMAGE
TESTIMAGE := $(DOCKERNAMESPACE)/arangodb-operator-test$(IMAGESUFFIX)
endif
2018-02-27 08:30:00 +00:00
ifndef ENTERPRISEIMAGE
ENTERPRISEIMAGE := $(DEFAULTENTERPRISEIMAGE)
endif
2018-02-20 17:53:33 +00:00
2018-02-09 10:11:33 +00:00
BINNAME := $(PROJECT)
BIN := $(BINDIR)/$(BINNAME)
2018-02-20 08:49:01 +00:00
TESTBINNAME := $(PROJECT)_test
TESTBIN := $(BINDIR)/$(TESTBINNAME)
2018-02-09 10:11:33 +00:00
RELEASE := $(GOBUILDDIR)/bin/release
GHRELEASE := $(GOBUILDDIR)/bin/github-release
2018-03-01 10:15:18 +00:00
TESTLENGTHOPTIONS := -test.short
TESTTIMEOUT := 20m
ifeq ($(LONG), 1)
TESTLENGTHOPTIONS :=
TESTTIMEOUT := 40m
endif
2018-03-01 15:10:20 +00:00
ifdef VERBOSE
TESTVERBOSEOPTIONS := -v
endif
2018-02-20 09:58:28 +00:00
2018-02-09 10:11:33 +00:00
SOURCES := $(shell find $(SRCDIR) -name '*.go' -not -path './test/*')
2018-03-12 11:18:50 +00:00
.PHONY: all
2018-03-12 12:12:01 +00:00
all: verify-generated build
2018-02-09 10:11:33 +00:00
2018-02-09 14:46:14 +00:00
#
# Tip: Run `eval $(minikube docker-env)` before calling make if you're developing on minikube.
#
2018-03-12 11:18:50 +00:00
.PHONY: build
build: check-vars docker manifests
2018-02-09 10:11:33 +00:00
2018-03-12 11:18:50 +00:00
.PHONY: clean
2018-02-09 10:11:33 +00:00
clean:
rm -Rf $(BIN) $(BINDIR) $(GOBUILDDIR)
2018-03-12 11:18:50 +00:00
.PHONY: check-vars
check-vars:
ifndef DOCKERNAMESPACE
@echo "DOCKERNAMESPACE must be set"
@exit 1
endif
@echo "Using docker namespace: $(DOCKERNAMESPACE)"
.PHONY: deps
2018-02-09 10:11:33 +00:00
deps:
@${MAKE} -B -s $(GOBUILDDIR)
$(GOBUILDDIR):
# Build pulsar from vendor
@mkdir -p $(GOBUILDDIR)
@ln -sf $(VENDORDIR) $(GOBUILDDIR)/src
@GOPATH=$(GOBUILDDIR) go install github.com/pulcy/pulsar
@rm -Rf $(GOBUILDDIR)/src
# Prepare .gobuild directory
2018-02-09 10:11:33 +00:00
@mkdir -p $(ORGDIR)
@rm -f $(REPODIR) && ln -sf ../../../.. $(REPODIR)
GOPATH=$(GOBUILDDIR) $(PULSAR) go flatten -V $(VENDORDIR)
2018-02-09 10:11:33 +00:00
2018-03-12 11:18:50 +00:00
.PHONY: update-vendor
update-vendor:
@mkdir -p $(GOBUILDDIR)
@GOPATH=$(GOBUILDDIR) go get github.com/pulcy/pulsar
2018-02-09 10:11:33 +00:00
@rm -Rf $(VENDORDIR)
@mkdir -p $(VENDORDIR)
@git clone https://github.com/kubernetes/code-generator.git $(VENDORDIR)/k8s.io/code-generator
@rm -Rf $(VENDORDIR)/k8s.io/code-generator/.git
2018-02-15 10:54:48 +00:00
@$(PULSAR) go vendor -V $(VENDORDIR) \
k8s.io/client-go/... \
k8s.io/gengo/args \
k8s.io/apiextensions-apiserver \
2018-02-23 06:43:56 +00:00
github.com/arangodb/go-driver \
2018-02-15 10:54:48 +00:00
github.com/cenkalti/backoff \
github.com/dchest/uniuri \
2018-02-16 10:46:46 +00:00
github.com/dgrijalva/jwt-go \
2018-03-05 10:06:53 +00:00
github.com/julienschmidt/httprouter \
2018-02-15 10:54:48 +00:00
github.com/pkg/errors \
github.com/prometheus/client_golang/prometheus \
github.com/pulcy/pulsar \
github.com/rs/zerolog \
2018-02-27 12:26:47 +00:00
github.com/spf13/cobra \
github.com/stretchr/testify
2018-02-09 10:11:33 +00:00
@$(PULSAR) go flatten -V $(VENDORDIR) $(VENDORDIR)
@${MAKE} -B -s clean
2018-03-12 11:18:50 +00:00
.PHONY: update-generated
2018-02-09 10:11:33 +00:00
update-generated: $(GOBUILDDIR)
@docker build $(SRCDIR)/tools/codegen --build-arg GOVERSION=$(GOVERSION) -t k8s-codegen
docker run \
--rm \
-v $(SRCDIR):/usr/code \
-e GOPATH=/usr/code/.gobuild \
-e GOBIN=/usr/code/.gobuild/bin \
-w /usr/code/ \
k8s-codegen \
"./deps/k8s.io/code-generator/generate-groups.sh" \
2018-02-09 10:11:33 +00:00
"all" \
"github.com/arangodb/k8s-operator/pkg/generated" \
"github.com/arangodb/k8s-operator/pkg/apis" \
2018-03-05 09:00:23 +00:00
"arangodb:v1alpha storage:v1alpha" \
2018-02-09 10:11:33 +00:00
--go-header-file "./tools/codegen/boilerplate.go.txt" \
$(VERIFYARGS)
2018-03-12 11:18:50 +00:00
.PHONY: verify-generated
2018-02-09 10:11:33 +00:00
verify-generated:
@${MAKE} -B -s VERIFYARGS=--verify-only update-generated
$(BIN): $(GOBUILDDIR) $(SOURCES)
@mkdir -p $(BINDIR)
docker run \
--rm \
-v $(SRCDIR):/usr/code \
-e GOPATH=/usr/code/.gobuild \
-e GOOS=linux \
-e GOARCH=amd64 \
-e CGO_ENABLED=0 \
2018-02-09 10:11:33 +00:00
-w /usr/code/ \
golang:$(GOVERSION) \
2018-02-09 16:21:06 +00:00
go build -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(BINNAME) $(REPOPATH)
2018-02-09 10:11:33 +00:00
2018-03-12 11:18:50 +00:00
.PHONY: docker
docker: check-vars $(BIN)
2018-02-20 17:53:33 +00:00
docker build -f $(DOCKERFILE) -t $(OPERATORIMAGE) .
2018-02-22 15:54:36 +00:00
ifdef PUSHIMAGES
docker push $(OPERATORIMAGE)
endif
2018-02-09 10:11:33 +00:00
2018-03-12 11:18:50 +00:00
# Manifests
.PHONY: manifests
2018-03-12 12:16:09 +00:00
manifests: $(GOBUILDDIR)
GOPATH=$(GOBUILDDIR) go run $(ROOTDIR)/tools/manifests/manifest_builder.go \
2018-03-12 11:18:50 +00:00
--output=$(MANIFESTPATH) \
--image=$(OPERATORIMAGE) \
--image-sha256=$(IMAGESHA256) \
--namespace=$(DEPLOYMENTNAMESPACE)
2018-02-20 08:49:01 +00:00
# Testing
2018-03-12 11:18:50 +00:00
.PHONY: run-unit-tests
2018-02-27 14:32:09 +00:00
run-unit-tests: $(GOBUILDDIR) $(SOURCES)
docker run \
--rm \
-v $(SRCDIR):/usr/code \
-e GOPATH=/usr/code/.gobuild \
-e GOOS=linux \
-e GOARCH=amd64 \
-e CGO_ENABLED=0 \
-w /usr/code/ \
golang:$(GOVERSION) \
2018-03-01 15:10:20 +00:00
go test $(TESTVERBOSEOPTIONS) \
2018-03-01 07:49:27 +00:00
$(REPOPATH)/pkg/apis/arangodb/v1alpha \
2018-03-01 13:27:20 +00:00
$(REPOPATH)/pkg/deployment \
2018-03-06 20:16:11 +00:00
$(REPOPATH)/pkg/util/k8sutil \
$(REPOPATH)/pkg/util/k8sutil/test
2018-02-27 14:32:09 +00:00
2018-02-20 08:49:01 +00:00
$(TESTBIN): $(GOBUILDDIR) $(SOURCES)
@mkdir -p $(BINDIR)
2018-02-20 09:58:28 +00:00
docker run \
2018-02-20 08:49:01 +00:00
--rm \
-v $(SRCDIR):/usr/code \
-e GOPATH=/usr/code/.gobuild \
-e GOOS=linux \
-e GOARCH=amd64 \
-e CGO_ENABLED=0 \
-w /usr/code/ \
golang:$(GOVERSION) \
2018-02-27 14:32:09 +00:00
go test -c -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(TESTBINNAME) $(REPOPATH)/tests
2018-02-20 08:49:01 +00:00
2018-03-12 11:18:50 +00:00
.PHONY: docker-test
2018-02-20 08:49:01 +00:00
docker-test: $(TESTBIN)
2018-02-20 17:53:33 +00:00
docker build --quiet -f $(DOCKERTESTFILE) -t $(TESTIMAGE) .
2018-02-20 08:49:01 +00:00
2018-03-12 11:18:50 +00:00
.PHONY: run-tests
2018-02-20 08:49:01 +00:00
run-tests: docker-test
2018-02-20 17:53:33 +00:00
ifdef PUSHIMAGES
docker push $(OPERATORIMAGE)
docker push $(TESTIMAGE)
endif
2018-03-12 11:18:50 +00:00
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(DEPLOYMENTNAMESPACE)
kubectl create namespace $(DEPLOYMENTNAMESPACE)
kubectl apply -f $(MANIFESTPATH)
$(ROOTDIR)/scripts/kube_create_storage.sh $(DEPLOYMENTNAMESPACE)
kubectl --namespace $(DEPLOYMENTNAMESPACE) \
2018-02-27 08:30:00 +00:00
run arangodb-operator-test -i --rm --quiet --restart=Never \
--image=$(TESTIMAGE) \
--env="ENTERPRISEIMAGE=$(ENTERPRISEIMAGE)" \
2018-03-12 11:18:50 +00:00
--env="TEST_NAMESPACE=$(DEPLOYMENTNAMESPACE)" \
2018-02-27 08:30:00 +00:00
-- \
2018-03-01 10:15:18 +00:00
-test.v -test.timeout $(TESTTIMEOUT) $(TESTLENGTHOPTIONS)
2018-03-12 11:18:50 +00:00
ifneq ($(DEPLOYMENTNAMESPACE), default)
kubectl delete namespace $(DEPLOYMENTNAMESPACE) --ignore-not-found --now
endif
2018-02-20 08:49:01 +00:00
2018-03-12 11:18:50 +00:00
.PHONY: cleanup-tests
2018-02-27 10:31:27 +00:00
cleanup-tests:
2018-03-12 11:18:50 +00:00
ifneq ($(DEPLOYMENTNAMESPACE), default)
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(DEPLOYMENTNAMESPACE)
endif
2018-02-27 10:31:27 +00:00
2018-02-20 08:49:01 +00:00
# Release building
2018-03-12 11:18:50 +00:00
.PHONY: docker-push
2018-02-09 10:11:33 +00:00
docker-push: docker
ifneq ($(DOCKERNAMESPACE), arangodb)
2018-02-20 17:53:33 +00:00
docker tag $(OPERATORIMAGE) $(DOCKERNAMESPACE)/arangodb-operator
2018-02-09 10:11:33 +00:00
endif
docker push $(DOCKERNAMESPACE)/arangodb-operator
2018-03-12 11:18:50 +00:00
.PHONY: docker-push-version
2018-02-09 10:11:33 +00:00
docker-push-version: docker
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:$(VERSION)
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:$(VERSION_MAJOR_MINOR)
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:$(VERSION_MAJOR)
docker tag arangodb/arangodb-operator arangodb/arangodb-operator:latest
docker push arangodb/arangodb-operator:$(VERSION)
docker push arangodb/arangodb-operator:$(VERSION_MAJOR_MINOR)
docker push arangodb/arangodb-operator:$(VERSION_MAJOR)
docker push arangodb/arangodb-operator:latest
$(RELEASE): $(GOBUILDDIR) $(SOURCES) $(GHRELEASE)
GOPATH=$(GOBUILDDIR) go build -o $(RELEASE) $(REPOPATH)/tools/release
$(GHRELEASE): $(GOBUILDDIR)
GOPATH=$(GOBUILDDIR) go build -o $(GHRELEASE) github.com/aktau/github-release
2018-03-12 11:18:50 +00:00
.PHONY: release-patch
2018-02-09 10:11:33 +00:00
release-patch: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=patch
2018-03-12 11:18:50 +00:00
.PHONY: release-minor
2018-02-09 10:11:33 +00:00
release-minor: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=minor
2018-03-12 11:18:50 +00:00
.PHONY: release-major
2018-02-09 10:11:33 +00:00
release-major: $(RELEASE)
GOPATH=$(GOBUILDDIR) $(RELEASE) -type=major
## Kubernetes utilities
2018-03-12 11:18:50 +00:00
.PHONY: minikube-start
minikube-start:
minikube start --cpus=4 --memory=6144
2018-03-12 11:18:50 +00:00
.PHONY: delete-operator
delete-operator:
2018-03-12 11:18:50 +00:00
kubectl delete -f $(MANIFESTPATH) --ignore-not-found
2018-03-12 11:18:50 +00:00
.PHONY: redeploy-operator
redeploy-operator: delete-operator manifests
kubectl apply -f $(MANIFESTPATH)
kubectl get pods