-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
167 lines (147 loc) · 5.07 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
SHELL:=/bin/bash
.SILENT:
MAKEFLAGS += --no-print-directory
# Default action:
.DEFAULT_GOAL := cdk-synth
### Figure out the application variables:
# Do here instead of the cdk app, so they're not duplicated in both and
# avoid getting out of sync. Just pass them in
maturity ?= prod
# The _application_id and _base_stack_prefix are only here to have in one place,
# THEY'RE NOT MEANT TO BE MODIFIED:
ifeq ($(maturity),prod)
_application_id := "ContainerManager"
else
_application_id := "ContainerManager-$(maturity)"
endif
_base_stack_prefix := "$(_application_id)-BaseStack"
## Make sure any required env-var's are set (i.e with guard-STACK_NAME)
guard-%:
@ if [ "${${*}}" = "" ]; then \
echo "ERROR: Required variable '$*' is not set!"; \
echo " (either export it, or use 'make <target> $*=abc')"; \
exit -1; \
fi
#########################
## Generic CDK Helpers ##
#########################
##################
#### DEPLOY STUFF:
.PHONY := _cdk-deploy-helper
_cdk-deploy-helper: guard-stack-regix # empty config-file is okay here
echo "Deploying Stack..."
echo "Starting at: `date +'%-I:%M%P (%Ss)'`"
echo ""
cdk deploy "$(stack-regix)" \
--require-approval never \
--no-previous-parameters \
--context _application_id="$(_application_id)" \
--context _base_stack_prefix="$(_base_stack_prefix)" \
--context config-file="$(config-file)" \
--context maturity="$(maturity)" \
--context container-id="$(container-id)"
echo "Finished at: `date +'%-I:%M%P (%Ss)'`"
# Edit the base stack:
.PHONY := cdk-deploy-base
cdk-deploy-base:
$(MAKE) _cdk-deploy-helper stack-regix="$(_base_stack_prefix)-*"
# Edit everything BUT the base stack, within the config-file scope:
# (The base stack will still be updated as a 'Dependency Stack')
.PHONY := cdk-deploy-leaf
cdk-deploy-leaf: guard-config-file
echo "Config File: $(config-file)"
$(MAKE) _cdk-deploy-helper stack-regix="!$(_base_stack_prefix)-*"
###################
#### DESTROY STUFF:
.PHONY := _cdk-destroy-helper
_cdk-destroy-helper: guard-stack-regix # empty config-file is okay here
echo "Destroying Stack..."
echo "Starting at: `date +'%-I:%M%P (%Ss)'`"
echo ""
cdk destroy "$(stack-regix)" \
--force \
--context _application_id="$(_application_id)" \
--context _base_stack_prefix="$(_base_stack_prefix)" \
--context config-file="$(config-file)" \
--context maturity="$(maturity)" \
--context container-id="$(container-id)"
echo "Finished at: `date +'%-I:%M%P (%Ss)'`"
# Destroy the base stack
.PHONY := cdk-destroy-base
cdk-destroy-base:
$(MAKE) _cdk-destroy-helper stack-regix="$(_base_stack_prefix)-*"
# Destroy everything BUT the base stack, within the config-file scope:
# (The base stack will still be updated as a 'Dependency Stack')
.PHONY := cdk-destroy-leaf
cdk-destroy-leaf: guard-config-file
echo "Config File: $(config-file)"
$(MAKE) _cdk-destroy-helper stack-regix="!$(_base_stack_prefix)-*"
########################
#### SYNTH / LINT STUFF:
## Take all non-var input, remove the 'cdk-synth' beginning, and pass the rest to cdk synth as stack-names
## (Can do stuff like `make cdk-synth --config-file=./my-config.yaml stack2` to ONLY synth stack2)
# If the first argument is "cdk-synth"...
ifeq (cdk-synth,$(firstword $(MAKECMDGOALS)))
# use the rest as arguments for "cdk-synth"
STACKS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
$(eval $(STACKS):;@:)
endif
.PHONY := cdk-synth
cdk-synth:
if [[ -n "$(config-file)" ]]; then \
echo "Config File: $(config-file)"; \
else \
echo "No Config File"; \
echo " (Pass in with 'make cdk-synth config-file=<config>' to synth that stack too!)"; \
fi
echo "Synthesizing Stack..."
echo ""
cdk synth \
--context _application_id="$(_application_id)" \
--context _base_stack_prefix="$(_base_stack_prefix)" \
--context config-file="$(config-file)" \
--context maturity="$(maturity)" \
--context container-id="$(container-id)" \
$(STACKS)
.PHONY := pylint
pylint:
pylint $$(git ls-files '*.py')
###################
## Misc Commands ##
###################
.PHONY := aws-whoami
aws-whoami:
# Make sure you're in the right account
aws sts get-caller-identity \
--query "$${query:-Arn}" \
--output text
.PHONY := update-npm
# n: node version manager
# hash -r: Refresh shell to use the latest node version
update-npm:
echo "## Setting up non-root Install..."
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo "## Updating NPM Stuff..."
npm install -g npm@latest aws-cdk@latest
echo ""
.PHONY := update-python
update-python:
echo "Updating Python Stuff..."
python3 -m pip install --upgrade \
pip \
-r requirements.txt \
-r requirements-dev.txt
echo ""
.PHONY := update
update: update-npm update-python
.PHONY := cdk-bootstrap
# --app="": It can't synth without the right variables, so don't load it:
cdk-bootstrap:
echo "Bootstrapping/Updating CDKToolkit..." && \
export AWS_ACCOUNT_ID=$$( $(MAKE) aws-whoami query=Account ) && \
cdk bootstrap \
--app="" \
"aws://$${AWS_ACCOUNT_ID}/$$( aws configure get region )" \
"aws://$${AWS_ACCOUNT_ID}/us-east-1"