-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
75 lines (60 loc) · 2.01 KB
/
Copy pathMakefile
File metadata and controls
75 lines (60 loc) · 2.01 KB
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
#!make
include ./configs/.env
export $(shell sed 's/=.*//' ./configs/.env)
export SAM_CLI_TELEMETRY=0
AWS_PROFILE ?= sandbox
APP_TEMPLATE = "template"
S3_BUCKET = $(APP_NAME)-$(AWS_PROFILE)-$(USERNAME)
ifneq ($(USE_DOCKER),no)
PROJECT_DIR ?= $(shell pwd)
DOCKER = docker run -t -v ${PROJECT_DIR}:/app $(APP_NAME):latest
endif
.SILENT:
.PHONY: help
## Prints this help screen
help:
printf "Available targets\n\n"
awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf "%-15s %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
## Create the s3 bucket that will host the artifcats in aws environment
setup:
aws configure --profile $(AWS_PROFILE)
aws s3 mb s3://$(S3_BUCKET) --profile $(AWS_PROFILE)
## Build the docker image to execute make commands locally
docker-build:
docker build -f build/ci/Dockerfile . -t $(APP_NAME):latest
## install npm dependencies
install:
${DOCKER} npm install
## Run linter
lint:
${DOCKER} npm run lint
## Format code
format:
${DOCKER} npm run lint:fix
## Run tests
tests:
${DOCKER} npm run test
## build webpack
webpack-build:
NODE_ENV=production ${DOCKER} npm run build
## Deploy application code (template.yml) to aws environment
deploy: webpack-build
scripts/deploy.sh $(AWS_PROFILE) $(S3_BUCKET) $(APP_NAME) ${APP_TEMPLATE} ${USERNAME}
## Run the lambda functions locally
run: webpack-build
cp configs/lambdas-env.json /tmp/lambdas-env.json && sed -n 's/#USERNAME#/${USERNAME}/g' /tmp/lambdas-env.json
cd .aws-sam/build/ && sam local start-api --env-vars /tmp/lambdas-env.json --profile $(AWS_PROFILE)
## Display logs of certain function (ex: make logs function=FUNCTION-NAME)
logs:
sam logs -n $(function) --stack-name $(APP_NAME) --profile $(AWS_PROFILE)
## Destroy the stacks (resources & application)
destroy:
aws cloudformation delete-stack --stack-name $(APP_NAME) --profile $(AWS_PROFILE)