-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathMakefile
222 lines (181 loc) · 6.97 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
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0
REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
VERSION := $(shell cat VERSION)
REGISTRY ?= europe-docker.pkg.dev/gardener-project/snapshots/gardener
FLUENT_BIT_TO_VALI_IMAGE_REPOSITORY := $(REGISTRY)/fluent-bit-to-vali
FLUENT_BIT_VALI_IMAGE_REPOSITORY := $(REGISTRY)/fluent-bit-vali
VALI_CURATOR_IMAGE_REPOSITORY := $(REGISTRY)/vali-curator
TELEGRAF_IMAGE_REPOSITORY := $(REGISTRY)/telegraf-iptables
TUNE2FS_IMAGE_REPOSITORY := $(REGISTRY)/tune2fs
EVENT_LOGGER_IMAGE_REPOSITORY := $(REGISTRY)/event-logger
IMAGE_TAG := $(VERSION)
EFFECTIVE_VERSION := $(VERSION)-$(shell git rev-parse --short HEAD)
SRC_DIRS := $(shell go list -f '{{.Dir}}' $(REPO_ROOT)/...)
LD_FLAGS := $(shell $(REPO_ROOT)/hack/get-build-ld-flags.sh)
BUILD_PLATFORM ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
BUILD_ARCH ?= $(shell uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
# project folder structure
PKG_DIR := $(REPO_ROOT)/pkg
TOOLS_DIR := $(REPO_ROOT)/tools
include hack/tools.mk
export PATH := $(abspath $(TOOLS_DIR)):$(PATH)
.DEFAULT_GOAL := all
all: verify
#################################################################
# Rules related to binary build, Docker image build and release #
#################################################################
.PHONY: plugin
plugin: tidy
@echo "building $@ for $(BUILD_PLATFORM)/$(BUILD_ARCH)"
@GOOS=$(BUILD_PLATFORM) \
GOARCH=$(BUILD_ARCH) \
go build -buildmode=c-shared \
-o $(REPO_ROOT)/build/out_vali.so \
-ldflags="$(LD_FLAGS)" \
./cmd/fluent-bit-vali-plugin
.PHONY: curator
curator: tidy
@echo "building $@ for $(BUILD_PLATFORM)/$(BUILD_ARCH)"
@GOOS=$(BUILD_PLATFORM) \
GOARCH=$(BUILD_ARCH) \
CGO_ENABLED=0 \
GO111MODULE=on \
go build \
-o $(REPO_ROOT)/build/curator \
-ldflags="$(LD_FLAGS)" \
./cmd/vali-curator
.PHONY: event-logger
event-logger: tidy
@echo "building $@ for $(BUILD_PLATFORM)/$(BUILD_ARCH)"
@GOOS=$(BUILD_PLATFORM) \
GOARCH=$(BUILD_ARCH) \
CGO_ENABLED=0 GO111MODULE=on \
go build \
-o $(REPO_ROOT)/build/event-logger \
-ldflags="$(LD_FLAGS)" \
$(REPO_ROOT)/cmd/event-logger
.PHONY: install
install: install-vali-curator install-event-logger
.PHONY: install-vali-curator
install-vali-curator:
@echo "building $@ for $(BUILD_PLATFORM)/$(BUILD_ARCH)"
@GOOS=$(BUILD_PLATFORM) \
GOARCH=$(BUILD_ARCH) \
EFFECTIVE_VERSION=$(EFFECTIVE_VERSION) \
./hack/install.sh \
./cmd/vali-curator
.PHONY: install-event-logger
install-event-logger:
@echo "building $@ for $(BUILD_PLATFORM)/$(BUILD_ARCH)"
@GOOS=$(BUILD_PLATFORM) \
GOARCH=$(BUILD_ARCH) \
EFFECTIVE_VERSION=$(EFFECTIVE_VERSION) \
./hack/install.sh \
./cmd/event-logger
.PHONY: install-copy
install-copy:
@echo "building $@ for $(BUILD_PLATFORM)/$(BUILD_ARCH)"
@GOOS=$(BUILD_PLATFORM) \
GOARCH=$(BUILD_ARCH) \
EFFECTIVE_VERSION=$(EFFECTIVE_VERSION) \
./hack/install.sh \
./cmd/copy
.PHONY: docker-images
docker-images:
@BUILD_ARCH=$(BUILD_ARCH) \
$(REPO_ROOT)/hack/docker-image-build.sh "fluent-bit-plugin" \
$(FLUENT_BIT_TO_VALI_IMAGE_REPOSITORY) $(IMAGE_TAG)
@BUILD_ARCH=$(BUILD_ARCH) \
$(REPO_ROOT)/hack/docker-image-build.sh "fluent-bit-vali" \
$(FLUENT_BIT_VALI_IMAGE_REPOSITORY) $(IMAGE_TAG)
@BUILD_ARCH=$(BUILD_ARCH) \
$(REPO_ROOT)/hack/docker-image-build.sh "curator" \
$(VALI_CURATOR_IMAGE_REPOSITORY) $(IMAGE_TAG)
@BUILD_ARCH=$(BUILD_ARCH) \
$(REPO_ROOT)/hack/docker-image-build.sh "telegraf" \
$(TELEGRAF_IMAGE_REPOSITORY) $(IMAGE_TAG)
@BUILD_ARCH=$(BUILD_ARCH) \
$(REPO_ROOT)/hack/docker-image-build.sh "event-logger" \
$(EVENT_LOGGER_IMAGE_REPOSITORY) $(IMAGE_TAG) $(EFFECTIVE_VERSION)
@BUILD_ARCH=$(BUILD_ARCH) \
$(REPO_ROOT)/hack/docker-image-build.sh "tune2fs" \
$(TUNE2FS_IMAGE_REPOSITORY) $(IMAGE_TAG)
.PHONY: docker-push
docker-push:
@$(REPO_ROOT)/hack/docker-image-push.sh "fluent-bit-plugin" \
$(FLUENT_BIT_TO_VALI_IMAGE_REPOSITORY) $(IMAGE_TAG)
@$(REPO_ROOT)/hack/docker-image-push.sh "curator" \
$(VALI_CURATOR_IMAGE_REPOSITORY) $(IMAGE_TAG)
@$(REPO_ROOT)/hack/docker-image-push.sh "telegraf" \
$(TELEGRAF_IMAGE_REPOSITORY) $(IMAGE_TAG)
@$(REPO_ROOT)/hack/docker-image-push.sh "event-logger" \
$(EVENT_LOGGER_IMAGE_REPOSITORY) $(IMAGE_TAG) $(EFFECTIVE_VERSION)
@$(REPO_ROOT)/hack/docker-image-push.sh "tune2fs" \
$(TUNE2FS_IMAGE_REPOSITORY) $(IMAGE_TAG)
#####################################################################
# Rules for verification, formatting, linting, testing and cleaning #
#####################################################################
.PHONY: tidy
tidy:
@go mod tidy
@go mod download
.PHONY: sast
sast: $(GOSEC)
@$(REPO_ROOT)/hack/sast.sh
.PHONY: sast-report
sast-report: $(GOSEC)
@$(REPO_ROOT)/hack/sast.sh --gosec-report true
.PHONY: check
check: format sast-report $(GO_LINT)
@$(GO_LINT) run --config=$(REPO_ROOT)/.golangci.yaml --timeout 10m $(REPO_ROOT)/cmd/... $(REPO_ROOT)/pkg/... $(REPO_ROOT)/tests/...
@go vet $(REPO_ROOT)/cmd/... $(REPO_ROOT)/pkg/... $(REPO_ROOT)/tests/...
.PHONY: format
format:
@gofmt -l -w $(REPO_ROOT)/cmd $(REPO_ROOT)/pkg $(REPO_ROOT)/tests
.PHONY: goimports
goimports: goimports_tool goimports-reviser_tool
.PHONY: goimports_tool
goimports_tool: $(GOIMPORTS)
@for dir in $(SRC_DIRS); do \
$(GOIMPORTS) -w $$dir/; \
done
.PHONY: goimports-reviser_tool
goimports-reviser_tool: $(GOIMPORTS_REVISER)
@for dir in $(SRC_DIRS); do \
GOIMPORTS_REVISER_OPTIONS="-imports-order std,project,general,company" \
$(GOIMPORTS_REVISER) -recursive $$dir/; \
done
.PHONY: add-license-headers
add-license-headers: $(GO_ADD_LICENSE)
@$(REPO_ROOT)/hack/add-license-header.sh
.PHONY: test
test: $(GINKGO)
@go test $(REPO_ROOT)/pkg/... --v --ginkgo.v --ginkgo.no-color
@go test $(REPO_ROOT)/tests/vali_plugin
.PHONY: verify
verify: check test
.PHONY: clean
clean:
@rm -rf $(REPO_ROOT)/build
.PHONY: e2e-tests
e2e-tests: $(KIND)
@go test -v $(REPO_ROOT)/tests/...
#########################################
# Tools #
#########################################
.PHONY: kind-up
kind-up: $(KIND) $(KUBECTL)
@$(REPO_ROOT)/hack/kind-up.sh
#########################################
# skaffold pipeline scenarios #
#########################################
skaffold-%: export KUBECONFIG = $(REPO_ROOT)/example/kind/kubeconfig
.PHONY: skaffold-run
skaffold-run: $(SKAFFOLD)
@$(SKAFFOLD) run --kubeconfig=$(KUBECONFIG)
# skaffold-dev target requires that skaffold run has been run
.PHONY: skaffold-dev
skaffold-dev: $(SKAFFOLD)
@$(SKAFFOLD) dev --kubeconfig=$(KUBECONFIG)