forked from aws/aws-node-termination-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
199 lines (145 loc) · 6.77 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
VERSION = $(shell git describe --tags --always --dirty)
LATEST_RELEASE_TAG=$(shell git describe --tags --abbrev=0)
LATEST_COMMIT_HASH=$(shell git rev-parse HEAD)
LATEST_COMMIT_CHART_VERSION=$(shell git --no-pager show ${LATEST_COMMIT_HASH}:config/helm/aws-node-termination-handler/Chart.yaml | grep 'version:' | cut -d' ' -f2 | tr -d '[:space:]')
PREVIOUS_RELEASE_TAG=$(shell git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
REPO_FULL_NAME=aws/aws-node-termination-handler
ECR_REGISTRY ?= public.ecr.aws/aws-ec2
ECR_REPO ?= ${ECR_REGISTRY}/aws-node-termination-handler
ECR_REPO_CHART ?= aws-node-termination-handler
IMG ?= amazon/aws-node-termination-handler
IMG_TAG ?= ${VERSION}
IMG_W_TAG = ${IMG}:${IMG_TAG}
GOOS ?= linux
GOARCH ?= amd64
GOPROXY ?= "https://proxy.golang.org,direct"
MAKEFILE_PATH = $(dir $(realpath -s $(firstword $(MAKEFILE_LIST))))
BUILD_DIR_PATH = ${MAKEFILE_PATH}/build
BIN_DIR = ${MAKEFILE_PATH}/bin
SUPPORTED_PLATFORMS_LINUX ?= "linux/amd64,linux/arm64"
SUPPORTED_PLATFORMS_WINDOWS ?= "windows/amd64"
BINARY_NAME ?= "node-termination-handler"
THIRD_PARTY_LICENSES = "${MAKEFILE_PATH}/THIRD_PARTY_LICENSES.md"
GOLICENSES = $(BIN_DIR)/go-licenses
K8S_1_25_ASSET_SUFFIX = "_k8s-1-25-or-newer"
$(shell mkdir -p ${BUILD_DIR_PATH} && touch ${BUILD_DIR_PATH}/_go.mod)
$(GOLICENSES):
GOBIN="$(BIN_DIR)" go install github.com/google/[email protected]
compile:
@echo ${MAKEFILE_PATH}
go build -a -tags nth${GOOS} -ldflags="-s -w" -o ${BUILD_DIR_PATH}/node-termination-handler ${MAKEFILE_PATH}/cmd/node-termination-handler.go
clean:
rm -rf ${BUILD_DIR_PATH}/
fmt:
goimports -w ./ && gofmt -s -w ./
docker-build:
${MAKEFILE_PATH}/scripts/build-docker-images -p ${GOOS}/${GOARCH} -r ${IMG} -v ${VERSION}
docker-run:
docker run ${IMG_W_TAG}
build-docker-images:
${MAKEFILE_PATH}/scripts/build-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -r ${IMG} -v ${VERSION}
build-docker-images-windows:
${MAKEFILE_PATH}/scripts/build-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -r ${IMG} -v ${VERSION}
push-docker-images:
${MAKEFILE_PATH}/scripts/retag-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -v ${VERSION} -o ${IMG} -n ${ECR_REPO}
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login
${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -r ${ECR_REPO} -v ${VERSION} -m
push-docker-images-windows:
${MAKEFILE_PATH}/scripts/retag-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -v ${VERSION} -o ${IMG} -n ${ECR_REPO}
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login
${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -r ${ECR_REPO} -v ${VERSION} -m
push-helm-chart:
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/helm-login
${MAKEFILE_PATH}/scripts/push-helm-chart -r ${ECR_REPO_CHART} -v ${LATEST_COMMIT_CHART_VERSION} -h ${ECR_REGISTRY}
version:
@echo ${VERSION}
chart-version:
@echo ${LATEST_COMMIT_CHART_VERSION}
latest-release-tag:
@echo ${LATEST_RELEASE_TAG}
previous-release-tag:
@echo ${PREVIOUS_RELEASE_TAG}
repo-full-name:
@echo ${REPO_FULL_NAME}
image:
@echo ${IMG_W_TAG}
binary-name:
@echo ${BINARY_NAME}
e2e-test:
${MAKEFILE_PATH}/test/k8s-local-cluster-test/run-test -b e2e-test -d
compatibility-test:
${MAKEFILE_PATH}/test/k8s-compatibility-test/run-k8s-compatibility-test.sh -p -d
.PHONY: third-party-licenses
third-party-licenses: $(GOLICENSES)
@$(GOLICENSES) report \
--include_tests \
--template "${MAKEFILE_PATH}/templates/third-party-licenses.tmpl" \
"${MAKEFILE_PATH}/..." > "${THIRD_PARTY_LICENSES}"
.PHONY: license-test
license-test: $(GOLICENSES)
@$(GOLICENSES) check \
--allowed_licenses="Apache-2.0,BSD-2-Clause,BSD-3-Clause,BSD-4-Clause,ISC,MIT" \
--include_tests \
"${MAKEFILE_PATH}/..." \
&& echo "✅ Passed" || echo "❌ Failed"
go-linter:
golangci-lint run
helm-version-sync-test:
${MAKEFILE_PATH}/test/helm-sync-test/run-helm-version-sync-test
helm-lint:
${MAKEFILE_PATH}/test/helm/helm-lint
helm-validate-chart-versions:
${MAKEFILE_PATH}/test/helm/validate-chart-versions
build-binaries:
${MAKEFILE_PATH}/scripts/build-binaries -p ${SUPPORTED_PLATFORMS_LINUX} -v ${VERSION}
build-binaries-windows:
${MAKEFILE_PATH}/scripts/build-binaries -p ${SUPPORTED_PLATFORMS_WINDOWS} -v ${VERSION}
upload-resources-to-github:
${MAKEFILE_PATH}/scripts/upload-resources-to-github
${MAKEFILE_PATH}/scripts/upload-resources-to-github -k -s ${K8S_1_25_ASSET_SUFFIX}
upload-resources-to-github-windows:
${MAKEFILE_PATH}/scripts/upload-resources-to-github -b
generate-k8s-yaml:
${MAKEFILE_PATH}/scripts/generate-k8s-yaml
${MAKEFILE_PATH}/scripts/generate-k8s-yaml -k "1.25.0" -s ${K8S_1_25_ASSET_SUFFIX}
sync-readme-to-ecr-public:
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login
${MAKEFILE_PATH}/scripts/sync-readme-to-ecr-public
sync-catalog-information-for-helm-chart:
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/helm-login
${MAKEFILE_PATH}/scripts/sync-catalog-information-for-helm-chart
unit-test:
go test -bench=. ${MAKEFILE_PATH}/... -v -coverprofile=coverage.txt -covermode=atomic -outputdir=${BUILD_DIR_PATH}
unit-test-linux:
${MAKEFILE_PATH}/scripts/run-unit-tests-in-docker
shellcheck:
${MAKEFILE_PATH}/test/shellcheck/run-shellcheck
spellcheck:
${MAKEFILE_PATH}/test/readme-test/run-readme-spellcheck
build: compile
helm-tests: helm-version-sync-test helm-lint helm-validate-chart-versions
eks-cluster-test:
${MAKEFILE_PATH}/test/eks-cluster-test/run-test
release: build-binaries build-docker-images push-docker-images generate-k8s-yaml upload-resources-to-github
release-windows: build-binaries-windows build-docker-images-windows push-docker-images-windows upload-resources-to-github-windows
test: spellcheck shellcheck unit-test e2e-test compatibility-test license-test go-linter helm-version-sync-test helm-lint
help:
@grep -E '^[a-zA-Z_-]+:.*$$' $(MAKEFILE_LIST) | sort
## Targets intended to be run in preparation for a new release
create-local-release-tag-major:
${MAKEFILE_PATH}/scripts/create-local-tag-for-release -m
create-local-release-tag-minor:
${MAKEFILE_PATH}/scripts/create-local-tag-for-release -i
create-local-release-tag-patch:
${MAKEFILE_PATH}/scripts/create-local-tag-for-release -p
create-release-pr:
${MAKEFILE_PATH}/scripts/prepare-for-release
create-release-pr-draft:
${MAKEFILE_PATH}/scripts/prepare-for-release -d
release-prep-major: create-local-release-tag-major create-release-pr
release-prep-minor: create-local-release-tag-minor create-release-pr
release-prep-patch: create-local-release-tag-patch create-release-pr
release-prep-custom: # Run make NEW_VERSION=v1.2.3 release-prep-custom to prep for a custom release version
ifdef NEW_VERSION
$(shell echo "${MAKEFILE_PATH}/scripts/create-local-tag-for-release -v $(NEW_VERSION) && echo && make create-release-pr")
endif