forked from aws-samples/aws-serverless-airline-booking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
155 lines (129 loc) · 5.37 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
##########################
# Bootstrapping variables
##########################
AWS_BRANCH ?= "dev"
FLIGHT_TABLE_NAME ?= "UNDEFINED"
STACK_NAME ?= "UNDEFINED"
DEPLOYMENT_BUCKET_NAME ?= "UNDEFINED"
GRAPHQL_API_ID ?= "UNDEFINED"
BOOKING_TABLE_NAME ?= "UNDEFINED"
target:
$(info ${HELP_MESSAGE})
@exit 0
init: ##=> Install OS deps and dev tools
$(info [*] Bootstrapping CI system...)
@$(MAKE) _install_os_packages
outputs: ##=> Fetch SAM stack outputs
$(MAKE) outputs.payment
outputs.payment: ##=> Converts Payments output stack to Vue env variables
aws cloudformation describe-stacks --stack-name $${STACK_NAME}-payment-$${AWS_BRANCH} --query 'Stacks[0].Outputs[?OutputKey==`PaymentChargeUrl`].OutputValue' | jq -r '.[] | "VUE_APP_PaymentChargeUrl" + "=\"" + (.|tostring) + "\""' > src/frontend/.env
@echo "VUE_APP_StripePublicKey=\"$$STRIPE_PUBLIC_KEY\"" >> src/frontend/.env
cat src/frontend/.env
deploy: ##=> Deploy services
$(info [*] Deploying...)
$(MAKE) deploy.payment
$(MAKE) deploy.booking
$(MAKE) deploy.loyalty
$(MAKE) deploy.log-processing
delete: ##=> Delete services
$(MAKE) delete.booking
$(MAKE) delete.payment
$(MAKE) delete.loyalty
$(MAKE) delete.log-processing
delete.booking: ##=> Delete booking service
aws cloudformation delete-stack --stack-name $${STACK_NAME}-booking-$${AWS_BRANCH}
delete.payment: ##=> Delete payment service
aws cloudformation delete-stack --stack-name $${STACK_NAME}-payment-$${AWS_BRANCH}
delete.loyalty: ##=> Delete booking service
aws cloudformation delete-stack --stack-name $${STACK_NAME}-loyalty-$${AWS_BRANCH}
delete.log-processing:
aws cloudformation delete-stack --stack-name $${STACK_NAME}-log-processing-$${AWS_BRANCH}
deploy.booking: ##=> Deploy booking service using SAM
$(info [*] Packaging and deploying Booking service...)
cd src/backend/booking && \
sam build && \
sam package \
--s3-bucket $${DEPLOYMENT_BUCKET_NAME} \
--output-template-file packaged.yaml && \
sam deploy \
--template-file packaged.yaml \
--stack-name $${STACK_NAME}-booking-$${AWS_BRANCH} \
--capabilities CAPABILITY_IAM \
--parameter-overrides \
BookingTable=$${BOOKING_TABLE_NAME} \
FlightTable=$${FLIGHT_TABLE_NAME} \
CollectPaymentFunction=/service/payment/collect-function/$${AWS_BRANCH} \
RefundPaymentFunction=/service/payment/refund-function/$${AWS_BRANCH} \
AppsyncApiId=$${GRAPHQL_API_ID} \
Stage=$${AWS_BRANCH}
deploy.payment: ##=> Deploy payment service using SAM
$(info [*] Packaging and deploying Payment service...)
cd src/backend/payment && \
sam build && \
sam package \
--s3-bucket $${DEPLOYMENT_BUCKET_NAME} \
--output-template-file packaged.yaml && \
sam deploy \
--template-file packaged.yaml \
--stack-name $${STACK_NAME}-payment-$${AWS_BRANCH} \
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND \
--parameter-overrides \
Stage=$${AWS_BRANCH} \
StripeKey=$${STRIPE_SECRET_KEY}
deploy.loyalty: ##=> Deploy loyalty service using SAM and TypeScript build
$(info [*] Packaging and deploying Loyalty service...)
cd src/backend/loyalty && \
npm install && \
npm run build && \
sam package \
--s3-bucket $${DEPLOYMENT_BUCKET_NAME} \
--output-template-file packaged.yaml && \
sam deploy \
--template-file packaged.yaml \
--stack-name $${STACK_NAME}-loyalty-$${AWS_BRANCH} \
--capabilities CAPABILITY_IAM \
--parameter-overrides \
BookingSNSTopic=/service/booking/booking-topic/$${AWS_BRANCH} \
Stage=$${AWS_BRANCH} \
AppsyncApiId=$${GRAPHQL_API_ID}
deploy.log-processing: ##=> Deploy Log Processing for CloudWatch Logs
$(info [*] Packaging and deploying Loyalty service...)
cd src/backend/log-processing && \
sam deploy \
--template-file template.yaml \
--stack-name $${STACK_NAME}-log-processing-$${AWS_BRANCH} \
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND
#############
# Helpers #
#############
_install_os_packages:
$(info [*] Installing jq...)
yum install jq -y
$(info [*] Upgrading Python SAM CLI and CloudFormation linter to the latest version...)
python3 -m pip install --upgrade --user cfn-lint aws-sam-cli
define HELP_MESSAGE
Environment variables:
These variables are automatically filled at CI time except STRIPE_SECRET_KEY
If doing a dirty/individual/non-ci deployment locally you'd need them to be set
AWS_BRANCH: "dev"
Description: Feature branch name used as part of stacks name; added by Amplify Console by default
FLIGHT_TABLE_NAME: "Flight-hnxochcn4vfdbgp6zaopgcxk2a-xray"
Description: Flight Table name created by Amplify for Catalog service
STACK_NAME: "awsserverlessairline-twitch-20190705130553"
Description: Stack Name already deployed; used for dirty/individual deployment
DEPLOYMENT_BUCKET_NAME: "a_valid_bucket_name"
Description: S3 Bucket name used for deployment artifacts
GRAPHQL_API_ID: "hnxochcn4vfdbgp6zaopgcxk2a"
Description: AppSync GraphQL ID already deployed
BOOKING_TABLE_NAME: "Booking-hnxochcn4vfdbgp6zaopgcxk2a-xray"
Description: Flight Table name created by Amplify for Booking service
STRIPE_SECRET_KEY: "sk-test-asdf..."
Description: Stripe Private Secret Key generated in Stripe; manually added in Amplify Console Env Variables per App
Common usage:
...::: Bootstraps environment with necessary tools like SAM CLI, cfn-lint, etc. :::...
$ make init
...::: Deploy all SAM based services :::...
$ make deploy
...::: Delete all SAM based services :::...
$ make delete
endef