This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
140 lines (119 loc) · 4.69 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
#################################################
# Please use mmake: https://github.com/tj/mmake #
#################################################
SHELL=bash
APP_NAME=workshop-lambda
# In order to use moto in AWS CodeBuild the following to environment varibales need to be unset.
# https://forums.aws.amazon.com/thread.jspa?messageID=785174
unexport AWS_DEFAULT_REGION
unexport AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Undefined $1$(if $2, ($2))))
# Remove all python artifacts.
clean:
$(info [*] Destroying environment....)
rm -fr build/
rm -fr dist/
rm -f requirements.txt
find . -name '*.orig' -exec rm -f {} +
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
.PHONY: clean
install: _install_packages _install_dev_packages
.PHONY: install
uninstall:
$(info [*] Destroy entire virtualenv....)
@pipenv --rm
.PHONY: uninstall
# Lint python code.
lint:
$(info [*] Running python codestyle check....)
@pipenv run pycodestyle --max-line-length 100 --ignore E402,W503,E704 --statistics src/
.PHONY: lint
# Run the unit tests.
test: lint
$(info [*] Running pytest on tests/....)
@AWS_XRAY_CONTEXT_MISSING=LOG_ERROR pipenv run python -m pytest -s -v tests/
# Run the unit tests.
# unittest:
# @echo "Running unittests..."
# AWS_XRAY_CONTEXT_MISSING=LOG_ERROR pytest -s -v .
# .PHONY: unittest
# Run test coverage.
coverage:
$(info [*] Running test coverage on tests/....)
@AWS_XRAY_CONTEXT_MISSING=LOG_ERROR pipenv run python -m pytest --cov=src \
--cov-report term-missing --no-cov-on-fail --cov-fail-under 35 tests/ -v
.PHONY: coverage
build: _clone_service_to_build _install_deps
.PHONY: build
sam: _clone_service_to_build
sam local start-api
.PHONY: sam
# Create the CloudFormation stack.
create-pipeline:
@:$(call check_defined, OAUTH_TOKEN)
@echo "Creating Cloudformation Stack ${APP_NAME}-pipeline."
@aws cloudformation create-stack --stack-name ${APP_NAME}-pipeline --template-body file://pipeline.yaml --parameters \
ParameterKey=ApplicationName,ParameterValue=${APP_NAME} \
ParameterKey=ArtifactBucket,ParameterValue=workshop-tim \
ParameterKey=GitHubOAuthToken,ParameterValue=${OAUTH_TOKEN} \
ParameterKey=GitHubUser,ParameterValue=bogguard \
ParameterKey=GitHubRepository,ParameterValue=workshop-lambda \
ParameterKey=GitHubBranch,ParameterValue=master \
--region eu-west-1 --capabilities CAPABILITY_NAMED_IAM --output text
@echo "Waiting for Cloudformation stack to complete..."
@aws cloudformation wait stack-create-complete --region eu-west-1 --stack-name ${APP_NAME}-pipeline
@echo "Deployment complete!"
.PHONY: create-pipeline
# Update the CloudFormation stack.
update-pipeline:
@:$(call check_defined, OAUTH_TOKEN)
@echo "updating Cloudformation Stack ${APP_NAME}-pipeline."
@aws cloudformation update-stack --stack-name ${APP_NAME}-pipeline --template-body file://pipeline.yaml --parameters \
ParameterKey=ApplicationName,ParameterValue=${APP_NAME} \
ParameterKey=ArtifactBucket,ParameterValue=workshop-tim \
ParameterKey=GitHubOAuthToken,ParameterValue=${OAUTH_TOKEN} \
ParameterKey=GitHubUser,ParameterValue=bogguard \
ParameterKey=GitHubRepository,ParameterValue=workshop-lambda \
ParameterKey=GitHubBranch,ParameterValue=master \
--region eu-west-1 --capabilities CAPABILITY_NAMED_IAM --output text
@echo "Waiting for Cloudformation update stack to complete..."
@aws cloudformation wait stack-update-complete --region eu-west-1 --stack-name ${APP_NAME}-pipeline
@echo "Stack update complete!"
.PHONY: update-pipeline
# Delete the CloudFormation stack.
delete-pipeline:
@echo "Delete Cloudformation Stack ${APP_NAME}-pipeline."
@aws cloudformation delete-stack --region eu-west-1 --stack-name ${APP_NAME}-pipeline
@echo "Waiting for Cloudformation delete stack to complete..."
@aws cloudformation wait stack-delete-complete --region eu-west-1 --stack-name ${APP_NAME}-pipeline
@echo "Stack removed!"
.PHONY: delete-pipeline
###################
# Helpers #
###################
_install_packages:
$(info [*] Install required packages....)
@pipenv install
_install_dev_packages:
$(info [*] Install required dev-packages....)
@pipenv install -d
_install_deps:
$(info [*] Installing service dependencies....)
@test -d build/ || mkdir build/
@pipenv lock -r > requirements.txt
@pipenv run pip install \
--isolated \
--disable-pip-version-check \
-Ur requirements.txt -t build/
_clone_service_to_build:
$(info [*] Cloning '$(SERVICE)' to build directory....)
@test -d build/ || mkdir build/
cp -av src/* build/