-
Notifications
You must be signed in to change notification settings - Fork 267
/
Makefile
228 lines (166 loc) · 8.2 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
223
224
225
226
227
228
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"
# Each windows version needs a separate make target because each build
# needs to happen on a separate GitHub runner
# A windows version is specified by major-minor-build-revision.
# The build number of the OS must match the build number of the container image
# The revision does not matter for windows 2019 and 2022.
# Reference: https://learn.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility
WINDOWS_2019 ?= "windows-10.0.17763.6189/amd64"
WINDOWS_2022 ?= "windows-10.0.20348.2582/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"
AMAZON_ECR_CREDENTIAL_HELPER_VERSION = 0.7.1
$(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-2019:
${MAKEFILE_PATH}/scripts/build-docker-images -p ${WINDOWS_2019} -r ${IMG} -v ${VERSION}
build-docker-images-windows-2022:
${MAKEFILE_PATH}/scripts/build-docker-images -p ${WINDOWS_2022} -r ${IMG} -v ${VERSION}
ecr-public-login:
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login
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
amazon-ecr-credential-helper:
bash ${MAKEFILE_PATH}/scripts/install-amazon-ecr-credential-helper $(AMAZON_ECR_CREDENTIAL_HELPER_VERSION)
push-docker-images-windows-2019:
${MAKEFILE_PATH}/scripts/retag-docker-images -p ${WINDOWS_2019} -v ${VERSION} -o ${IMG} -n ${ECR_REPO}
bash ${MAKEFILE_PATH}/scripts/install-amazon-ecr-credential-helper $(AMAZON_ECR_CREDENTIAL_HELPER_VERSION)
${MAKEFILE_PATH}/scripts/push-docker-images -p ${WINDOWS_2019} -r ${ECR_REPO} -v ${VERSION} -m
push-docker-images-windows-2022:
${MAKEFILE_PATH}/scripts/retag-docker-images -p ${WINDOWS_2022} -v ${VERSION} -o ${IMG} -n ${ECR_REPO}
bash ${MAKEFILE_PATH}/scripts/install-amazon-ecr-credential-helper $(AMAZON_ECR_CREDENTIAL_HELPER_VERSION)
${MAKEFILE_PATH}/scripts/push-docker-images -p ${WINDOWS_2022} -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-2019:
${MAKEFILE_PATH}/scripts/build-binaries -p ${WINDOWS_2019} -v ${VERSION}
build-binaries-windows-2022:
${MAKEFILE_PATH}/scripts/build-binaries -p ${WINDOWS_2022} -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:
powershell -File ${MAKEFILE_PATH}/scripts/upload-resources-to-github-windows.ps1 -BinariesOnly
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-2019: build-binaries-windows-2019 build-docker-images-windows-2019 push-docker-images-windows-2019
release-windows-2022: build-binaries-windows-2022 build-docker-images-windows-2022 push-docker-images-windows-2022
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