-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMakefile
More file actions
168 lines (138 loc) · 5.56 KB
/
Makefile
File metadata and controls
168 lines (138 loc) · 5.56 KB
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
# 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_PLUGIN_IMAGE_REPOSITORY := $(REGISTRY)/fluent-bit-plugin
FLUENT_BIT_OUTPUT_IMAGE_REPOSITORY := $(REGISTRY)/fluent-bit-output
TUNE2FS_IMAGE_REPOSITORY := $(REGISTRY)/tune2fs
EVENT_LOGGER_IMAGE_REPOSITORY := $(REGISTRY)/event-logger
EFFECTIVE_VERSION := $(VERSION)-$(shell git rev-parse --short HEAD)
SRC_DIRS := $(shell go list -f '{{.Dir}}' $(REPO_ROOT)/...)
LD_FLAGS := -s -w $(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/')
GCI_OPT ?= -s standard -s default -s "prefix($(shell go list -m))" --skip-generated
ifneq ($(strip $(shell git status --porcelain 2>/dev/null)),)
EFFECTIVE_VERSION := $(EFFECTIVE_VERSION)-dirty
endif
IMAGE_TAG := $(EFFECTIVE_VERSION)
# project folder structure
TOOLS_DIR := $(REPO_ROOT)/tools
TOOLS_MODFILE := $(TOOLS_DIR)/go.mod
export PATH := $(abspath $(TOOLS_DIR)):$(PATH)
.DEFAULT_GOAL := all
all: tidy fmt gci plugin event-logger lint
#################################################################
# Build targets #
#################################################################
.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/output_plugin.so \
-ldflags="$(LD_FLAGS)" \
./cmd/fluent-bit-output-plugin
.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: copy
copy: 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/copy \
-ldflags="$(LD_FLAGS)" \
$(REPO_ROOT)/cmd/copy
#################################################################
# Container images build targets #
#################################################################
.PHONY: docker-images
docker-images:
@BUILD_ARCH=$(BUILD_ARCH) \
$(REPO_ROOT)/hack/docker-image-build.sh "fluent-bit-plugin" \
$(FLUENT_BIT_PLUGIN_IMAGE_REPOSITORY) $(IMAGE_TAG)
@BUILD_ARCH=$(BUILD_ARCH) \
$(REPO_ROOT)/hack/docker-image-build.sh "fluent-bit-output" \
$(FLUENT_BIT_OUTPUT_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_PLUGIN_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)
#################################################################
# Code check targets #
#################################################################
.PHONY: tidy
tidy:
@go mod tidy
@cd $(TOOLS_DIR) && go mod tidy
.PHONY: check
check: tidy fmt gci
.PHONY: fmt
fmt: tidy
@echo "Running fmt..."
@go tool -modfile=$(TOOLS_MODFILE) golangci-lint fmt \
--config=$(REPO_ROOT)/.golangci.yaml \
$(SRC_DIRS)
.PHONY: gci
gci: tidy
@echo "Running gci..."
@go tool -modfile=$(TOOLS_MODFILE) gci write $(GCI_OPT) $(SRC_DIRS)
.PHONY: lint
lint: tidy
@echo "Running lint..."
@go tool -modfile=$(TOOLS_MODFILE) golangci-lint run \
--config=$(REPO_ROOT)/.golangci.yaml \
$(SRC_DIRS)
.PHONY: test
test: tidy
@go tool -modfile=$(TOOLS_MODFILE) gotestsum $(REPO_ROOT)/pkg/... --v --ginkgo.v --ginkgo.no-color
@go tool -modfile=$(TOOLS_MODFILE) gotestsum $(REPO_ROOT)/tests/plugin
.PHONY: e2e-tests
e2e-tests: tidy
@KIND_PATH=$(shell go tool -modfile=$(TOOLS_MODFILE) -n kind) go tool -modfile=$(TOOLS_MODFILE) gotestsum $(REPO_ROOT)/tests/e2e
.PHONY: check-go-fix
check-go-fix: tidy
@echo "Running go fix..."
@go fix $(SRC_DIRS)/...
@if [ -n "$$(git status --porcelain $(SRC_DIRS))" ]; then \
echo "Error: go fix produced changes. Please run 'go fix ./...' and commit the changes."; \
git --no-pager diff; \
exit 1; \
fi
.PHONY: verify
verify: check check-go-fix test
.PHONY: sast
sast:
@$(REPO_ROOT)/hack/sast.sh
.PHONY: sast-report
sast-report:
@$(REPO_ROOT)/hack/sast.sh --gosec-report true
.PHONY: add-license-headers
add-license-headers: tidy
@$(REPO_ROOT)/hack/add-license-header.sh
.PHONY: clean
clean:
@rm -rf $(REPO_ROOT)/build