-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
120 lines (110 loc) · 3.48 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
#include .env
ifndef AWS_PROFILE
$(error You must specify AWS_PROFILE parameter)
endif
ifndef roleArn
$(error You must specify roleArn parameter)
endif
ifndef KeyName
$(error You must specify KeyName parameter. create your key pair in AWS Console)
endif
ifndef region
$(error You must specify region parameter)
endif
ifndef BUCKET
$(error You must specify BUCKET parameter)
endif
ifndef CODA_BUCKET_SECRETS
$(error You must specify CODA_BUCKET_SECRETS parameter)
endif
ifndef AWS_BUILD_SUBNET
$(error You must specify AWS_BUILD_SUBNET parameter)
endif
ifndef NOTIFY_EMAIL
$(error You must specify NOTIFY_EMAIL parameter)
endif
env?=staging
version?=$(shell ./ci/version.sh)
region?=us-east-1
appName?=Coda
stack_name?=$(appName)-$(region)-$(env)
AWS_SOURCE_AMI?=$(shell ./bin/source-ami.sh $(AWS_PROFILE) $(region))
BastionVersion?=dev-master
KeyName?=code-infra-test
AWS_PROFILE?=coda
AWS_AMI_USER?=ubuntu
AWS_DISTRIBUTION?=Ubuntu
BastionAmiVersion?=1.0.2-1e231703-9044-4c58-b471-4b6345daf4a4-ami-0eb177f6a414935d8.4
AWS_INSTANCE_BUILD_TYPE?=t2.micro
AWS_INSTANCE_TYPE?=c5.2xlarge
BastionAmiId?=$(shell ./bin/bastion-ami.sh $(BastionAmiVersion) $(region) $(AWS_PROFILE) )
CodaAmiId?=$(shell ./bin/coda-ami.sh $(AWS_PROFILE) $(env))
BUCKET?=init-stack-templatebucket-h0zgfseupync
CodaInstanceType?=c5.2xlarge
## Condtionnal start of the stacks
RunVpcStack?=true
RunBastionStack?=true
RunCodaStack?=true
RunCodaWorkerStack?=true
NbAzs=$(shell ./bin/getRegionAzs.sh $(region) $(AWS_PROFILE))
## Install packer
packer-install:
sudo $(PWD)/ci/install_packer.sh /usr/local/
## Update aws-cli
update-aws-cli:
pip install awscli --upgrade --user
## Check packer template
packer-validate: update-aws-cli
cd packer && packer inspect template.json && packer validate -var-file variables.json template.json
## Build Coda AMI using packer ansible local
build-ami:
packer version
cd packer && \
PACKER_LOG=1 AWS_PROFILE=$(AWS_PROFILE) AWS_BUILD_SUBNET=$(AWS_BUILD_SUBNET) AWS_INSTANCE_BUILD_TYPE=${AWS_INSTANCE_BUILD_TYPE} \
AWS_SOURCE_AMI=$(AWS_SOURCE_AMI) \
packer build \
-var-file variables.json \
-var "playbook_version=$(version)" \
-var "region=$(region)" \
-var "env=$(env)" \
template.json
## Package Cloud Formation template
package:
aws --profile $(AWS_PROFILE) \
--region $(region) \
cloudformation package \
--template-file cloudformation/stacks/main.yml \
--s3-bucket $(BUCKET) \
--output-template-file template-output.yml
## Deploy Cloud Formation stack
deploy: package
aws --profile $(AWS_PROFILE) \
--region $(region) \
cloudformation deploy \
--template-file template-output.yml \
--capabilities CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
--role-arn $(roleArn) \
--stack-name $(stack_name) \
--parameter-overrides \
BastionAmiId=$(BastionAmiId) CodaAmiId=$(CodaAmiId) CodaWorkerAmiId=$(CodaAmiId)\
KeyName=$(KeyName) \
CodaInstanceType=$(CodaInstanceType) \
RunVpcStack=$(RunVpcStack) \
RunBastionStack=$(RunBastionStack) \
CodaBucketInfra=$(CODA_BUCKET_SECRETS) \
BucketInfra=$(BUCKET) \
NotifyEmail=$(NOTIFY_EMAIL) \
NumberOfAZs=$(NbAzs)
## Describe Cloud Formation stack outputs
describe:
aws --profile $(AWS_PROFILE) \
--region $(region) \
cloudformation describe-stacks \
--stack-name $(stack_name) \
--query 'Stacks[0].Outputs[*].[OutputKey, OutputValue]' --output text
## Delete Cloud Formation stack
delete:
aws --profile $(AWS_PROFILE) \
--region $(region) \
cloudformation delete-stack \
--stack-name $(stack_name)