-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
48 lines (41 loc) · 1.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
ALL: deploy
.PHONY: layers deploy package validate
PROJECT := Math
ENVIRONMENT ?= Test
STACK_NAME ?= MathApi$(ENVIRONMENT)
PACKAGE_TEMPLATE := template.yml
PACKAGE_BUCKET ?= chialab-cloudformation-templates
PACKAGE_PREFIX ?= chialab/math-api/$(shell git symbolic-ref --short HEAD)
PACKAGE_PROFILE ?= chialabsrl
DEPLOY_PROFILE ?= chialab
layers:
docker run --rm \
-v $(PWD)/layers/mathjax-node-layer/nodejs:/var/task \
-e NODE_ENV=production \
lambci/lambda:build-nodejs8.10 \
npm $(if $(wildcard layers/mathjax-node-layer/nodejs/node_modules/*), rebuild, install)
ensure-layer-%:
@if ! [[ -d 'layers/$*/nodejs/node_modules' ]]; then \
printf '\033[31mDependencies for layer \033[1m%s\033[22m are not installed, run \033[1m%s\033[22m first!\033[0m\n' $* 'make layers'; \
exit 1; \
fi
deploy: package
aws cloudformation deploy \
--template-file $(PACKAGE_TEMPLATE) \
--stack-name $(STACK_NAME) \
--tags Project=$(PROJECT) Environment=$(ENVIRONMENT) \
--capabilities CAPABILITY_IAM \
--profile $(DEPLOY_PROFILE)
package: ensure-layer-mathjax-node-layer validate
aws cloudformation package \
--template-file templates/root.yml \
--output-template-file $(PACKAGE_TEMPLATE) \
--s3-bucket $(PACKAGE_BUCKET) \
--s3-prefix $(PACKAGE_PREFIX) \
--profile $(PACKAGE_PROFILE)
aws s3 cp $(PACKAGE_TEMPLATE) s3://$(PACKAGE_BUCKET)/$(PACKAGE_PREFIX)/ --profile $(PACKAGE_PROFILE)
@echo "https://$(PACKAGE_BUCKET).s3.amazonaws.com/$(PACKAGE_PREFIX)/$(PACKAGE_TEMPLATE)"
validate:
aws cloudformation validate-template \
--template-body file://templates/root.yml \
--profile $(PACKAGE_PROFILE)