-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
247 lines (222 loc) · 7.21 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# ---------------------------
SELF_DIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
DIST_DIR := ${SELF_DIR}/dist
SERVED_BY_CUMULUS_API ?= "true"
.SILENT:
.ONESHELL:
.PHONY: clean container-shell test test-watch daac workflows
# ---------------------------
define banner =
echo
echo "========================================"
if command -v figlet 2>/dev/null; then
figlet $@
elif command -v banner 2>/dev/null; then
banner $@
else
echo "Making: $@"
fi
echo "========================================"
endef
# ---------------------------
${DIST_DIR}:
mkdir ${DIST_DIR}
# ---------------------------
clean:
rm -rf ${DIST_DIR}
find workflows -name "*.pyc" -type f -delete
find workflows -name __pycache__ -type d -delete
# ---------------------------
image: Dockerfile
docker build -f Dockerfile -t cirrus-daac .
container-shell:
docker run -it --rm \
--user `id -u` \
-v ${PWD}:/CIRRUS-DAAC \
-v ~/.aws:/root/.aws \
--name=cirrus-daac \
cirrus-daac
# ---------------------------
test:
cd workflows
flake8
pytest -vv
test-watch:
cd workflows
ptw -c --beforerun flake8
# ---------------------------
%-init:
$(banner)
cd $*
rm -f .terraform/environment
terraform init -reconfigure -input=false -no-color \
-backend-config "region=${AWS_REGION}" \
-backend-config "bucket=${DEPLOY_NAME}-cumulus-${MATURITY}-tf-state-${AWS_ACCOUNT_ID_LAST4}" \
-backend-config "key=$*/terraform.tfstate" \
-backend-config "dynamodb_table=${DEPLOY_NAME}-cumulus-${MATURITY}-tf-locks"
terraform workspace new ${DEPLOY_NAME} 2>/dev/null || terraform workspace select ${DEPLOY_NAME}
modules = daac workflows rds
init-modules := $(modules:%-init=%)
# ---------------------------
daac: daac-init
$(banner)
cd $@
if [ -f "variables/${MATURITY}.tfvars" ]
then
echo "***************************************************************"
export VARIABLES_OPT="-var-file=variables/${MATURITY}.tfvars"
echo "Found maturity-specific variables: $$VARIABLES_OPT"
echo "***************************************************************"
fi
terraform apply \
$$VARIABLES_OPT \
-input=false \
-auto-approve \
-no-color
# ---------------------------
plan-daac: daac-init
$(banner)
cd daac
if [ -f "variables/${MATURITY}.tfvars" ]
then
echo "***************************************************************"
export VARIABLES_OPT="-var-file=variables/${MATURITY}.tfvars"
echo "Found maturity-specific variables: $$VARIABLES_OPT"
echo "***************************************************************"
fi
terraform plan \
$$VARIABLES_OPT \
-input=false \
-no-color
# ---------------------------
${DIST_DIR}/lambda_dependencies_layer.zip: ${DIST_DIR} workflows/requirements.txt
mkdir -p ${DIST_DIR}/python
cd ${DIST_DIR}/python
pip3 install -r ${SELF_DIR}/workflows/requirements.txt --target .
cd ..
zip -r ${DIST_DIR}/lambda_dependencies_layer.zip python/*
${DIST_DIR}/lambdas.zip: ${DIST_DIR} workflows/lambdas/*.py
cd workflows
zip ${DIST_DIR}/lambdas.zip lambdas/*.py
artifacts: \
${DIST_DIR}/lambda_dependencies_layer.zip \
${DIST_DIR}/lambdas.zip
workflows: workflows-init artifacts
$(banner)
cd $@
terraform apply -var 'DIST_DIR=${DIST_DIR}' -input=false -auto-approve -no-color
plan-workflows: workflows-init artifacts
$(banner)
cd workflows
terraform plan -var 'DIST_DIR=${DIST_DIR}' -input=false -no-color
destroy-workflows: workflows-init
$(banner)
cd workflows
terraform destroy -var 'DIST_DIR=${DIST_DIR}' -input=false -auto-approve -no-color
# ---------------------------
rds: rds-init
$(banner)
cd $@
if [ -f "secrets/${MATURITY}.tfvars" ]
then
echo "***************************************************************"
export SECRETS_OPT="-var-file=secrets/${MATURITY}.tfvars"
echo "Found maturity-specific secrets: $$SECRETS_OPT"
echo "***************************************************************"
fi
if [ -f "variables/${MATURITY}.tfvars" ]
then
echo "***************************************************************"
export VARIABLES_OPT="-var-file=variables/${MATURITY}.tfvars"
echo "Found maturity-specific variables: $$VARIABLES_OPT"
echo "***************************************************************"
fi
terraform apply \
$$SECRETS_OPT \
$$VARIABLES_OPT \
-input=false \
-auto-approve \
-no-color
# ---------------------------
plan-rds: rds-init
$(banner)
cd rds
if [ -f "secrets/${MATURITY}.tfvars" ]
then
echo "***************************************************************"
export SECRETS_OPT="-var-file=secrets/${MATURITY}.tfvars"
echo "Found maturity-specific secrets: $$SECRETS_OPT"
echo "***************************************************************"
fi
if [ -f "variables/${MATURITY}.tfvars" ]
then
echo "***************************************************************"
export VARIABLES_OPT="-var-file=variables/${MATURITY}.tfvars"
echo "Found maturity-specific variables: $$VARIABLES_OPT"
echo "***************************************************************"
fi
terraform plan \
$$SECRETS_OPT \
$$VARIABLES_OPT \
-input=false \
-no-color
# ---------------------------
destroy-rds: rds-init
$(banner)
cd rds
if [ -f "secrets/${MATURITY}.tfvars" ]
then
echo "***************************************************************"
export SECRETS_OPT="-var-file=secrets/${MATURITY}.tfvars"
echo "Found maturity-specific secrets: $$SECRETS_OPT"
echo "***************************************************************"
fi
if [ -f "variables/${MATURITY}.tfvars" ]
then
echo "***************************************************************"
export VARIABLES_OPT="-var-file=variables/${MATURITY}.tfvars"
echo "Found maturity-specific variables: $$VARIABLES_OPT"
echo "***************************************************************"
fi
export TF_CMD="terraform destroy \
$$VARIABLES_OPT \
$$SECRETS_OPT \
-input=false \
-no-color \
-auto-approve"
eval $$TF_CMD
# ---------------------------
pcrs: workflows/providers/* workflows/collections/* workflows/rules/*
if [ -z ${cumulus_id_rsa+x} ]; then echo "Env Var \$cumulus_id_rsa is not set, using ~/.ssh/id_rsa"; fi
scripts/deploy-pcrs.sh ${SELF_DIR}/workflows ${cumulus_id_rsa-"~/.ssh/id_rsa"}
# ------ Cumulus Dashboard ------
# Environment variables:
# - DASHBOARD_DIR: Directory where the dashboard source code is checked out
# We could get more granular with the dependencies here, but using the
# dashboard directory is probably fine since we aren't developing it.
${DASHBOARD_DIR}/dist: ${DASHBOARD_DIR} cumulus-init
if [ "${MATURITY}" = "sbx" ]; then
export SERVED_BY_CUMULUS_API=true
fi
export DAAC_NAME=${DEPLOY_NAME}
export STAGE=${MATURITY}
export HIDE_PDR=false
export LABELS=daac
export AUTH_METHOD=launchpad
if [ -z "${APIROOT}" ]; then
export APIROOT=$(shell cd cumulus && terraform output archive_api_uri)
fi
cd $(DASHBOARD_DIR)
@echo "SERVED_BY_CUMULUS_API='$$SERVED_BY_CUMULUS_API'"
@echo "DAAC_NAME='$$DAAC_NAME'"
@echo "STAGE='$$STAGE'"
@echo "HIDE_PDR='$$HIDE_PDR'"
@echo "LABELS='$$LABELS'"
@echo "AUTH_METHOD='$$AUTH_METHOD'"
@echo "APIROOT='$$APIROOT'"
npm install --no-optional --cache $(DASHBOARD_DIR)/.npm
npm run build
.PHONY: dashboard
dashboard: $(DASHBOARD_DIR)/dist
$(banner)
aws s3 sync $(DASHBOARD_DIR)/dist s3://${DEPLOY_NAME}-cumulus-${MATURITY}-dashboard --delete