forked from argoproj/argo-rollouts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
331 lines (260 loc) · 12.2 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
PACKAGE=github.com/argoproj/argo-rollouts
CURRENT_DIR=$(shell pwd)
DIST_DIR=${CURRENT_DIR}/dist
PATH := $(DIST_DIR):$(PATH)
PLUGIN_CLI_NAME?=kubectl-argo-rollouts
TEST_TARGET ?= ./...
BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_TAG=$(shell if [ -z "`git status --porcelain`" ]; then git describe --exact-match --tags HEAD 2>/dev/null; fi)
GIT_TREE_STATE=$(shell if [ -z "`git status --porcelain`" ]; then echo "clean" ; else echo "dirty"; fi)
GIT_REMOTE_REPO=upstream
VERSION=$(shell if [ ! -z "${GIT_TAG}" ] ; then echo "${GIT_TAG}" | sed -e "s/^v//" ; else cat VERSION ; fi)
TARGET_ARCH?=linux/amd64
# docker image publishing options
DOCKER_PUSH ?= false
IMAGE_TAG ?= latest
# build development images
DEV_IMAGE ?= false
# E2E variables
E2E_K8S_CONTEXT ?= rancher-desktop
E2E_INSTANCE_ID ?= argo-rollouts-e2e
E2E_TEST_OPTIONS ?=
E2E_PARALLEL ?= 1
E2E_WAIT_TIMEOUT ?= 90
GOPATH ?= $(shell go env GOPATH)
# Global toolchain configuration
NODE_OPTIONS=""
override LDFLAGS += \
-X ${PACKAGE}/utils/version.version=${VERSION} \
-X ${PACKAGE}/utils/version.buildDate=${BUILD_DATE} \
-X ${PACKAGE}/utils/version.gitCommit=${GIT_COMMIT} \
-X ${PACKAGE}/utils/version.gitTreeState=${GIT_TREE_STATE}
ifneq (${GIT_TAG},)
IMAGE_TAG=${GIT_TAG}
override LDFLAGS += -X ${PACKAGE}.gitTag=${GIT_TAG}
endif
ifeq (${DOCKER_PUSH},true)
ifndef IMAGE_NAMESPACE
$(error IMAGE_NAMESPACE must be set to push images (e.g. IMAGE_NAMESPACE=quay.io/argoproj))
endif
endif
ifdef IMAGE_NAMESPACE
IMAGE_PREFIX=${IMAGE_NAMESPACE}/
endif
## protoc,my.proto
define protoc
# protoc $(1)
PATH=${DIST_DIR}:$$PATH protoc \
-I /usr/local/include \
-I ${DIST_DIR}/protoc-include \
-I . \
-I ./vendor \
-I ${GOPATH}/src \
-I ${GOPATH}/pkg/mod/github.com/gogo/[email protected]/gogoproto \
-I ${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
--gogofast_out=plugins=grpc:${GOPATH}/src \
--grpc-gateway_out=logtostderr=true:${GOPATH}/src \
--swagger_out=logtostderr=true,fqn_for_swagger_name=true:. \
$(1)
endef
.PHONY: all
all: controller image
##@ Development
.PHONY: go-mod-vendor
go-mod-vendor: ## downloads vendor files needed by tools.go (i.e. go_install)
go mod tidy
go mod vendor
.PHONY: lint
lint: go-mod-vendor ## run all linters
golangci-lint run --fix
.PHONY: install-go-tools-local
install-go-tools-local: go-mod-vendor ## install all go tools
./hack/installers/install-codegen-go-tools.sh
.PHONY: install-protoc-local
install-protoc-local: ## install protoc tool
./hack/installers/install-protoc.sh
.PHONY: install-devtools-local
install-devtools-local: ## install dev tools
./hack/installers/install-dev-tools.sh
# Installs all tools required to build and test locally
.PHONY: install-tools-local
install-tools-local: install-go-tools-local install-protoc-local install-devtools-local
TYPES := $(shell find pkg/apis/rollouts/v1alpha1 -type f -name '*.go' -not -name openapi_generated.go -not -name '*generated*' -not -name '*test.go')
APIMACHINERY_PKGS=k8s.io/apimachinery/pkg/util/intstr,+k8s.io/apimachinery/pkg/api/resource,+k8s.io/apimachinery/pkg/runtime/schema,+k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/api/core/v1,k8s.io/api/batch/v1
.PHONY: install-toolchain
install-toolchain: install-go-tools-local install-protoc-local
##@ Code Generation
# generates all auto-generated code
.PHONY: codegen
codegen: go-mod-vendor gen-proto gen-k8scodegen gen-openapi gen-mocks gen-crd manifests docs
# generates all files related to proto files
.PHONY: gen-proto
gen-proto: k8s-proto api-proto ui-proto
# generates the .proto files affected by changes to types.go
.PHONY: k8s-proto
k8s-proto: go-mod-vendor $(TYPES) ## generate kubernetes protobuf files
PATH=${DIST_DIR}:$$PATH GOPATH=${GOPATH} go-to-protobuf \
--go-header-file=./hack/custom-boilerplate.go.txt \
--packages=github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1 \
--apimachinery-packages=${APIMACHINERY_PKGS} \
--proto-import $(CURDIR)/vendor \
--proto-import=${DIST_DIR}/protoc-include
touch pkg/apis/rollouts/v1alpha1/generated.proto
cp -R ${GOPATH}/src/github.com/argoproj/argo-rollouts/pkg . | true
# generates *.pb.go, *.pb.gw.go, swagger from .proto files
.PHONY: api-proto
api-proto: go-mod-vendor k8s-proto ## generate api protobuf files
$(call protoc,pkg/apiclient/rollout/rollout.proto)
# generates ui related proto files
.PHONY: ui-proto
ui-proto: ## generate ui protobuf files
yarn --cwd ui run protogen
# generates k8s client, informer, lister, deepcopy from types.go
.PHONY: gen-k8scodegen
gen-k8scodegen: go-mod-vendor ## generate kubernetes codegen files
./hack/update-codegen.sh
# generates ./manifests/crds/
.PHONY: gen-crd
gen-crd: install-go-tools-local ## generate crd manifests
go run ./hack/gen-crd-spec/main.go
# generates mock files from interfaces
.PHONY: gen-mocks
gen-mocks: install-go-tools-local ## generate mock files
./hack/update-mocks.sh
gen-mocks-fast:
./hack/update-mocks.sh
# generates openapi_generated.go
.PHONY: gen-openapi
gen-openapi: $(DIST_DIR)/openapi-gen ## generate openapi files
PATH=${DIST_DIR}:$$PATH GOPATH=${GOPATH} openapi-gen \
--go-header-file ${CURRENT_DIR}/hack/custom-boilerplate.go.txt \
--input-dirs github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1 \
--output-package github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1 \
--report-filename pkg/apis/api-rules/violation_exceptions.list
##@ Plugins
.PHONY: plugin
plugin: ui/dist ## build plugin
cp -r ui/dist/app/* server/static
CGO_ENABLED=0 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${PLUGIN_CLI_NAME} ./cmd/kubectl-argo-rollouts
ui/dist:
yarn --cwd ui install
yarn --cwd ui build
.PHONY: plugin-linux
plugin-linux: ui/dist ## build plugin for linux
cp -r ui/dist/app/* server/static
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${PLUGIN_CLI_NAME}-linux-amd64 ./cmd/kubectl-argo-rollouts
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${PLUGIN_CLI_NAME}-linux-arm64 ./cmd/kubectl-argo-rollouts
.PHONY: plugin-darwin
plugin-darwin: ui/dist ## build plugin for darwin
cp -r ui/dist/app/* server/static
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${PLUGIN_CLI_NAME}-darwin-amd64 ./cmd/kubectl-argo-rollouts
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${PLUGIN_CLI_NAME}-darwin-arm64 ./cmd/kubectl-argo-rollouts
.PHONY: plugin-windows
plugin-windows: ui/dist ## build plugin for windows
cp -r ui/dist/app/* server/static
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/${PLUGIN_CLI_NAME}-windows-amd64 ./cmd/kubectl-argo-rollouts
##@ Build
.PHONY: controller
controller: ## build controller binary
CGO_ENABLED=0 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/rollouts-controller ./cmd/rollouts-controller
.PHONY: builder-image
builder-image: ## build builder image
DOCKER_BUILDKIT=1 docker build -t $(IMAGE_PREFIX)argo-rollouts-ci-builder:$(IMAGE_TAG) --target builder .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)argo-rollouts:$(IMAGE_TAG) ; fi
.PHONY: image
image:
ifeq ($(DEV_IMAGE), true)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/step-plugin-e2e-linux-amd64 ./test/cmd/step-plugin-e2e
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/rollouts-controller-linux-amd64 ./cmd/rollouts-controller
DOCKER_BUILDKIT=1 docker build --platform=$(TARGET_ARCH) -t $(IMAGE_PREFIX)argo-rollouts:$(IMAGE_TAG) -f Dockerfile.dev ${DIST_DIR}
else
DOCKER_BUILDKIT=1 docker build --platform=$(TARGET_ARCH) -t $(IMAGE_PREFIX)argo-rollouts:$(IMAGE_TAG) .
endif
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)argo-rollouts:$(IMAGE_TAG) ; fi
# Build sample plugin with debug info
# https://www.jetbrains.com/help/go/attach-to-running-go-processes-with-debugger.html
.PHONY: build-sample-metric-plugin-debug
build-sample-metric-plugin-debug: ## build sample metric plugin with debug info
go build -gcflags="all=-N -l" -o plugin-bin/metric-plugin test/cmd/metrics-plugin-sample/main.go
.PHONY: build-sample-traffic-plugin-debug
build-sample-traffic-plugin-debug: ## build sample traffic plugin with debug info
go build -gcflags="all=-N -l" -o plugin-bin/traffic-plugin test/cmd/trafficrouter-plugin-sample/main.go
.PHONY: build-sample-step-plugin-debug
build-sample-step-plugin-debug: ## build sample traffic plugin with debug info
go build -gcflags="all=-N -l" -o plugin-bin/step-plugin test/cmd/step-plugin-sample/main.go
.PHONY: plugin-image
plugin-image: ## build plugin image
DOCKER_BUILDKIT=1 docker build --platform=$(TARGET_ARCH) --target kubectl-argo-rollouts -t $(IMAGE_PREFIX)kubectl-argo-rollouts:$(IMAGE_TAG) .
if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)kubectl-argo-rollouts:$(IMAGE_TAG) ; fi
##@ Test
.PHONY: test
test: test-kustomize ## run all tests
@make test-unit
.PHONY: test-kustomize
test-kustomize: ## run kustomize tests
./test/kustomize/test.sh
setup-e2e:
@kubectl apply --context='${E2E_K8S_CONTEXT}' -f manifests/crds/rollout-crd.yaml
@kubectl apply --context='${E2E_K8S_CONTEXT}' -n argo-rollouts -f test/e2e/step-plugin/argo-rollouts-config.yaml
@rm -rf plugin-bin
@go build -gcflags="all=-N -l" -o plugin-bin/e2e-step-plugin test/cmd/step-plugin-e2e/main.go
.PHONY: start-e2e
start-e2e: ## start e2e test environment
mkdir -p coverage-output-e2e
GOCOVERDIR=coverage-output-e2e go run -cover ./cmd/rollouts-controller/main.go --instance-id ${E2E_INSTANCE_ID} --loglevel debug --kloglevel 6
.PHONY: test-e2e
test-e2e: install-devtools-local
${DIST_DIR}/gotestsum --rerun-fails-report=rerunreport.txt --junitfile=junit-e2e-test.xml --format=testname --packages="./test/e2e" --rerun-fails=5 -- -timeout 60m -count 1 --tags e2e -p ${E2E_PARALLEL} -parallel ${E2E_PARALLEL} -v --short ./test/e2e ${E2E_TEST_OPTIONS}
.PHONY: test-unit
test-unit: install-devtools-local ## run unit tests
mkdir -p coverage-output-unit
${DIST_DIR}/gotestsum --junitfile=junit-unit-test.xml --format=testname -- `go list ./... | grep -v ./test/cmd/metrics-plugin-sample` -cover -test.gocoverdir=$(CURDIR)/coverage-output-unit
.PHONY: coverage
coverage: test ## run coverage tests
go tool cover -html=coverage.out -o coverage.html
open coverage.html
.PHONY: manifests
manifests: ## generate manifests e.g. CRD, RBAC etc.
./hack/update-manifests.sh
.PHONY: clean
clean: ## clean up build artifacts
-rm -rf ${CURRENT_DIR}/dist
-rm -rf ${CURRENT_DIR}/ui/dist
.PHONY: precheckin
precheckin: test lint
##@ Docs
# convenience target to run `mkdocs serve` using a docker container
.PHONY: serve-docs
serve-docs: docs ## serve docs locally
docker run --rm -it -p 8000:8000 -v ${CURRENT_DIR}:/docs squidfunk/mkdocs-material serve -a 0.0.0.0:8000
.PHONY: docs
docs: ## build docs
go run ./hack/gen-docs/main.go
##@ Release
.PHONY: release-docs
release-docs: docs ## build and deploy docs
docker run --rm -it \
-v ~/.ssh:/root/.ssh \
-v ${CURRENT_DIR}:/docs \
-v ~/.gitconfig:/root/.gitconfig \
squidfunk/mkdocs-material gh-deploy -r ${GIT_REMOTE_REPO}
.PHONY: release-precheck
release-precheck: manifests ## precheck release
@if [ "$(GIT_TREE_STATE)" != "clean" ]; then echo 'git tree state is $(GIT_TREE_STATE)' ; exit 1; fi
@if [ -z "$(GIT_TAG)" ]; then echo 'commit must be tagged to perform release' ; exit 1; fi
@if [ "$(GIT_TAG)" != "v`cat VERSION`" ]; then echo 'VERSION does not match git tag'; exit 1; fi
.PHONY: release-plugins
release-plugins: ## build and push plugins
./hack/build-release-plugins.sh
.PHONY: release
release: release-precheck precheckin image plugin-image release-plugins
.PHONY: trivy
trivy: ## run trivy scan
@trivy fs --clear-cache
@trivy fs .
.PHONY: checksums
checksums:
shasum -a 256 ./dist/kubectl-argo-rollouts-* | awk -F './dist/' '{print $$1 $$2}' > ./dist/argo-rollouts-checksums.txt
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)