-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMakefile
More file actions
96 lines (77 loc) · 2.63 KB
/
Makefile
File metadata and controls
96 lines (77 loc) · 2.63 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
FUNCTION=undefined
PLATFORM=undefined
URL=undefined
VERSION=undefined
BUILD_NUMBER=undefined
CODE=$(shell ls *.py)
ifneq (,$(findstring -staging,$(FUNCTION)))
ENVIRONMENT = STAGING
else ifneq (,$(findstring -production,$(FUNCTION)))
ENVIRONMENT = PRODUCTION
else
ENVIRONMENT = undefined
endif
hello:
@echo "Here are the targets for this Makefile:"
@echo " requirements - install the project requirements"
@echo " lint - run linters on the code"
@echo " black - run black to format the code"
@echo " test - run the tests"
@echo " build - build the lambda.zip file"
@echo " deploy - deploy the lambda.zip file to AWS"
@echo " testdeployment - test the deployment"
@echo " clean - remove the lambda.zip file"
@echo " all - clean, lint, black, test, build, and deploy"
@echo
@echo
@echo "You must set the FUNCTION variables to use the deploy target."
@echo "FUNCTION must be set to the name of an existing lambda function to update."
@echo "For example:"
@echo
@echo " make deploy FUNCTION=sample-application-staging"
@echo
@echo "Optional deploy variables are:"
@echo " VERSION - the version of the code being deployed (default: undefined)"
@echo " PLATFORM - the platform being used for the deployment (default: undefined)"
@echo " BUILD_NUMBER - the build number assigned by the deployment platform (default: undefined)"
@echo " URL - the URL to use for testing the deployment (default: undefined)"
@echo
requirements:
pip install -U pip
pip install --requirement requirements.txt
check:
set
zip --version
python --version
pylint --version
flake8 --version
aws --version
lint:
pylint --exit-zero --errors-only --disable=C0301 --disable=C0326 --disable=R,C $(CODE)
flake8 --exit-zero --ignore=E501,E231 $(CODE)
black:
black --diff $(CODE)
test:
python -m unittest -v index_test
build:
zip lambda.zip index.py data.json template.html
deploy:
aws sts get-caller-identity
aws lambda wait function-active \
--function-name="$(FUNCTION)"
aws lambda update-function-configuration \
--function-name="$(FUNCTION)" \
--environment "Variables={PLATFORM=$(PLATFORM),VERSION=$(VERSION),BUILD_NUMBER=$(BUILD_NUMBER),ENVIRONMENT=$(ENVIRONMENT)}"
aws lambda wait function-updated \
--function-name="$(FUNCTION)"
aws lambda update-function-code \
--function-name="$(FUNCTION)" \
--zip-file=fileb://lambda.zip
aws lambda wait function-updated \
--function-name="$(FUNCTION)"
testdeployment:
curl -s $(URL) | grep $(VERSION)
clean:
rm -vf lambda.zip
all: clean lint black test build deploy
.PHONY: test build deploy all clean