-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
115 lines (87 loc) · 3.63 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
# SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0
NAME := kube-rbac-proxy-watcher
REGISTRY ?= europe-docker.pkg.dev/gardener-project/snapshots/gardener/extensions
IMAGE_REPOSITORY := $(REGISTRY)/kube-rbac-proxy-watcher
REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BIN := $(REPO_ROOT)/bin
VERSION := $(shell cat "$(REPO_ROOT)/VERSION")
EFFECTIVE_VERSION := $(VERSION)-$(shell git rev-parse 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/')
IMAGE_TAG := $(VERSION)
PKG_DIR := $(REPO_ROOT)/pkg
TOOLS_DIR := $(REPO_ROOT)/tools
ifneq ($(strip $(shell git status --porcelain 2>/dev/null)),)
EFFECTIVE_VERSION := $(EFFECTIVE_VERSION)-dirty
endif
.DEFAULT_GOAL := all
all: watcher
#########################################
# Tools #
#########################################
include $(REPO_ROOT)/hack/tools.mk
export PATH := $(abspath $(TOOLS_DIR)):$(PATH)
#################################################################
# Rules related to binary build, Docker image build and release #
#################################################################
docker-images:
@BUILD_ARCH=$(BUILD_ARCH) \
$(REPO_ROOT)/hack/docker-image-build.sh "watcher" \
$(IMAGE_REPOSITORY) $(IMAGE_TAG)
docker-push:
@$(REPO_ROOT)/hack/docker-image-push.sh "watcher" \
$(IMAGE_REPOSITORY) $(IMAGE_TAG)
#####################################################################
# Rules for verification, formatting, linting, testing and cleaning #
#####################################################################
tidy:
@go mod tidy
@go mod download
watcher:
@echo "building $@ for $(BUILD_PLATFORM)/$(BUILD_ARCH)"
@go mod tidy
@go mod download
@GOOS=$(BUILD_PLATFORM) \
GOARCH=$(BUILD_ARCH) \
CGO_ENABLED=0 \
GO111MODULE=on \
go build \
-o $(REPO_ROOT)/build/watcher \
-ldflags="$(LD_FLAGS)" \
$(REPO_ROOT)/cmd/watcher
verify: check test sast
verify-extended: check test-cov sast-report
clean: test-clean
@rm -f $(REPO_ROOT)/build/watcher
check: format $(GO_LINT)
@$(GO_LINT) run --config=$(REPO_ROOT)/.golangci.yaml --timeout 10m $(REPO_ROOT)/cmd/... $(REPO_ROOT)/pkg/...
@go vet $(REPO_ROOT)/cmd/... $(REPO_ROOT)/pkg/...
format:
@gofmt -l -w $(REPO_ROOT)/cmd $(REPO_ROOT)/pkg
goimports: goimports_tool goimports-reviser_tool
goimports_tool: $(GOIMPORTS)
@for dir in $(SRC_DIRS); do \
$(GOIMPORTS) -w $$dir/; \
done
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
test:
@go test $(REPO_ROOT)/cmd/parameters/... $(REPO_ROOT)/pkg/...
test-cov:
@$(REPO_ROOT)/hack/test-cover.sh ./cmd/... ./pkg/...
test-clean:
@rm -f $(REPO_ROOT)/test.*
add-license-headers: $(GO_ADD_LICENSE)
@./hack/add-license-header.sh
sast: tidy $(GOSEC)
@$(REPO_ROOT)/hack/sast.sh
sast-report: tidy $(GOSEC)
@$(REPO_ROOT)/hack/sast.sh --gosec-report true
.PHONY: docker-images docker-push watcher verify verify-extended clean check format goimports goimports_tool goimports-reviser_tool test test-cov test-clean add-license-headers sast sast-report