-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
110 lines (79 loc) · 2.68 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
BASE := $(shell /bin/pwd)
CODE_COVERAGE = 72
PIPENV ?= pipenv
#############
# SAM vars #
#############
# Name of Docker Network to connect to
# Helpful when you're running Amazon DynamoDB local etc.
NETWORK = ""
target:
$(info ${HELP_MESSAGE})
@exit 0
clean: ##=> Deletes current build environment and latest build
$(info [*] Who needs all that anyway? Destroying environment....)
rm -rf ./.aws-sam/
all: clean build
install:
$(info [*] Installing pipenv)
@pip install pipenv --upgrade
$(MAKE) dev
dev:
$(info [*] Installing pipenv project dependencies)
@$(PIPENV) install
@$(PIPENV) install -d
shell:
@$(PIPENV) shell
build: ##=> Same as package except that we don't create a ZIP
sam build --use-container
deploy.guided: ##=> Guided deploy that is typically run for the first time only
sam deploy --guided
deploy: ##=> Deploy app using previously saved SAM CLI configuration
sam deploy
invoke: ##=> Run SAM Local function with a given event payload
@sam local invoke IdentityFunction --event events/hello_world_event.json
run: ##=> Run SAM Local API GW and can optionally run new containers connected to a defined network
@test -z ${NETWORK} \
&& sam local start-api \
|| sam local start-api --docker-network ${NETWORK}
test: ##=> Run pytest
@POWERTOOLS_TRACE_DISABLED=1 POWERTOOLS_METRICS_NAMESPACE="MyServerlessApplication" $(PIPENV) run python -m pytest --cov . --cov-report term-missing --cov-fail-under $(CODE_COVERAGE) tests/ -vv
ci: ##=> Run full workflow - Install deps, build deps, and deploy
$(MAKE) dev
$(MAKE) build
$(MAKE) deploy
hurry: ##=> Run full workflow for the first time
$(MAKE) install
$(MAKE) build
$(MAKE) deploy.guided
#############
# Helpers #
#############
define HELP_MESSAGE
Environment variables to be aware of or to hardcode depending on your use case:
NETWORK
Default: ""
Info: Docker Network to connect to when running Lambda function locally
Common usage:
...::: Installs Pipenv, application and dev dependencies defined in Pipfile :::...
$ make install
...::: Builds Lambda function dependencies:::...
$ make build
...::: Deploy for the first time :::...
$ make deploy.guided
...::: Deploy subsequent changes :::...
$ make deploy
...::: Run SAM Local API Gateway :::...
$ make run
...::: Run Pytest under tests/ with pipenv :::...
$ make test
...::: Spawn a virtual environment shell :::...
$ make shell
...::: Cleans up the environment - Deletes Virtualenv, ZIP builds and Dev env :::...
$ make clean
...::: Run full workflow from installing Pipenv, dev and app deps, build, and deploy :::...
$ make ci
Advanced usage:
...::: Run SAM Local API Gateway within a Docker Network :::...
$ make run NETWORK="sam-network"
endef