forked from awslabs/amazon-eks-ami
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
143 lines (114 loc) · 5.25 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
PACKER_BINARY ?= packer
AVAILABLE_PACKER_VARIABLES := $(shell $(PACKER_BINARY) inspect -machine-readable eks-worker-al2.json | grep 'template-variable' | awk -F ',' '{print $$4}')
K8S_VERSION_PARTS := $(subst ., ,$(kubernetes_version))
K8S_VERSION_MINOR := $(word 1,${K8S_VERSION_PARTS}).$(word 2,${K8S_VERSION_PARTS})
MAKEFILE_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# expands to 'true' if PACKER_VARIABLE_FILE is non-empty
# and the file contains the string passed as the first argument
# otherwise, expands to 'false'
packer_variable_file_contains = $(if $(PACKER_VARIABLE_FILE),$(shell grep -Fq $1 $(PACKER_VARIABLE_FILE) && echo true || echo false),false)
# expands to 'true' if the version comparison is affirmative
# otherwise expands to 'false'
vercmp = $(shell $(MAKEFILE_DIR)/files/bin/vercmp "$1" "$2" "$3")
# expands to 'true' if the 'aws_region' contains 'us-iso' (an isolated region)
# otherwise, expands to 'false'
in_iso_region = $(if $(findstring us-iso,$(aws_region)),true,false)
# gp3 volumes are used by default for 1.27+
# TODO: remove when 1.26 reaches EOL
# TODO: remove when gp3 is supported in isolated regions
ifneq ($(call packer_variable_file_contains,volume_type), true)
ifeq ($(call in_iso_region), true)
volume_type ?= gp2
else ifeq ($(call vercmp,$(kubernetes_version),lt,1.27.0), true)
volume_type ?= gp2
endif
endif
# Docker is not present on 1.25+ AMI's
# TODO: remove this when 1.24 reaches EOL
ifeq ($(call vercmp,$(kubernetes_version),gteq,1.25.0), true)
# do not tag the AMI with the Docker version
docker_version ?= none
# do not include the Docker version in the AMI description
ami_component_description ?= (k8s: {{ user `kubernetes_version` }}, containerd: {{ user `containerd_version` }})
endif
arch ?= x86_64
ifeq ($(arch), arm64)
instance_type ?= m6g.large
ami_name ?= amazon-eks-arm64-node-$(K8S_VERSION_MINOR)-v$(shell date +'%Y%m%d')
else
instance_type ?= m4.large
ami_name ?= amazon-eks-node-$(K8S_VERSION_MINOR)-v$(shell date +'%Y%m%d')
endif
ifeq ($(aws_region), cn-northwest-1)
source_ami_owners ?= 141808717104
endif
ifeq ($(aws_region), us-gov-west-1)
source_ami_owners ?= 045324592363
endif
T_RED := \e[0;31m
T_GREEN := \e[0;32m
T_YELLOW := \e[0;33m
T_RESET := \e[0m
.PHONY: latest
latest: 1.26 ## Build EKS Optimized AL2 AMI with the latest supported version of Kubernetes
# ensure that these flags are equivalent to the rules in the .editorconfig
SHFMT_FLAGS := --list \
--language-dialect auto \
--indent 2 \
--binary-next-line \
--case-indent \
--space-redirects
SHFMT_COMMAND := $(shell which shfmt)
ifeq (, $(SHFMT_COMMAND))
SHFMT_COMMAND = docker run --rm -v $(MAKEFILE_DIR):$(MAKEFILE_DIR) mvdan/shfmt
endif
.PHONY: fmt
fmt: ## Format the source files
$(SHFMT_COMMAND) $(SHFMT_FLAGS) --write $(MAKEFILE_DIR)
SHELLCHECK_COMMAND := $(shell which shellcheck)
ifeq (, $(SHELLCHECK_COMMAND))
SHELLCHECK_COMMAND = docker run --rm -v $(MAKEFILE_DIR):$(MAKEFILE_DIR) koalaman/shellcheck:stable
endif
SHELL_FILES := $(shell find $(MAKEFILE_DIR) -type f -name '*.sh')
.PHONY: lint
lint: ## Check the source files for syntax and format issues
$(SHFMT_COMMAND) $(SHFMT_FLAGS) --diff $(MAKEFILE_DIR)
$(SHELLCHECK_COMMAND) --format gcc --severity error $(SHELL_FILES)
.PHONY: test
test: ## run the test-harness
test/test-harness.sh
# include only variables which have a defined value
PACKER_VARIABLES := $(foreach packerVar,$(AVAILABLE_PACKER_VARIABLES),$(if $($(packerVar)),$(packerVar)))
PACKER_VAR_FLAGS := -var-file eks-worker-al2-variables.json \
$(if $(PACKER_VARIABLE_FILE),--var-file=$(PACKER_VARIABLE_FILE),) \
$(foreach packerVar,$(PACKER_VARIABLES),-var $(packerVar)='$($(packerVar))')
.PHONY: validate
validate: ## Validate packer config
$(PACKER_BINARY) validate $(PACKER_VAR_FLAGS) eks-worker-al2.json
.PHONY: k8s
k8s: validate ## Build default K8s version of EKS Optimized AL2 AMI
@echo "$(T_GREEN)Building AMI for version $(T_YELLOW)$(kubernetes_version)$(T_GREEN) on $(T_YELLOW)$(arch)$(T_RESET)"
$(PACKER_BINARY) build -timestamp-ui -color=false $(PACKER_VAR_FLAGS) eks-worker-al2.json
# Build dates and versions taken from https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html
.PHONY: 1.22
1.22: ## Build EKS Optimized AL2 AMI - K8s 1.22
$(MAKE) k8s kubernetes_version=1.22.17 kubernetes_build_date=2023-03-17 pull_cni_from_github=true
.PHONY: 1.23
1.23: ## Build EKS Optimized AL2 AMI - K8s 1.23
$(MAKE) k8s kubernetes_version=1.23.17 kubernetes_build_date=2023-03-17 pull_cni_from_github=true
.PHONY: 1.24
1.24: ## Build EKS Optimized AL2 AMI - K8s 1.24
$(MAKE) k8s kubernetes_version=1.24.11 kubernetes_build_date=2023-03-17 pull_cni_from_github=true
.PHONY: 1.25
1.25: ## Build EKS Optimized AL2 AMI - K8s 1.25
$(MAKE) k8s kubernetes_version=1.25.7 kubernetes_build_date=2023-03-17 pull_cni_from_github=true
.PHONY: 1.26
1.26: ## Build EKS Optimized AL2 AMI - K8s 1.26
$(MAKE) k8s kubernetes_version=1.26.2 kubernetes_build_date=2023-03-17 pull_cni_from_github=true
.PHONY: clean
clean:
rm *-manifest.json
rm *-version-info.json
.PHONY: help
help: ## Display help
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[\.a-zA-Z_0-9\-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)