forked from aws-samples/aws-serverless-airline-booking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
116 lines (97 loc) · 3.59 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
##########################
# 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 and save under /tmp
$(MAKE) outputs.payment
outputs.payment: ##=> Fetch SAM stack outputs
aws cloudformation describe-stacks --stack-name $${STACK_NAME}-payment-$${AWS_BRANCH} --query 'Stacks[0].Outputs' > /tmp/payment-stack.json
outputs.vue: ##=> Converts Payments output stack to Vue env variables
cat /tmp/payment-stack.json | jq -r '.[] | "VUE_APP_" + .OutputKey + "=\"" + (.OutputValue|tostring) + "\""' > src/frontend/.env
deploy: ##=> Deploy services
$(info [*] Deploying...)
$(MAKE) deploy.payment
$(MAKE) deploy.booking
$(MAKE) deploy.loyalty
delete: ##=> Delete services
$(MAKE) deploy.booking
$(MAKE) deploy.payment
$(MAKE) deploy.loyalty
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}
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}
#############
# Helpers #
#############
_install_os_packages:
$(info [*] Installing jq...)
yum install jq -y
$(info [*] Upgrading Python PIP, SAM CLI and CloudFormation linter...)
python3 -m pip install --upgrade pip cfn-lint aws-sam-cli
define HELP_MESSAGE
Common usage:
...::: Bootstraps environment with necessary tools like SAM and Pipenv :::...
$ make init
...::: Deploy all SAM based services :::...
$ make deploy
endef