-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathMakefile
182 lines (155 loc) · 7.51 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
# Copyright 2021 NetApp, Inc. All Rights Reserved
.DEFAULT_GOAL:=help
.PHONY: help deps clean build test fmt lint package asup dev fetch-asup ci
SHELL := /bin/bash
REQUIRED_GO_VERSION := 1.23
GOLANGCI_LINT_VERSION := latest
GOVULNCHECK_VERSION := latest
ifneq (, $(shell which go))
FOUND_GO_VERSION := $(shell go version | cut -d" " -f3 | cut -d"o" -f 2)
CORRECT_GO_VERSION := $(shell expr `go version | cut -d" " -f3 | cut -d"o" -f 2` \>= ${REQUIRED_GO_VERSION})
endif
RELEASE ?= 1
VERSION ?= $(shell expr `date +%Y.%m.%d | cut -c 3-`)
COMMIT := $(shell git rev-parse --short HEAD)
BUILD_DATE := `date +%FT%T%z`
LD_FLAGS := "-X 'github.com/netapp/harvest/v2/cmd/harvest/version.VERSION=$(VERSION)' -X 'github.com/netapp/harvest/v2/cmd/harvest/version.Release=$(RELEASE)' -X 'github.com/netapp/harvest/v2/cmd/harvest/version.Commit=$(COMMIT)' -X 'github.com/netapp/harvest/v2/cmd/harvest/version.BuildDate=$(BUILD_DATE)'"
GOARCH ?= amd64
GOOS ?= linux
CGO_ENABLED ?= 0
HARVEST_PACKAGE := harvest-${VERSION}-${RELEASE}_${GOOS}_${GOARCH}
DIST := dist
TMP := /tmp/${HARVEST_PACKAGE}
ASUP_TMP := /tmp/asup
ASUP_MAKE_TARGET ?= build #one of build/production
GIT_TOKEN ?=
CURRENT_DIR = $(shell pwd)
ASUP_BIN = asup
ASUP_BIN_VERSION ?= main #change it to match tag of release branch
BIN_PLATFORM ?= linux
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
MKDOCS_EXISTS := $(shell which mkdocs)
FETCH_ASUP_EXISTS := $(shell which ./.github/fetch-asup)
HARVEST_ENV := .harvest.env
# Read the environment file if it exists and export the uncommented variables
ifneq (,$(wildcard $(HARVEST_ENV)))
include $(HARVEST_ENV)
export $(shell sed '/^\#/d; s/=.*//' $(HARVEST_ENV))
endif
# FIPS flag
FIPS ?= 0
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-11s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
header:
@echo " _ _ _ ___ __ "
@echo " | || |__ _ _ ___ _____ __| |_ |_ ) / \ "
@echo " | __ / _\` | '_\ V / -_|_-< _| / / | () | "
@echo " |_||_\__,_|_| \_/\___/__/\__| /___(_)__/ "
deps: header ## Check dependencies
@# Make sure that go exists
ifeq (${FOUND_GO_VERSION}, )
$(error Harvest requires that Go is installed and at least version: ${REQUIRED_GO_VERSION})
endif
@# Check to make sure that GO is the correct version
ifeq ("${CORRECT_GO_VERSION}", "0")
$(error Required Go version is ${REQUIRED_GO_VERSION}, but found ${FOUND_GO_VERSION})
endif
clean: ## Cleanup the project binary (bin) folders
@echo "Cleaning Harvest files"
@if [ -d bin ]; then \
find ./bin -type f -not -name "*asup*" -exec rm -f {} +; \
fi
test: ## Run tests
@echo "Testing"
@# The ldflags force the old Apple linker to suppress ld warning messages on MacOS
@# See https://github.com/golang/go/issues/61229#issuecomment-1988965927
@go test -ldflags=-extldflags=-Wl,-ld_classic -race -shuffle=on ./...
fmt: ## Format the go source files
@echo "Formatting"
@go fmt ./...
lint: ## Run golangci-lint on the source files
@echo "Linting"
@go run github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION} run ./...
@cd integration && go mod tidy && go run github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION} run ./...
govulncheck: ## Run govulncheck on the source files
@echo "Govulnchecking"
@go run golang.org/x/vuln/cmd/govulncheck@${GOVULNCHECK_VERSION} ./...
@cd integration && go mod tidy && go run golang.org/x/vuln/cmd/govulncheck@${GOVULNCHECK_VERSION} ./...
mkdocs:
ifeq (${MKDOCS_EXISTS}, )
$(error mkdocs task requires that you have https://squidfunk.github.io/mkdocs-material/getting-started/ installed.)
endif
mkdocs serve
build: clean deps fmt harvest fetch-asup ## Build the project
package: clean deps build test dist-tar ## Package Harvest binary
all: package ## Build, Test, Package
harvest: deps
@mkdir -p bin
@# Build the harvest and poller cli
ifeq ($(FIPS), 1)
@echo "Building with BoringCrypto (FIPS compliance)"
GOEXPERIMENT=boringcrypto GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -trimpath -tags boringcrypto -o bin -ldflags=$(LD_FLAGS) ./cmd/harvest ./cmd/poller
else
@echo "Building"
@GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) go build -trimpath -o bin -ldflags=$(LD_FLAGS) ./cmd/harvest ./cmd/poller
endif
@cp service/contrib/grafana bin; chmod +x bin/grafana
###############################################################################
# Build tar gz distribution
###############################################################################
dist-tar:
@echo "Building tar"
@rm -rf ${TMP}
@rm -rf ${DIST}
@mkdir ${TMP}
@mkdir ${DIST}
@cp -r bin conf container grafana service cert autosupport README.md LICENSE prom-stack.tmpl ${TMP}
@cp harvest.yml ${TMP}/harvest.yml
@tar --directory /tmp --create --gzip --file ${DIST}/${HARVEST_PACKAGE}.tar.gz ${HARVEST_PACKAGE}
@rm -rf ${TMP}
@echo "tar artifact @" ${DIST}/${HARVEST_PACKAGE}.tar.gz
asup:
@echo "Building AutoSupport"
@rm -rf autosupport/asup
@rm -rf ${ASUP_TMP}
@mkdir ${ASUP_TMP}
# check if there is an equivalent branch name to harvest. If branch name is not found then take autosupport code from main branch.
@if [[ $(shell git ls-remote --heads https://${GIT_TOKEN}@github.com/NetApp/harvest-private.git ${BRANCH} | wc -l | xargs) == 0 ]]; then\
git clone -b main https://${GIT_TOKEN}@github.com/NetApp/harvest-private.git ${ASUP_TMP};\
else\
git clone -b ${BRANCH} https://${GIT_TOKEN}@github.com/NetApp/harvest-private.git ${ASUP_TMP};\
fi
@cd ${ASUP_TMP}/harvest-asup && make ${ASUP_MAKE_TARGET} VERSION=${VERSION} RELEASE=${RELEASE} FIPS=${FIPS}
@mkdir -p ${CURRENT_DIR}/autosupport
@cp ${ASUP_TMP}/harvest-asup/bin/asup ${CURRENT_DIR}/autosupport
dev: build lint govulncheck
@echo "Deleting AutoSupport binary"
@rm -rf autosupport/asup
fetch-asup:
ifneq (${FETCH_ASUP_EXISTS}, )
@./.github/fetch-asup ${ASUP_BIN} ${ASUP_BIN_VERSION} ${BIN_PLATFORM} 2>/dev/null #Suppress Error in case of internet connectivity
endif
docs: mkdocs ## Serve docs for local dev
license-check:
@echo "Licence checking"
@go run github.com/frapposelli/wwhrd@latest check -q -t
@cd integration && go mod tidy && go run github.com/frapposelli/wwhrd@latest check -q -t -f ../.wwhrd.yml
ci: clean deps fmt harvest lint test govulncheck license-check
ci-local: ## Run CI locally
ifeq ($(origin ci),undefined)
@echo ci-local requires a path to the CI harvest.yml like so:
@echo make ci=/path/to/harvest.yml ci-local
@exit 1
endif
-@docker stop $$(docker ps -a --format '{{.ID}} {{.Names}}' | grep -E 'grafana|prometheus|poller') 2>/dev/null || true
-@docker rm $$(docker ps -a --format '{{.ID}} {{.Names}}' | grep -E 'grafana|prometheus|poller') 2>/dev/null || true
-@docker volume rm harvest_grafana_data harvest_prometheus_data 2>/dev/null || true
@if [ "$(ci)" != "harvest.yml" ]; then cp $(ci) harvest.yml; else echo "Source and destination files are the same, skipping copy"; fi
@./bin/harvest generate docker full --port --output harvest-compose.yml
@docker build -f container/onePollerPerContainer/Dockerfile -t ghcr.io/netapp/harvest:latest . --no-cache --build-arg GO_VERSION=${GO_VERSION} --build-arg VERSION=${VERSION}
@docker compose -f prom-stack.yml -f harvest-compose.yml up -d --remove-orphans
@cp harvest.yml integration/test/
VERSION=${VERSION} INSTALL_DOCKER=1 ./integration/test/test.sh
VERSION=${VERSION} REGRESSION=1 ./integration/test/test.sh
VERSION=${VERSION} ANALYZE_DOCKER_LOGS=1 ./integration/test/test.sh
VERSION=${VERSION} CHECK_METRICS=1 ./integration/test/test.sh