forked from openshift/certman-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
standard.mk
95 lines (77 loc) · 2.69 KB
/
standard.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Validate variables in project.mk exist
ifndef IMAGE_REGISTRY
$(error IMAGE_REGISTRY is not set; check project.mk file)
endif
ifndef IMAGE_REPOSITORY
$(error IMAGE_REPOSITORY is not set; check project.mk file)
endif
ifndef IMAGE_NAME
$(error IMAGE_NAME is not set; check project.mk file)
endif
ifndef VERSION_MAJOR
$(error VERSION_MAJOR is not set; check project.mk file)
endif
ifndef VERSION_MINOR
$(error VERSION_MINOR is not set; check project.mk file)
endif
# Generate version and tag information from inputs
COMMIT_NUMBER=$(shell git rev-list `git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$$"`..HEAD --count)
CURRENT_COMMIT=$(shell git rev-parse --short=8 HEAD)
OPERATOR_VERSION=$(VERSION_MAJOR).$(VERSION_MINOR).$(COMMIT_NUMBER)-$(CURRENT_COMMIT)
IMG?=$(IMAGE_REGISTRY)/$(IMAGE_REPOSITORY)/$(IMAGE_NAME):v$(OPERATOR_VERSION)
OPERATOR_IMAGE_URI=${IMG}
OPERATOR_IMAGE_URI_LATEST=$(IMAGE_REGISTRY)/$(IMAGE_REPOSITORY)/$(IMAGE_NAME):latest
OPERATOR_DOCKERFILE ?=build/ci-operator/Dockerfile
BINFILE=build/_output/bin/$(OPERATOR_NAME)
MAINPACKAGE=./cmd/manager
unexport GOFLAGS
GOENV=GOOS=linux GOARCH=amd64 CGO_ENABLED=0
GOBUILDFLAGS=-gcflags="all=-trimpath=${GOPATH}" -asmflags="all=-trimpath=${GOPATH}"
# ex, -v
TESTOPTS :=
ALLOW_DIRTY_CHECKOUT?=false
default: gobuild
.PHONY: clean
clean:
rm -rf ./build/_output
.PHONY: isclean
isclean:
@(test "$(ALLOW_DIRTY_CHECKOUT)" != "false" || test 0 -eq $$(git status --porcelain | wc -l)) || (echo "Local git checkout is not clean, commit changes and try again." && exit 1)
.PHONY: build
build: isclean envtest
docker build . -f $(OPERATOR_DOCKERFILE) -t $(OPERATOR_IMAGE_URI)
docker tag $(OPERATOR_IMAGE_URI) $(OPERATOR_IMAGE_URI_LATEST)
.PHONY: push
push:
docker push $(OPERATOR_IMAGE_URI)
docker push $(OPERATOR_IMAGE_URI_LATEST)
.PHONY: gocheck
gocheck: ## Lint code
gofmt -s -l ./... | grep ".*\.go"; if [ "$$?" = "0" ]; then gofmt -s -d ./...; exit 1; fi
go vet ./cmd/... ./pkg/...
.PHONY: gobuild
gobuild: ## Build binary
$(GOENV) go build $(GOBUILDFLAGS) -o $(BINFILE) $(MAINPACKAGE)
.PHONY: gotest
gotest:
go test $(TESTOPTS) ./...
.PHONY: coverage
coverage:
hack/codecov.sh
.PHONY: envtest
envtest: isclean
@# test that the env target can be evaluated, required by osd-operators-registry
@eval $$($(MAKE) env --no-print-directory) || (echo 'Unable to evaulate output of `make env`. This breaks osd-operators-registry.' && exit 1)
.PHONY: test
test: envtest gotest
.PHONY: generate
generate:
operator-sdk generate k8s
operator-sdk generate openapi
.PHONY: env
.SILENT: env
env: isclean
echo OPERATOR_NAME=$(OPERATOR_NAME)
echo OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE)
echo OPERATOR_VERSION=$(OPERATOR_VERSION)
echo OPERATOR_IMAGE_URI=$(OPERATOR_IMAGE_URI)