This repository has been archived by the owner on Mar 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
211 lines (195 loc) · 4.81 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
SHELL = /bin/sh
#
# import environment variables
#
ifneq (,$(wildcard ./.env))
include .env
export
endif
#
# define CLI prefix for commands
#
BLUE_ = \033[34m
CYAN_ = \033[36m
GRAY_ = \033[90m
BOLD_ = \033[1m
_ENDF = \033[0m
define prompt
@echo "$(CYAN_)make:$@$(GRAY_)$$$(_ENDF) \c"
endef
define header
@echo ""
@echo "$(BLUE_)$(BOLD_)************************************************************$(_ENDF)"
@echo "$(BLUE_):: $(CYAN_)make.target = $(BOLD_)$@$(_ENDF)"
@echo "$(BLUE_)$(BOLD_)************************************************************$(_ENDF)"
endef
#
# common values
#
sam-dir = .aws-sam
src-pip-reqts = src/requirements.txt
src-py-files = src/*.py
venv-dir = .venv
#
# configure goals
#
default: lint unittest dist
.PHONY: .gitignore mostlyclean clean destroy init deplock diagrams lint unittest dist deploy e2etest
#
# create .gitignore file
#
.gitignore:
$(call header)
$(call prompt)
curl https://www.toptal.com/developers/gitignore/api/linux,osx,pycharm,python,virtualenv,visualstudiocode,windows > $@
$(call prompt)
cat .utils/gitignore.ext >> $@
#
# remove generated files from project
#
mostlyclean:
$(call header)
$(call prompt)
rm -rf $(sam-dir)
$(call prompt)
rm -rf .coverage
$(call prompt)
rm -rf **/.pytest_cache
$(call prompt)
rm -rf **/__pycache__
clean: | mostlyclean
$(call header)
$(call prompt)
rm -rf $(venv-dir)
$(call prompt)
rm -f $(src-pip-reqts)
destroy:
$(call header)
$(call prompt)
aws cloudformation delete-stack \
--stack-name "${STACK_NAME}" | jq -rc .
#
# Poetry initialization rules
#
$(venv-dir): poetry.lock
$(call header)
$(call prompt)
poetry install
$(call prompt)
touch $@
$(src-pip-reqts): pyproject.toml poetry.lock
$(call header)
$(call prompt)
poetry export -f requirements.txt > $@
#
# initialization rules
#
init: $(venv-dir) $(src-pip-reqts)
deplock:
$(call header)
$(call prompt)
poetry lock
$(call prompt)
touch $@
#
# diagram generation rule
#
diagrams: | init
$(call header)
$(call prompt)
poetry run python3 docs/overview_diagram.py
#
# project linting rule
# * find pyilnt errors (exit non-zero if found)
# * list pylint warnings (exit zero always)
# * find flake8 errors (exit non-zero if found)
# * validate Python docstring conventions
#
lint: | init
$(call header)
$(call prompt)
poetry run pylint --errors-only src docs tests
$(call prompt)
poetry run pylint --exit-zero src docs tests
$(call prompt)
poetry run flake8 --benchmark --count src docs tests
$(call prompt)
poetry run pydocstyle --match='.*\.py' --count src docs tests
#
# project unit testing rule
#
unittest: | init
$(call header)
$(call prompt)
poetry run pytest --cov=src/ tests/unit
#
# project building rule
# * validate the SAM template
# * build the local build artifacts
# * package the artifacts and deliver to S3 bucket
#
$(sam-dir): $(venv-dir) template.yaml $(src-py-files)
$(call header)
$(call prompt)
poetry run sam validate
$(call prompt)
poetry run sam build
$(call prompt)
touch $@
dist: $(sam-dir)
#
# project integration testing rule
#
inttest: | init dist
$(call header)
$(call prompt)
poetry run sam local invoke minecraft-local-get-servers \
--event tests/integration/get-servers.json \
--parameter-overrides "\
ParameterKey=Environment,ParameterValue=local \
ParameterKey=FunctionRole,ParameterValue=${FUNCTION_ROLE_ARN} \
" \
| jq -r '.body'
poetry run sam local invoke minecraft-local-get-server \
--event tests/integration/get-servers-dream.json \
--parameter-overrides "\
ParameterKey=Environment,ParameterValue=local \
ParameterKey=FunctionRole,ParameterValue=${FUNCTION_ROLE_ARN} \
" \
| jq -r '.body'
poetry run sam local invoke minecraft-local-get-users \
--event tests/integration/get-users.json \
--parameter-overrides "\
ParameterKey=Environment,ParameterValue=local \
ParameterKey=FunctionRole,ParameterValue=${FUNCTION_ROLE_ARN} \
" \
| jq -r '.body'
#
# deploy the application to AWS
#
deploy: | init dist
$(call header)
$(call prompt)
poetry run sam deploy \
--stack-name "${STACK_NAME}" \
--s3-bucket "${S3_DEPLOYMENT_BUCKET}" \
--s3-prefix "${STACK_NAME}" \
--capabilities CAPABILITY_NAMED_IAM \
--role-arn "${CLOUDFORMATION_ROLE_ARN}" \
--no-fail-on-empty-changeset \
--parameter-overrides "\
ParameterKey=Environment,ParameterValue=${ENVIRONMENT} \
ParameterKey=EventBridgeRole,ParameterValue=${EVENTBRIDGE_ROLE_ARN} \
ParameterKey=FunctionRole,ParameterValue=${FUNCTION_ROLE_ARN} \
ParameterKey=StateMachineRole,ParameterValue=${STATEMACHINE_ROLE_ARN} \
ParameterKey=ApiDomainName,ParameterValue=${API_DOMAIN_NAME} \
ParameterKey=HostedZoneId,ParameterValue=${HOSTED_ZONE_ID} \
ParameterKey=CertificateArn,ParameterValue=${CERTIFICATE_ARN} \
"
#
# project end-to-end testing rule
#
e2etest: | init
$(call header)
$(call prompt)
poetry run pytest tests/e2e