-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
113 lines (93 loc) · 3.18 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
OUT?=./bin
BINARY_NAME?=$(OUT)/naavik
WORKING_DIR=$(shell pwd)
MAIN_PATH_NAAVIK=./main.go
# Image Build Args
DOCKER_REPO?=admiralproj
IMAGE?=$(DOCKER_REPO)/naavik
DOCKERFILE?=Dockerfile.naavik
GOVERSION=1.21
ISTIO_VERSION=1.21.0
setup-dev: setup-dependencies setup-format-tools setup-swagger
# install go 1.21
# set go 1.21 as default
# validate go version. If go version is less than 1.21, exit with error
install-go:
brew install go@$(GOVERSION)
brew unlink go && brew link --overwrite go@$(GOVERSION)
@go version
@go version | grep -q "go version go$(GOVERSION)" || (echo "Go version must be $(GOVERSION). Validate PATH is set properly." && exit 1)
# validate go version. If go version is less than 1.25, exit with error
setup-dependencies:
@go version | grep -q "go version go$(GOVERSION)" || (echo "Go version must be $(GOVERSION). Run make setup-golang" && exit 1)
go mod tidy
setup-format-tools:
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint --version
go install github.com/segmentio/[email protected]
golines --version
go install github.com/onsi/ginkgo/v2/ginkgo
ginkgo version
go install github.com/boumenot/gocover-cobertura@latest
setup-swagger:
go install github.com/swaggo/swag/cmd/swag@latest
swag --version
generate-swagger:
swag fmt
swag init -g ./internal/server/swagger/docs.go -o ./internal/server/swagger
lint:
golangci-lint run --fast --fix -c .golangci.yml
lint-ci:
golangci-lint run --fast -c .golangci.yml
format:
go fmt ./...
# for f in $(find $(pwd) -name '*.go'); do golines $f -w -m 200; done
run-local:
go run $(MAIN_PATH_NAAVIK) --kube_config ~/.kube/config --log_level debug --log_color true --config_resolver=secret --state_checker=none --config_path ./config/config.yaml
test:
ginkgo run -r -v -race --coverprofile=coverage.out -skip "Traffic config processing performance test"
gocover-cobertura < coverage.out > coverage.xml
perf:
ginkgo -v -race -focus "Traffic config processing performance test" -r 2>&1 | tee perf_output.log
go run tests/perf/calc/calc_timetaken.go 2>&1 | tee -a perf_output.log
help:
go run $(MAIN_PATH_NAAVIK) --help
build-mac:
go build -o $(BINARY_NAME) -v $(MAIN_PATH_NAAVIK)
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(BINARY_NAME) -v $(MAIN_PATH_NAAVIK)
set-tag:
ifndef TAG
ifeq ($(BRANCH),master)
override TAG=latest
endif
endif
ifndef TAG
override TAG=$(SHA)
endif
docker-build: set-tag
#NOTE: Assumes binary has already been built (admiral)
docker build -t $(IMAGE):$(TAG) -f ./build/docker/$(DOCKERFILE) .
docker-publish:
ifndef DO_NOT_PUBLISH
ifndef PIPELINE_BUILD
echo "$(DOCKER_PASS)" | docker login -u ${DOCKER_USERNAME} --password-stdin --storage-driver=overlay
endif
endif
ifeq ($(TAG),)
echo "This is not a Tag/Release, skipping docker publish"
else
ifndef DO_NOT_PUBLISH
docker push $(IMAGE):$(TAG)
docker pull $(IMAGE):$(TAG)
endif
endif
#no tag set and its master branch, in this case publish `latest` tag
ifeq ($(TAG),)
ifeq ($(BRANCH),master)
docker push $(IMAGE):latest
docker pull $(IMAGE):$(TAG)
else
echo "This is not master branch, skipping to publish 'latest' tag"
endif
endif