This repository has been archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
Makefile
114 lines (97 loc) · 5.68 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
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
ROOT ?= $(shell pwd)
AWS_ACCOUNT_ID := $(shell aws sts get-caller-identity --query 'Account' --output text)
YAML_BRANCH ?= stable
ECS_YAML_URL ?= https://s3-us-west-2.amazonaws.com/pahud-cfn-us-west-2/ecs-cfn-refarch/cloudformation/ecs-$(YAML_BRANCH).yaml
CLUSTER_STACK_NAME ?= ecsdemo
CLUSTER_NAME ?= $(CLUSTER_STACK_NAME)
REGION ?= ap-northeast-1
SSH_KEY_NAME ?= 'aws-pahud'
VPC_ID ?= vpc-e549a281
SUBNET1 ?= subnet-05b643f57a6997deb
SUBNET2 ?= subnet-09e79eb1dec82b7e2
SUBNET3 ?= subnet-0c365d97cbc75ceec
ExtraSG ?= ''
OnDemandBaseCapacity ?= 0
NodeAutoScalingGroupMinSize ?= 0
NodeAutoScalingGroupDesiredSize ?= 2
NodeAutoScalingGroupMaxSize ?= 5
ASGAutoAssignPublicIp ?= yes
InstanceTypesOverride ?= 't3.medium,t3.large,t3.xlarge'
EnableEcsSvcCustomMetricsLogger ?= no
# all: deploy
# deploy:
# #aws --region us-west-2 s3 cp cloudformation s3://pahud-cfn-us-west-2/ecs-cfn-refarch/cloudformation/ --acl public-read --recursive
# aws --region us-west-2 s3 sync cloudformation s3://pahud-cfn-us-west-2/ecs-cfn-refarch/cloudformation/ --acl public-read
.PHONY: update-yaml
update-stable-yaml:
@aws --region us-west-2 s3 cp cloudformation/ecs.yaml s3://pahud-cfn-us-west-2/ecs-cfn-refarch/cloudformation/ecs-stable.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/service.yaml s3://pahud-cfn-us-west-2/ecs-cfn-refarch/cloudformation/service-stable.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/ecs-svc-custom-metrics-logger.yaml s3://pahud-cfn-us-west-2/ecs-cfn-refarch/cloudformation/ecs-svc-custom-metrics-logger-stable.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/awscli-lambda-layer.yaml s3://pahud-cfn-us-west-2/ecs-cfn-refarch/cloudformation/awscli-lambda-layer-stable.yaml --acl public-read
.PHONY: update-dev-yaml
update-dev-yaml:
@aws --region us-west-2 s3 cp cloudformation/ecs.yaml s3://pahud-cfn-us-west-2/ecs-cfn-refarch/cloudformation/ecs-dev.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/service.yaml s3://pahud-cfn-us-west-2/ecs-cfn-refarch/cloudformation/service-dev.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/ecs-svc-custom-metrics-logger.yaml s3://pahud-cfn-us-west-2/ecs-cfn-refarch/cloudformation/ecs-svc-custom-metrics-logger-dev.yaml --acl public-read
@aws --region us-west-2 s3 cp cloudformation/awscli-lambda-layer.yaml s3://pahud-cfn-us-west-2/ecs-cfn-refarch/cloudformation/awscli-lambda-layer-dev.yaml --acl public-read
.PHONY: create-cluster
create-ecs-cluster:
@aws --region $(REGION) cloudformation create-stack --template-url $(ECS_YAML_URL) \
--stack-name $(CLUSTER_STACK_NAME) \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
--parameters \
ParameterKey=YamlBranch,ParameterValue="$(YAML_BRANCH)" \
ParameterKey=EnableEcsSvcCustomMetricsLogger,ParameterValue="$(EnableEcsSvcCustomMetricsLogger)" \
ParameterKey=VpcId,ParameterValue="$(VPC_ID)" \
ParameterKey=SshKeyName,ParameterValue="$(SSH_KEY_NAME)" \
ParameterKey=ExtraSG,ParameterValue="$(ExtraSG)" \
ParameterKey=OnDemandBaseCapacity,ParameterValue="$(OnDemandBaseCapacity)" \
ParameterKey=ASGMinSize,ParameterValue="$(NodeAutoScalingGroupMinSize)" \
ParameterKey=ASGDesiredCapacity,ParameterValue="$(NodeAutoScalingGroupDesiredSize)" \
ParameterKey=ASGMaxSize,ParameterValue="$(NodeAutoScalingGroupMaxSize)" \
ParameterKey=InstanceTypesOverride,ParameterValue="$(InstanceTypesOverride)" \
ParameterKey=ASGAutoAssignPublicIp,ParameterValue="$(ASGAutoAssignPublicIp)" \
ParameterKey=SubnetIds,ParameterValue=$(SUBNET1)\\,$(SUBNET2)\\,$(SUBNET3)
@echo click "https://console.aws.amazon.com/cloudformation/home?region=$(REGION)#/stacks to see the details"
.PHONY: update-ecs-cluster
update-ecs-cluster:
@aws --region $(REGION) cloudformation update-stack --template-url $(ECS_YAML_URL) \
--stack-name $(CLUSTER_STACK_NAME) \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
--parameters \
ParameterKey=YamlBranch,ParameterValue="$(YAML_BRANCH)" \
ParameterKey=EnableEcsSvcCustomMetricsLogger,ParameterValue="$(EnableEcsSvcCustomMetricsLogger)" \
ParameterKey=VpcId,ParameterValue="$(VPC_ID)" \
ParameterKey=SshKeyName,ParameterValue="$(SSH_KEY_NAME)" \
ParameterKey=ExtraSG,ParameterValue="$(ExtraSG)" \
ParameterKey=OnDemandBaseCapacity,ParameterValue="$(OnDemandBaseCapacity)" \
ParameterKey=ASGMinSize,ParameterValue="$(NodeAutoScalingGroupMinSize)" \
ParameterKey=ASGDesiredCapacity,ParameterValue="$(NodeAutoScalingGroupDesiredSize)" \
ParameterKey=ASGMaxSize,ParameterValue="$(NodeAutoScalingGroupMaxSize)" \
ParameterKey=InstanceTypesOverride,ParameterValue="$(InstanceTypesOverride)" \
ParameterKey=ASGAutoAssignPublicIp,ParameterValue="$(ASGAutoAssignPublicIp)" \
ParameterKey=SubnetIds,ParameterValue=$(SUBNET1)\\,$(SUBNET2)\\,$(SUBNET3)
@echo click "https://console.aws.amazon.com/cloudformation/home?region=$(REGION)#/stacks to see the details"
.PHONY: get-ecs-cluster
get-ecs-cluster:
@aws --region $(REGION) cloudformation describe-stacks \
--stack-name $(CLUSTER_STACK_NAME) \
--query "Stacks[0].Outputs" --output json
.PHONY: describe-ecs-cluster
describe-ecs-cluster: get-ecs-cluster
.PHONY: delete-ecs-cluster
delete-ecs-cluster:
@aws --region $(REGION) cloudformation delete-stack --stack-name "$(CLUSTER_STACK_NAME)"
@echo "deleting the stacks now."
@echo click "https://console.aws.amazon.com/cloudformation/home?region=$(REGION)#/stacks to make sure the stacks were deleted"
clean:
echo "done"
.PHONY: all deploy clean