-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
171 lines (133 loc) · 5.38 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
NAME=incident-commander
OS = $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH = $(shell uname -m | sed 's/x86_64/amd64/')
ifeq ($(VERSION),)
VERSION_TAG=$(shell git describe --abbrev=0 --tags --exact-match 2>/dev/null || echo latest)
else
VERSION_TAG=$(VERSION)
endif
# Image URL to use all building/pushing image targets
IMG ?= docker.io/flanksource/$(NAME):${VERSION_TAG}
# 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
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: static
static: manifests generate fmt ginkgo
.PHONY: test
test:
ginkgo -r --keep-going --junit-report junit-report.xml --github-output --output-dir test-reports --succinct
fmt:
go fmt ./...
docker:
docker build . -t ${IMG}
# Build the docker image
docker-dev: linux
docker build ./ -f ./Dockerfile.dev -t ${IMG}
docker-push-%:
docker build ./ -f ./Dockerfile.dev -t ${IMG}
docker tag $(IMG) $*/$(IMG)
docker push $*/$(IMG)
kubectl set image deployment/$(NAME) $(NAME)=$*/$(IMG)
# Push the docker image
docker-push:
docker push ${IMG}
.PHONY: tidy
tidy:
go mod tidy
git add go.mod go.sum
.PHONY: compress
compress: .bin/upx
upx -5 ./.bin/$(NAME)_linux_amd64 ./.bin/$(NAME)_linux_arm64
.PHONY: linux
linux:
GOOS=linux GOARCH=amd64 go build -o ./.bin/$(NAME)_linux_amd64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
GOOS=linux GOARCH=arm64 go build -o ./.bin/$(NAME)_linux_arm64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
.PHONY: darwin
darwin:
GOOS=darwin GOARCH=amd64 go build -o ./.bin/$(NAME)_darwin_amd64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
GOOS=darwin GOARCH=arm64 go build -o ./.bin/$(NAME)_darwin_arm64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
.PHONY: windows
windows:
GOOS=windows GOARCH=amd64 go build -o ./.bin/$(NAME).exe -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
.PHONY: binaries
binaries: linux darwin windows compress
.PHONY: release
release: binaries
mkdir -p .release
cp .bin/incident-commander* .release/
.PHONY: lint
lint:
golangci-lint run
# Generate OpenAPI schema
.PHONY: gen-schemas
gen-schemas:
cp go.mod hack/generate-schemas && \
cd hack/generate-schemas && \
go mod edit -module=github.com/flanksource/incident-commander/hack/generate-schemas && \
go mod edit -require=github.com/flanksource/incident-commander@v1.0.0 && \
go mod edit -replace=github.com/flanksource/incident-commander=../../ && \
go mod tidy && \
go run ./main.go
.PHONY: manifests
manifests: controller-gen generate gen-schemas ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) crd paths="./api/..." output:crd:artifacts:config=config/crds
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object paths="./api/..."
.PHONY: build
build:
go build -o ./.bin/$(NAME) -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
.PHONY: dev
dev:
go build -x -v -o ./.bin/$(NAME) -gcflags="all=-N -l" main.go
.PHONY: install
install:
cp ./.bin/$(NAME) /usr/local/bin/
.PHONY: test-e2e
test-e2e: bin
./test/e2e.sh
.bin/upx: .bin
wget -nv -O upx.tar.xz https://github.com/upx/upx/releases/download/v3.96/upx-3.96-$(ARCH)_$(OS).tar.xz
tar xf upx.tar.xz
mv upx-3.96-$(ARCH)_$(OS)/upx .bin
rm -rf upx-3.96-$(ARCH)_$(OS)
.bin:
mkdir -p .bin
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/.bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.14.0
.PHONY: ginkgo
ginkgo:
go install github.com/onsi/ginkgo/v2/ginkgo
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
$(KUSTOMIZE): $(LOCALBIN)
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/kustomize; \
fi
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest