forked from aws-samples/amazon-eks-refarch-cloudformation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
186 lines (163 loc) · 9.62 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
SECRETS_FILE ?= secrets.mk
ifeq ($(shell test -e $(SECRETS_FILE) && echo -n yes),yes)
include $(SECRETS_FILE)
endif
CUSTOM_FILE ?= custom.mk
ifeq ($(shell test -e $(CUSTOM_FILE) && echo -n yes),yes)
include $(CUSTOM_FILE)
endif
ifeq ($(UPDATE_AMI),1)
ForceUpdateAMI ?= $(shell date +%s)
else
ForceUpdateAMI ?= placeholder
endif
ROOT ?= $(shell pwd)
AWS_ACCOUNT_ID := $(shell aws sts get-caller-identity --query 'Account' --output text)
YAML_BRANCH ?= stable
EKS_YAML_URL ?= https://s3-us-west-2.amazonaws.com/pahud-cfn-us-west-2/eks-templates/cloudformation/eks-$(YAML_BRANCH).yaml
# CLUSTER_YAML ?= https://s3-us-west-2.amazonaws.com/pahud-cfn-us-west-2/eks-templates/cloudformation/cluster.yaml
CLUSTER_STACK_NAME ?= eksdemo
CLUSTER_NAME ?= $(CLUSTER_STACK_NAME)
EKS_ADMIN_ROLE ?= arn:aws:iam::903779448426:role/AmazonEKSAdminRole
REGION ?= ap-northeast-1
SSH_KEY_NAME ?= 'aws-pahud'
VPC_ID ?= vpc-e549a281
SUBNET1 ?= subnet-05b643f57a6997deb
SUBNET2 ?= subnet-09e79eb1dec82b7e2
SUBNET3 ?= subnet-0c365d97cbc75ceec
OnDemandBaseCapacity ?= 1
NodeAutoScalingGroupMinSize ?= 0
NodeAutoScalingGroupDesiredSize ?= 4
NodeAutoScalingGroupMaxSize ?= 5
NodeVolumeSize ?= 20
ASGAutoAssignPublicIp ?= yes
ClusterVersion ?= latest
InstanceTypesOverride ?= 't3.medium,t3.large,t3.xlarge'
EnableNodeDrainer ?= no
.PHONY: sam-dev-package
sam-dev-package:
@docker run -ti \
-v $(PWD):/home/samcli/workdir \
-v $(HOME)/.aws:/home/samcli/.aws \
-w /home/samcli/workdir \
-e AWS_DEFAULT_REGION=$(REGION) \
pahud/aws-sam-cli:latest sam package --template-file ./cloudformation/configmap-sar.yaml --s3-bucket $(S3BUCKET) --output-template-file ./cloudformation/configmap-sar-packaged.yaml
.PHONY: all
all: deploy
.PHONY: sync
sync: deploy
.PHONY: update-ami
update-ami:
@aws s3 cp files/eks-latest-ami.yaml s3://pahud-eks-templates/eks-latest-ami.yaml --acl public-read
.PHONY: update-yaml
update-stable-yaml:
@aws --region us-west-2 s3 cp cloudformation/eks.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/eks-stable.yaml --acl public-read
# @aws --region us-west-2 s3 cp cloudformation/ami.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/ami-stable.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/cluster.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/cluster-stable.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/nodegroup.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/nodegroup-stable.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/configmap.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/configmap-stable.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/configmap-sar.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/configmap-sar-stable.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/eks-lambda-drainer.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/eks-lambda-drainer-stable.yaml --acl public-read
@echo https://s3-us-west-2.amazonaws.com/pahud-cfn-us-west-2/eks-templates/cloudformation/eks-stable.yaml
.PHONY: update-dev-yaml
update-dev-yaml:
@aws --region us-west-2 s3 cp cloudformation/eks.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/eks-dev.yaml --acl public-read
# @aws --region us-west-2 s3 cp cloudformation/ami.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/ami-dev.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/cluster.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/cluster-dev.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/nodegroup.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/nodegroup-dev.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/configmap.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/configmap-dev.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/configmap-sar.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/configmap-sar-dev.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/eks-lambda-drainer.yaml s3://pahud-cfn-us-west-2/eks-templates/cloudformation/eks-lambda-drainer-dev.yaml --acl public-read
@echo https://s3-us-west-2.amazonaws.com/pahud-cfn-us-west-2/eks-templates/cloudformation/eks-dev.yaml
.PHONY: clean
clean:
echo "done"
.PHONY: create-eks-cluster
create-eks-cluster:
@aws --region $(REGION) cloudformation create-stack --template-url $(EKS_YAML_URL) \
--stack-name $(CLUSTER_STACK_NAME) \
--role-arn $(EKS_ADMIN_ROLE) \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
--parameters \
ParameterKey=VpcId,ParameterValue="$(VPC_ID)" \
ParameterKey=ClusterName,ParameterValue="$(CLUSTER_NAME)" \
ParameterKey=ClusterVersion,ParameterValue="$(ClusterVersion)" \
ParameterKey=YamlBranch,ParameterValue="$(YAML_BRANCH)" \
ParameterKey=KeyName,ParameterValue="$(SSH_KEY_NAME)" \
ParameterKey=LambdaRoleArn,ParameterValue="$(EKS_ADMIN_ROLE)" \
ParameterKey=OnDemandBaseCapacity,ParameterValue="$(OnDemandBaseCapacity)" \
ParameterKey=NodeImageId,ParameterValue="$(NodeImageId)" \
ParameterKey=NodeAutoScalingGroupMinSize,ParameterValue="$(NodeAutoScalingGroupMinSize)" \
ParameterKey=NodeAutoScalingGroupDesiredSize,ParameterValue="$(NodeAutoScalingGroupDesiredSize)" \
ParameterKey=NodeAutoScalingGroupMaxSize,ParameterValue="$(NodeAutoScalingGroupMaxSize)" \
ParameterKey=NodeVolumeSize,ParameterValue="$(NodeVolumeSize)" \
ParameterKey=InstanceTypesOverride,ParameterValue="$(InstanceTypesOverride)" \
ParameterKey=ASGAutoAssignPublicIp,ParameterValue="$(ASGAutoAssignPublicIp)" \
ParameterKey=EnableNodeDrainer,ParameterValue="$(EnableNodeDrainer)" \
ParameterKey=SubnetIds,ParameterValue=$(SUBNET1)\\,$(SUBNET2)\\,$(SUBNET3) \
ParameterKey=ExtraNodeSecurityGroups,ParameterValue=$(ExtraNodeSecurityGroups) \
ParameterKey=ExistingNodeSecurityGroups,ParameterValue=$(ExistingNodeSecurityGroups)
@echo click "https://console.aws.amazon.com/cloudformation/home?region=$(REGION)#/stacks to see the details"
.PHONY: update-eks-cluster
update-eks-cluster:
@aws --region $(REGION) cloudformation update-stack --template-url $(EKS_YAML_URL) \
--stack-name $(CLUSTER_STACK_NAME) \
--role-arn $(EKS_ADMIN_ROLE) \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
--parameters \
ParameterKey=VpcId,ParameterValue="$(VPC_ID)" \
ParameterKey=ClusterName,ParameterValue="$(CLUSTER_NAME)" \
ParameterKey=ClusterVersion,ParameterValue="$(ClusterVersion)" \
ParameterKey=YamlBranch,ParameterValue="$(YAML_BRANCH)" \
ParameterKey=KeyName,ParameterValue="$(SSH_KEY_NAME)" \
ParameterKey=LambdaRoleArn,ParameterValue="$(EKS_ADMIN_ROLE)" \
ParameterKey=OnDemandBaseCapacity,ParameterValue="$(OnDemandBaseCapacity)" \
ParameterKey=NodeImageId,ParameterValue="$(NodeImageId)" \
ParameterKey=NodeAutoScalingGroupMinSize,ParameterValue="$(NodeAutoScalingGroupMinSize)" \
ParameterKey=NodeAutoScalingGroupDesiredSize,ParameterValue="$(NodeAutoScalingGroupDesiredSize)" \
ParameterKey=NodeAutoScalingGroupMaxSize,ParameterValue="$(NodeAutoScalingGroupMaxSize)" \
ParameterKey=NodeVolumeSize,ParameterValue="$(NodeVolumeSize)" \
ParameterKey=InstanceTypesOverride,ParameterValue="$(InstanceTypesOverride)" \
ParameterKey=ASGAutoAssignPublicIp,ParameterValue="$(ASGAutoAssignPublicIp)" \
ParameterKey=EnableNodeDrainer,ParameterValue="$(EnableNodeDrainer)" \
ParameterKey=ForceUpdateAMI,ParameterValue="$(ForceUpdateAMI)" \
ParameterKey=SubnetIds,ParameterValue=$(SUBNET1)\\,$(SUBNET2)\\,$(SUBNET3) \
ParameterKey=ExtraNodeSecurityGroups,ParameterValue=$(ExtraNodeSecurityGroups) \
ParameterKey=ExistingNodeSecurityGroups,ParameterValue=$(ExistingNodeSecurityGroups)
@echo click "https://console.aws.amazon.com/cloudformation/home?region=$(REGION)#/stacks to see the details"
.PHONY: delete-eks-cluster
delete-eks-cluster:
@aws --region $(REGION) cloudformation delete-stack --role-arn $(EKS_ADMIN_ROLE) --stack-name "$(CLUSTER_STACK_NAME)"
@echo click "https://console.aws.amazon.com/cloudformation/home?region=$(REGION)#/stacks to see the details"
.PHONY: deploy-pl
deploy-pl:
@aws --region us-west-2 cloudformation create-stack --template-body file://cloudformation/codepipeline.yml \
--stack-name eksGlobalPL \
--parameters \
ParameterKey=GitHubToken,ParameterValue=$(GitHubToken) \
ParameterKey=CloudFormationExecutionRole,ParameterValue=$(EKS_ADMIN_ROLE) \
ParameterKey=OnDemandBaseCapacity,ParameterValue=$(OnDemandBaseCapacity) \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND
.PHONY: update-pl
update-pl:
@aws --region us-west-2 cloudformation update-stack --template-body file://cloudformation/codepipeline.yml \
--stack-name eksGlobalPL \
--parameters \
ParameterKey=GitHubToken,ParameterValue=$(GitHubToken) \
ParameterKey=CloudFormationExecutionRole,ParameterValue=$(EKS_ADMIN_ROLE) \
ParameterKey=OnDemandBaseCapacity,ParameterValue=$(OnDemandBaseCapacity) \
ParameterKey=NodeAutoScalingGroupDesiredSize,ParameterValue=$(NodeAutoScalingGroupDesiredSize) \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND
.PHONY: delete-pl-stacks
delete-pl-stacks:
# delete all cfn stacks provisioned from the pipeline
@aws --region us-west-2 cloudformation update-stack --template-body file://cloudformation/codepipeline.yml \
--stack-name eksGlobalPL \
--parameters \
ParameterKey=GitHubToken,ParameterValue=$(GitHubToken) \
ParameterKey=ActionMode,ParameterValue=DELETE_ONLY \
ParameterKey=CloudFormationExecutionRole,ParameterValue=$(EKS_ADMIN_ROLE) \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND
.PHONY: delete-pl
delete-pl:
@aws --region us-west-2 cloudformation delete-stack --stack-name eksGlobalPL