-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
118 lines (97 loc) · 3.87 KB
/
Makefile
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Image URL to use all building/pushing image targets
IMG ?= keppel.eu-de-1.cloud.sap/ccloud/git-cert-shim
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
## Location to install dependencies an GO binaries
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
GOLINT ?= $(LOCALBIN)/golangci-lint
## Tool Versions
GOLINT_VERSION ?= 1.63.4
GINKGOLINTER_VERSION ?= 0.18.4
CONTROLLER_GEN_VERSION ?= 0.16.5
all: build
# Run tests
test: generate fmt vet manifests
go test ./... -coverprofile cover.out
# Build git-cert-shim binary
build: BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
build: GIT_REVISION=$(shell git rev-parse --short HEAD)
build: GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
build: VERSION=$(shell cat VERSION)
build: generate fmt vet
go build\
-ldflags "-s -w -X github.com/sapcc/git-cert-shim/pkg/version.Revision=$(GIT_REVISION) -X github.com/sapcc/git-cert-shim/pkg/version.Branch=$(GIT_BRANCH) -X github.com/sapcc/git-cert-shim/pkg/version.BuildDate=$(BUILD_DATE) -X github.com/sapcc/git-cert-shim/pkg/version.Version=$(VERSION)"\
-o bin/git-cert-shim main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
go run ./main.go
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: VERSION=$(shell cat VERSION)
deploy: manifests
@if [ ! -f deploy-with-kustomize ]; then echo "ERROR: The deployment in CCloud is now managed with Helm! Refusing to deploy unless you 'touch ./deploy-with-kustomize'."; false; fi
cd config/controller && kustomize edit set image git-cert-shim=${IMG}:${VERSION}
kustomize build config | kubectl apply -f -
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) rbac:roleName=git-cert-shim-role webhook paths="./..." output:rbac:artifacts:config=config/rbac
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build the docker image
docker-build: VERSION=$(shell cat VERSION)
docker-build:
docker build . --platform linux/amd64 -t ${IMG}:${VERSION}
# Push the docker image
docker-push: VERSION=$(shell cat VERSION)
docker-push:
docker push ${IMG}:${VERSION} && \
docker tag ${IMG}:${VERSION} ${IMG}:latest && \
docker push ${IMG}:latest
git-push-tag: VERSION=$(shell cat VERSION)
git-push-tag:
git push origin ${VERSION}
git-tag-release: VERSION=$(shell cat VERSION)
git-tag-release: check-release-version
git tag --annotate ${VERSION} --message "git-cert-shim ${VERSION}"
check-release-version: VERSION=$(shell cat VERSION)
check-release-version:
if test x$$(git tag --list ${VERSION}) != x; \
then \
echo "Tag [${VERSION}] already exists. Please check the working copy."; git diff . ; exit 1;\
fi
set-image: VERSION=$(shell cat VERSION)
set-image:
cd config/controller && kustomize edit set image git-cert-shim=${IMG}:${VERSION}
git commit -am "set git-cert-shim image to ${VERSION}"
release: VERSION=$(shell cat VERSION)
release: git-tag-release set-image git-push-tag docker-build docker-push
# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v$(CONTROLLER_GEN_VERSION)
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
.PHONY: lint
lint: golint
$(GOLINT) run -v --timeout 5m
.PHONY: golint
golint: $(GOLINT)
$(GOLINT): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(GOLINT_VERSION)
GOBIN=$(LOCALBIN) go install github.com/nunnatsa/ginkgolinter/cmd/ginkgolinter@v$(GINKGOLINTER_VERSION)