-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
54 lines (44 loc) · 2.18 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
# The variable TRAVIS_AWS_PROFILE is set when .travis.yml runs
# We create a function to simplify getting variables for aws parameter store.
# The variable TRAVIS_AWS_PROFILE is set when .travis.yml runs
define ssm
$(shell aws --profile $(TRAVIS_AWS_PROFILE) ssm get-parameters --names $1 --with-decryption --query Parameters[0].Value --output text)
endef
# The other variables needed up in UPJSON and PRODUPJSON are set when `source ./aws.env` runs
# - STAGE
# - DOMAIN
# - EMAIL_FOR_NOTIFICATION_UNIT
# - PRIVATE_SUBNET_1
# - PRIVATE_SUBNET_2
# - PRIVATE_SUBNET_3
# - LAMBDA_TO_RDS_SECURITY_GROUP
# These variables can be edited in the AWS parameter store for the environment
UPJSON = '.profile |= "$(TRAVIS_AWS_PROFILE)" \
|.stages.production |= (.domain = "unit.$(call ssm,STAGE).$(call ssm,DOMAIN)" | .zone = "$(call ssm,STAGE).$(call ssm,DOMAIN)") \
| .actions[0].emails |= ["$(call ssm,EMAIL_FOR_NOTIFICATION_UNIT)"] \
| .lambda.vpc.subnets |= [ "$(call ssm,PRIVATE_SUBNET_1)", "$(call ssm,PRIVATE_SUBNET_2)", "$(call ssm,PRIVATE_SUBNET_3)" ] \
| .lambda.vpc.security_groups |= [ "$(call ssm,LAMBDA_TO_RDS_SECURITY_GROUP)" ]'
PRODUPJSON = '.profile |= "$(TRAVIS_AWS_PROFILE)" \
|.stages.production |= (.domain = "unit.$(call ssm,DOMAIN)" | .zone = "$(call ssm,DOMAIN)") \
| .actions[0].emails |= ["$(call ssm,EMAIL_FOR_NOTIFICATION_UNIT)"] \
| .lambda.vpc.subnets |= [ "$(call ssm,PRIVATE_SUBNET_1)", "$(call ssm,PRIVATE_SUBNET_2)", "$(call ssm,PRIVATE_SUBNET_3)" ] \
| .lambda.vpc.security_groups |= [ "$(call ssm,LAMBDA_TO_RDS_SECURITY_GROUP)" ]'
# We have everything, we can run up now.
dev:
@echo $$AWS_ACCESS_KEY_ID
jq $(UPJSON) up.json.in > up.json
up deploy production
demo:
@echo $$AWS_ACCESS_KEY_ID
# We replace the relevant variable in the up.json file
# We use the template defined in up.json.in for that
jq $(UPJSON) up.json.in > up.json
up deploy production
prod:
@echo $$AWS_ACCESS_KEY_ID
# We replace the relevant variable in the up.json file
# We use the template defined in up.json.in for that
jq $(PRODUPJSON) up.json.in > up.json
up deploy production
test:
curl -i -H "Authorization: Bearer $(API_ACCESS_TOKEN)" https://unit.$(STAGE).$(DOMAIN)/metrics