-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
114 lines (96 loc) · 3.5 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
include MakefileConstants.mk
#################
#
# Init Targets
#
#################
init-backend: check-py-virtualenv
pip install -q -r backend/requirements-dev.txt
#################
#
# Prerequisite checks
#
#################
.PHONY: check-py-virtualenv ## Verify python dev environment
check-py-virtualenv: $(PYTHON_VERIFICATION_FILE)
$(PYTHON_VERIFICATION_FILE):
@if [ -n "$(VIRTUAL_ENV)" ] ; then \
printf "$(INFO_COLOR)OK:$(NO_COLOR) python virtual env found at $(VIRTUAL_ENV) - all good!\n" ; \
date > $@ ; \
else \
printf "$(ERROR_COLOR)ERROR:$(NO_COLOR) python virtual env not found. Please install and configure a virtual env!\n" ; \
exit 1 ; \
fi
#################
#
# Deploy Targets
#
#################
.PHONY: deploy
deploy: build-layer sam-build check-environment-arg
sam deploy \
--s3-bucket ${service}-deployment \
--stack-name ${service}-$(environment) \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
--profile $(awsProfile) \
--parameter-overrides \
Service=${service} \
Environment=$(environment) \
Bucket=$(bucket) \
BucketRegion=$(region) \
BcoDmoOfficeURI=$(bcodmoOfficeURI) \
.PHONY: sam-build
sam-build:
sam build --use-container
# target only runs when requirements.txt is newer than package folder
PACKAGE_FOLDER := package
.PHONY: build-layer
build-layer: $(PACKAGE_FOLDER)
$(PACKAGE_FOLDER): backend/requirements.txt ## install requirements into $(PACKAGE_FOLDER) when requirements.txt is newer than the folder
rm -rf $(PACKAGE_FOLDER)
pip install --target package/python -r backend/requirements.txt
#################
#
# Cleanup
#
#################
.PHONY: clean
clean: clean-backend-deploy clean-tox clean-pyc
.PHONY: clean-backend-deploy
clean-backend-deploy:
rm -rf package
.PHONY: gone
gone: check-environment-arg
aws cloudformation delete-stack --stack-name ${service}-$(environment)
#################
#
# Helper Targets
#
#################
.PHONY: check-environment-arg
check-environment-arg:
@if [ -z "$${environment}" ] ; then make environment-not-set ; make cfn_help ; exit 1 ; fi
# Add an implicit guard for parameter input validation; use as target dependency guard-VARIABLE_NAME, e.g. guard-AWS_ACCESS_KEY_ID
.PHONY: %-not-set
%-not-set:
@if [ "${${*}}" = "" ]; then \
printf \
"$(ERROR_COLOR)ERROR:$(NO_COLOR) Variable [$(ERROR_COLOR)$*$(NO_COLOR)] not set.\n"; \
exit 1; \
fi
.PHONY: cfn_help
cfn_help: ## print help for make (deploy|remove) targets
@printf "\nmake (deploy|gone)\n"
@printf "Usage:\n"
@printf " make awsprofile=<aws-profile> environment=<dpp2prov-environment> bucket=<dataset-pipelines-bucket> region=<region-for-bucket> bcodmoOfficeURI=<linked-data-uri> deploy\n"
@printf "\n"
@printf "Required:\n"
@printf " awsProfile: The AWS credentials profile to deploy from.\n"
@printf " environment: dpp2prov environment, unique \"environment\" e.g. \"dev\" or \"prod\".\n"
@printf " bucket: AWS S3 bucket where dataset pipelines can be found.\n"
@printf " region: The AWS region for the S3 bucket of dataset pipelines.\n"
@printf " bcodmoOfficeURI: The Linked Data URI for the BCO-DMO Organization.\n"
@printf "\n"
.PHONY: help
help: ## Prints the names and descriptions of available targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'