-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
135 lines (113 loc) · 3.9 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
init:
pipenv --python 3.8
pipenv install --dev
# Command to run everytime you make changes to verify everything works
dev: flake lint test
# Verifications to run before sending a pull request
pr: init dev
SAM_TEMPLATE ?= template.yaml
ENV ?= ${USER}
APPNAME ?= $(shell basename ${CURDIR})
STACKNAME = $(APPNAME)-$(ENV)
AWS_REGION ?= $(shell aws configure get region)
PIPELINE_STACKNAME = $(APPNAME)-pipeline-$(ENV)
PIPELINE_CONFIG_FILE ?= codepipeline-config-$(ENV).yaml
REPO_ID ?= ServerlessOpsIO/PhotoOps
BRANCH ?= 'master'
check_profile:
# Make sure we have a user-scoped credentials profile set. We don't want to be accidentally using the default profile
@aws configure --profile ${AWS_PROFILE} list 1>/dev/null 2>/dev/null || (echo '\nMissing AWS Credentials Profile called '${AWS_PROFILE}'. Run `aws configure --profile ${AWS_PROFILE}` to create a profile called '${AWS_PROFILE}' with creds to your personal AWS Account'; exit 1)
build:
$(info Building application)
sam build --use-container --parallel --template ${SAM_TEMPLATE}
validate:
$(info linting SAM template)
$(info linting CloudFormation)
@cfn-lint template.yaml
$(info validating SAM template)
@sam validate
deploy: validate build
$(info Deploying to personal development stack)
sam deploy \
--region ${AWS_REGION} \
--resolve-s3 \
--stack-name $(STACKNAME) \
--tags \
ServiceName=$(APPNAME) \
ServiceEnv=$(ENV) \
StackName=$(STACKNAME) \
--parameter-overrides \
ServiceName=$(APPNAME) \
ServiceEnv=$(ENV)
# Requires usage of PipelineUser IAM user.
deploy-pipeline:
$(info Deploying to personal development stack)
sam deploy \
--region ${AWS_REGION} \
--resolve-s3 \
--template codepipeline.yaml \
--stack-name $(PIPELINE_STACKNAME) \
--tags \
ServiceName=$(APPNAME) \
ServiceEnv=$(ENV) \
StackName=$(PIPELINE_STACKNAME) \
PipelineStack=true \
--parameter-overrides \
ServiceName=$(APPNAME) \
FullRepositoryId=$(REPO_ID) \
GitBranch=$(BRANCH)
generate-codepipeline-cfn-config:
$(info generating configurations for CloudFormation deploy)
echo '{ "Tags": {"ServiceName":"$(APPNAME)", "ServiceEnv":"$(ENV)", "StackName":"$(STACKNAME)"} }' > $(PIPELINE_CONFIG_FILE)
describe:
$(info Describing stack)
@aws cloudformation describe-stacks --stack-name $(STACKNAME) --output table --query 'Stacks[0]'
outputs:
$(info Displaying stack outputs)
@aws cloudformation describe-stacks --stack-name $(STACKNAME) --output table --query 'Stacks[0].Outputs'
parameters:
$(info Displaying stack parameters)
@aws cloudformation describe-stacks --stack-name $(STACKNAME) --output table --query 'Stacks[0].Parameters'
delete:
$(info Delete stack)
@sam delete --stack-name $(STACKNAME)
function:
$(info creating function: ${F})
mkdir -p src/handlers/${F}
touch src/handlers/${F}/__init__.py
touch src/handlers/${F}/function.py
mkdir -p tests/{unit,integration}/src/handlers/${F}
touch tests/unit/src/handlers/${F}/__init__.py
touch tests/unit/src/handlers/${F}/test_handler.py
touch tests/integration/src/handlers/${F}/__init__.py
touch tests/integration/src/handlers/${F}/test_handler.py
echo "-e src/common/" > src/handlers/${F}/requirements.txt
touch data/events/${F}-{event,data}.json
touch data/outputs/${F}-outputs.json
unit-test:
$(info running unit tests)
# Integration tests don't need code coverage
pipenv run unit-test
integ-test:
$(info running integration tests)
# Integration tests don't need code coverage
pipenv run integ-test
test:
$(info running tests)
# Run unit tests
# Fail if coverage falls below 95%
pipenv run test
flake8:
$(info running flake8 on code)
# Make sure code conforms to PEP8 standards
pipenv run flake8 src
pipenv run flake8 tests/unit tests/integration
pylint:
$(info running pylint on code)
# Linter performs static analysis to catch latent bugs
pipenv run lint --rcfile .pylintrc src
lint: pylint flake8
clean:
$(info cleaning project)
# remove sam cache
rm -rf .aws-sam