-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
425 lines (375 loc) · 18.9 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
ECR_REPO_NAME := wormbase/names
EB_APP_ENV_FILE := app-env.config
PROJ_NAME ?= wormbase-names-dev
LOCAL_GOOGLE_REDIRECT_URI := "http://lvh.me:3000"
AWS_DEFAULT_REGION ?= us-east-1
ifeq ($(PROJ_NAME), wormbase-names)
WB_DB_URI ?= "datomic:ddb://${AWS_DEFAULT_REGION}/WSNames/wormbase"
GOOGLE_REDIRECT_URI ?= "https://names.wormbase.org"
APP_PROFILE ?= "prod"
else ifeq ($(PROJ_NAME), wormbase-names-test)
WB_DB_URI ?= "datomic:ddb://${AWS_DEFAULT_REGION}/WSNames-test-15/wormbase"
GOOGLE_REDIRECT_URI ?= "https://test-names.wormbase.org"
APP_PROFILE ?= "test"
else
WB_DB_URI ?= "datomic:ddb-local://localhost:8000/WBNames_local/wormbase"
# Ensure GOOGLE_REDIRECT_URI is defined appropriately as an env variable or CLI argument
# if intended for AWS deployment (default is set for local execution)
GOOGLE_REDIRECT_URI ?= ${LOCAL_GOOGLE_REDIRECT_URI}
APP_PROFILE ?= "dev"
endif
STORE_SECRETS_FILE = secrets.makedef
APP_JAR_PATH ?= build/app.jar
PORT := 3000
WB_ACC_NUM := 357210185381
ECR_URI := ${WB_ACC_NUM}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com
ECR_REPO_URI := ${ECR_URI}/${ECR_REPO_NAME}
ECR_IMAGE_URI = ${ECR_REPO_URI}:${VERSION_TAG}
# Define AWS (EB) CLI base commands as appropriate
AWS_CLI_BASE := aws
EB_CLI_BASE := eb
ifneq (${AWS_EB_PROFILE},)
EB_CLI_BASE := export AWS_EB_PROFILE=${AWS_EB_PROFILE} && ${EB_CLI_BASE}
ifeq (${AWS_PROFILE},)
AWS_CLI_BASE := ${AWS_CLI_BASE} --profile ${AWS_EB_PROFILE}
endif
endif
ifneq (${AWS_PROFILE},)
AWS_CLI_BASE := ${AWS_CLI_BASE} --profile ${AWS_PROFILE}
ifeq (${AWS_EB_PROFILE},)
EB_CLI_BASE := export AWS_EB_PROFILE=${AWS_PROFILE} && ${EB_CLI_BASE}
endif
endif
define target-help
$1
$2
endef
define print-help
$(if $(need-help),$(info $(call target-help,$1,$2)))
endef
need-help := $(filter help,$(MAKECMDGOALS))
help: ; @echo $(if $(need-help),,\
Type \'$(MAKE)$(dash-f) help\' to get help)
source-secrets:
ifneq ($(SECRETS_SRC), )
@echo "Sourcing secrets file ${SECRETS_SRC}"
$(eval SECRETS_CONTENT := $(shell cat "${SECRETS_SRC}"))
$(foreach secret,${SECRETS_CONTENT},$(eval ${secret}))
endif
.PHONY: ENV.VERSION_TAG
ENV.VERSION_TAG: \
$(call print-help,ENV.VERSION_TAG,\
Extract the VERSION_TAG env variables for make targets from git tags if undefined.)
$(eval REVISION_NAME_CMD = git describe --tags)
ifeq (${VERSION_TAG},)
# If REF_NAME is defined, convert provided ref in matching name
# (ref could be a tagname, a reference like "HEAD", branch-names...)
ifneq (${REF_NAME},)
$(eval REVISION_NAME_CMD = ${REVISION_NAME_CMD} ${REF_NAME})
# Else, assume working-directory deployment
else
$(eval REVISION_NAME_CMD = ${REVISION_NAME_CMD} --dirty=-DIRTY)
endif
$(eval VERSION_TAG = $(shell ${REVISION_NAME_CMD} | sed 's/^wormbase-names-//'))
$(call check_defined, VERSION_TAG, Ensure your working directory is a\
git clone of the repository)
@echo "Retrieved VERSION_TAG '${VERSION_TAG}' from git tags."
else
@echo "Using predefined VERSION_TAG '${VERSION_TAG}'."
endif
.PHONY: show-version
show-version: ENV.VERSION_TAG \
$(call print-help,show-version,\
Show the current application version.)
@echo "${VERSION_TAG}"
build/:
mkdir build/
build/datomic-pro-1.0.6165.zip:
@echo "Downloading datomic bundle from S3."
@${AWS_CLI_BASE} s3 cp s3://wormbase/datomic-pro/distro/datomic-pro-1.0.6165.zip build/
.PHONY: build-docker-image
build-docker-image: build/ ENV.VERSION_TAG ${STORE_SECRETS_FILE} build/datomic-pro-1.0.6165.zip \
$(call print-help,build-docker-image,\
Build the docker image from the current git revision.)
$(eval DOCKER_CMD := docker build -t ${ECR_REPO_NAME}:${VERSION_TAG})
ifeq (${APP_PROFILE},prod)
$(eval DOCKER_CMD := ${DOCKER_CMD} --no-cache --pull)
endif
@${DOCKER_CMD} \
--secret id=make-secrets-file,src=${STORE_SECRETS_FILE} \
.
@rm ${STORE_SECRETS_FILE}
.PHONY: docker-build-image
docker-build-image: build-docker-image \
$(call print-help,docker-build-image,\
Alias for build-docker-image.)
.PHONY: build-ui
build-ui: ENV.GOOGLE_OAUTH_CLIENT_ID \
$(call print-help,build-ui,\
Build JS and CSS file for release.)
@ export REACT_APP_GOOGLE_OAUTH_CLIENT_ID=${GOOGLE_OAUTH_CLIENT_ID} && \
echo "Building UI using APP_PROFILE: '${APP_PROFILE}'" && \
./scripts/build-ui.sh ${APP_PROFILE}
.PHONY: clean
clean: \
$(call print-help,clean,\
Remove the locally built UI and API artefacts.)
@rm -f ${APP_JAR_PATH}
@rm -rf client/build/*
${APP_JAR_PATH}: build/ \
$(call print-help,${APP_JAR_PATH},\
Build the jar file.)
@./scripts/build-appjar.sh ${APP_JAR_PATH}
build-app-jar: ${APP_JAR_PATH} \
$(call print-help,build-app-jar,\
Build the jar file.)
.PHONY: build-local
build-local: clean build-ui build-app-jar \
$(call print-help,build-local,\
Build UI and app JAR (locally).)
.PHONY: docker-ecr-login
docker-ecr-login: \
$(call print-help,docker-ecr-login [AWS_PROFILE=<profile_name>],\
Login to ECR.)
${AWS_CLI_BASE} ecr get-login-password | docker login -u AWS --password-stdin https://${ECR_URI}
.PHONY: docker-push-ecr
docker-push-ecr: docker-ecr-login \
$(call print-help,docker-push-ecr,\
Push the image tagged with the current git revision to ECR.)
@docker push ${ECR_IMAGE_URI}
.PHONY: docker-tag
docker-tag: ENV.VERSION_TAG \
$(call print-help,docker-tag,\
Tag the image with current git revision and ':latest' alias.)
@docker tag ${ECR_REPO_NAME}:${VERSION_TAG} ${ECR_IMAGE_URI}
@docker tag ${ECR_REPO_NAME}:${VERSION_TAG} ${ECR_REPO_URI}
.PHONY: eb-def-app-env
eb-def-app-env: google-oauth2-secrets caltech-api-secrets ENV.VERSION_TAG \
$(call print-help,eb-def-app-env \
[WB_DB_URI=<datomic-db-uri>] [GOOGLE_REDIRECT_URI=<google-redirect-uri>],\
Define the ElasticBeanStalk app-environment config file.)
ifndef WB_DB_URI
$(error WB_DB_URI not set! Define datomic-DB-URI as WB_DB_URI arg)
endif
ifndef GOOGLE_REDIRECT_URI
$(error GOOGLE_REDIRECT_URI not set! Define the google redirect-uri to use for authentication as GOOGLE_REDIRECT_URI arg)
endif
@cp ebextensions-templates/${EB_APP_ENV_FILE} .ebextensions/
sed -i -r 's~(WB_DB_URI:\s+)".*"~\1"'"${WB_DB_URI}"'"~' .ebextensions/${EB_APP_ENV_FILE}
sed -i -r 's~(API_GOOGLE_OAUTH_CLIENT_ID:\s+)".*"~\1"'"${GOOGLE_OAUTH_CLIENT_ID}"'"~' .ebextensions/${EB_APP_ENV_FILE}
sed -i -r 's~(API_GOOGLE_OAUTH_CLIENT_SECRET:\s+)".*"~\1"'"${GOOGLE_OAUTH_CLIENT_SECRET}"'"~' .ebextensions/${EB_APP_ENV_FILE}
sed -i -r 's~(GOOGLE_REDIRECT_URI:\s+)".*"~\1"'"${GOOGLE_REDIRECT_URI}"'"~' .ebextensions/${EB_APP_ENV_FILE}
sed -i -r 's~(CALTECH_API_URL:\s+)".*"~\1"'"${CALTECH_API_URL}"'"~' .ebextensions/${EB_APP_ENV_FILE}
sed -i -r 's~(CALTECH_API_USER:\s+)".*"~\1"'"${CALTECH_API_USER}"'"~' .ebextensions/${EB_APP_ENV_FILE}
SED_SAFE="$(shell printf '%s\n' "${CALTECH_API_PASSWORD}" | sed -e 's~[\~&]~\\&~g')" && \
sed -i -r 's~(CALTECH_API_PASSWORD:\s+)".*"~\1"'"$$SED_SAFE"'"~' .ebextensions/${EB_APP_ENV_FILE}
sed -i -r 's~(WB_NAMES_RELEASE: ).+~\1'${VERSION_TAG}'~' .ebextensions/${EB_APP_ENV_FILE}
.PHONY: eb-create
eb-create: eb-def-app-env \
$(call print-help,eb-create [AWS(_EB)?_PROFILE=<profile_name>] \
[AWS_IAM_UNAME=<iam_username>] [PROJ_NAME=<eb-env-name>] [WB_DB_URI=<datomic-db-uri>] \
[GOOGLE_REDIRECT_URI=<google-redirect-uri>],\
Create an ElasticBeanStalk environment using the Docker platform.)
$(eval AWS_IAM_UNAME ?= $(shell test ${AWS_IAM_UNAME} && echo ${AWS_IAM_UNAME}\
|| ${AWS_CLI_BASE} iam get-user --query "User.UserName"))
@test ${AWS_IAM_UNAME} || (\
echo "Failed to retrieve IAM user-name. Define IAM username as AWS_IAM_UNAME arg." \
&& exit 1 \
)
@${EB_CLI_BASE} create ${PROJ_NAME} \
--region=${AWS_DEFAULT_REGION} \
--tags="CreatedBy=${AWS_IAM_UNAME},Role=RestAPI" \
--cname="${PROJ_NAME}" \
-p docker \
--elb-type application \
--vpc.id vpc-8e0087e9 --vpc.ec2subnets subnet-1ce4c744,subnet-a33a2bd5 --vpc.elbsubnets subnet-1ce4c744,subnet-a33a2bd5 \
--vpc.elbpublic --vpc.publicip
.PHONY: eb-deploy
eb-deploy: eb-def-app-env \
$(call print-help,eb-deploy [PROJ_NAME=<eb-env-name>] \
[AWS(_EB)?_PROFILE=<profile_name>] [WB_DB_URI=<datomic-db-uri>] \
[GOOGLE_REDIRECT_URI=<google-redirect-uri>],\
Deploy the application using ElasticBeanstalk.)
@${EB_CLI_BASE} deploy ${PROJ_NAME}
.PHONY: eb-env
eb-setenv: \
$(call print-help,eb-env [AWS(_EB)_PROFILE=<profile_name>] [PROJ_NAME=<eb-env-name>] \
[WB_DB_URI=<datomic-uri>] [GOOGLE_REDIRECT_URI=<google-redirect-uri>],\
Set enviroment variables for the ElasticBeanStalk environment.)
@${EB_CLI_BASE} setenv \
WB_DB_URI="${WB_DB_URI}" \
GOOGLE_REDIRECT_URI="${GOOGLE_REDIRECT_URI}" \
_JAVA_OPTIONS="-Xmx14g" \
AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \
AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \
AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" \
-e "${PROJ_NAME}"
.PHONY: eb-local
eb-local: docker-ecr-login \
$(call print-help,eb-local [AWS(_EB)_PROFILE=<profile_name>] [PORT=<port>] \
[WB_DB_URI=<datomic-uri>] [GOOGLE_REDIRECT_URI=<google-redirect-uri>],\
Runs the ElasticBeanStalk/docker build and run locally.)
@${EB_CLI_BASE} local run --envvars PORT=${PORT},WB_DB_URI=${WB_DB_URI},GOOGLE_REDIRECT_URI=${GOOGLE_REDIRECT_URI}
#Note: the run-docker command can currently only be used with non-local WB_DB_URI value.
# Current setup fails to connect to local datomic DB (on host, outside of container)
# from within the application container.
# Making the host's "localhost" accessible within the container as "host.docker.internal"
# through the following options in the `docker run` command makes the DB URI accessible
# from within the container, but the transactor still fails to be accessible.
# -e WB_DB_URI=datomic:ddb-local://host.docker.internal:8000/WBNames_local/wormbase
# --add-host=host.docker.internal:host-gateway
.PHONY: run-docker
run-docker: ENV.VERSION_TAG clean-docker-run \
$(call print-help,run [PORT=<port>] [PROJ_NAME=<docker-project-name>] \
[WB_DB_URI=<datomic-uri>] [GOOGLE_REDIRECT_URI=<google-redirect-uri>],\
Run the application docker container (locally).)
$(eval RUN_CMD = docker run \
--name ${PROJ_NAME} \
--publish-all=true \
--publish ${PORT}:${PORT} \
--detach \
-e WB_DB_URI=${WB_DB_URI} \
-e GOOGLE_REDIRECT_URI=${GOOGLE_REDIRECT_URI} \
-e PORT=${PORT} \
-e AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION})
ifneq (${AWS_ACCESS_KEY_ID},)
ifneq (${AWS_SECRET_ACCESS_KEY},)
$(eval RUN_CMD = ${RUN_CMD} -e AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY})
$(eval RUN_CMD = ${RUN_CMD} -e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID})
ifneq (${AWS_SESSION_TOKEN},)
$(eval RUN_CMD = ${RUN_CMD} -e AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN})
endif
else
@echo 'ENV var "AWS_ACCESS_KEY_ID" is defined but "AWS_SECRET_ACCESS_KEY" is not. Either define both or none.' >&2
@exit 1
endif
else
ifneq (${AWS_PROFILE},)
$(eval RUN_CMD = ${RUN_CMD} -e AWS_PROFILE=${AWS_PROFILE} -v ~/.aws:/root/.aws)
endif
endif
${RUN_CMD} ${ECR_REPO_NAME}:${VERSION_TAG}
.PHONY: clean-docker-run
clean-docker-run: \
$(call print-help,clean-docker-run [PROJ_NAME=<docker-project-name>],\
Stop and remove the docker container (if running).)
# Stop if running container found
@echo $(if $(shell docker ps -q --filter name=${PROJ_NAME}),$(shell docker stop ${PROJ_NAME})) > /dev/null
# Remove if stopped container found
@echo $(if $(shell docker ps -a -q --filter name=${PROJ_NAME}),$(shell docker rm ${PROJ_NAME})) > /dev/null
.PHONY: deploy-ecr
deploy-ecr: build-docker-image docker-tag docker-push-ecr
$(call print-help,deploy-ecr,\
Deploy the application to the AWS container registry.)
.PHONY: vc-release
vc-release: ENV.VERSION_TAG \
$(call print-help,vc-release LEVEL=<major|minor|patch>,\
Perform the Version Control tasks to release the applicaton.)
clj -A:release --without-sign ${LEVEL}
.PHONY: release
release: ENV.VERSION_TAG deploy-ecr \
$(call print-help,release [AWS_PROFILE=<profile_name>] [REF_NAME=<tag-or-gitref>],\
Release the applicaton.)
.PHONY: run-tests
run-tests: google-oauth2-secrets caltech-api-secrets \
$(call print-help,run-tests,\
Run all tests.)
@ export API_GOOGLE_OAUTH_CLIENT_ID="${GOOGLE_OAUTH_CLIENT_ID}" && \
export API_GOOGLE_OAUTH_CLIENT_SECRET="${GOOGLE_OAUTH_CLIENT_SECRET}" && \
export CALTECH_API_URL="${CALTECH_API_URL}" && \
export CALTECH_API_USER="${CALTECH_API_USER}" && \
export CALTECH_API_PASSWORD="${CALTECH_API_PASSWORD}" && \
export GOOGLE_REDIRECT_URI="${LOCAL_GOOGLE_REDIRECT_URI}" && \
clojure -A:datomic-pro:logging:webassets:dev:test:run-tests
.PHONY: run-dev-webserver
run-dev-webserver: PORT := 4010
run-dev-webserver: google-oauth2-secrets caltech-api-secrets \
$(call print-help,run-dev-webserver PORT=<port> WB_DB_URI=<datomic-uri> \
GOOGLE_REDIRECT_URI=<google-redirect-uri>,\
Run a local development webserver.)
@ export WB_DB_URI=${WB_DB_URI} && export PORT=${PORT} && \
export GOOGLE_REDIRECT_URI="${GOOGLE_REDIRECT_URI}" && \
export API_GOOGLE_OAUTH_CLIENT_ID="${GOOGLE_OAUTH_CLIENT_ID}" && \
export API_GOOGLE_OAUTH_CLIENT_SECRET="${GOOGLE_OAUTH_CLIENT_SECRET}" && \
export CALTECH_API_URL="${CALTECH_API_URL}" && \
export CALTECH_API_USER="${CALTECH_API_USER}" && \
export CALTECH_API_PASSWORD="${CALTECH_API_PASSWORD}" && \
clj -A:logging:datomic-pro:webassets:dev -m wormbase.names.service
.PHONY: run-dev-ui
run-dev-ui: google-oauth2-secrets\
$(call print-help,run-dev-ui [REACT_APP_GOOGLE_OAUTH_CLIENT_ID=<google-client-id>] \
Run a local development UI.)
@export REACT_APP_GOOGLE_OAUTH_CLIENT_ID=${GOOGLE_OAUTH_CLIENT_ID} && \
cd client/ && \
. $(HOME)/.nvm/nvm.sh && nvm use && \
npm install && \
npm run start
.PHONY: ENV.GOOGLE_OAUTH_CLIENT_ID
ENV.GOOGLE_OAUTH_CLIENT_ID: source-secrets \
$(call print-help,ENV.GOOGLE_OAUTH_CLIENT_ID,\
Retrieve the GOOGLE_OAUTH_CLIENT_ID env variable for make targets from aws ssm if undefined.)
$(eval ACTION_MSG := $(if ${GOOGLE_OAUTH_CLIENT_ID},"Using predefined GOOGLE_OAUTH_CLIENT_ID.","Retrieving GOOGLE_OAUTH_CLIENT_ID from AWS SSM (APP_PROFILE '${APP_PROFILE}')."))
@echo ${ACTION_MSG}
$(if ${GOOGLE_OAUTH_CLIENT_ID},,$(eval GOOGLE_OAUTH_CLIENT_ID := $(shell ${AWS_CLI_BASE} ssm get-parameter --name "/name-service/${APP_PROFILE}/google-oauth2-app-config/client-id" --query "Parameter.Value" --output text --with-decryption)))
$(call check_defined, GOOGLE_OAUTH_CLIENT_ID, Check the defined APP_PROFILE value\
and ensure the AWS_PROFILE variable is appropriately defined)
.PHONY: ENV.GOOGLE_OAUTH_CLIENT_SECRET
ENV.GOOGLE_OAUTH_CLIENT_SECRET: source-secrets \
$(call print-help,ENV.GOOGLE_OAUTH_CLIENT_SECRET,\
Retrieve the GOOGLE_OAUTH_CLIENT_SECRET env variable for make targets from aws ssm if undefined.)
$(eval ACTION_MSG := $(if ${GOOGLE_OAUTH_CLIENT_SECRET},"Using predefined GOOGLE_OAUTH_CLIENT_SECRET.","Retrieving GOOGLE_OAUTH_CLIENT_SECRET from AWS SSM (APP_PROFILE '${APP_PROFILE}')."))
@echo ${ACTION_MSG}
$(if ${GOOGLE_OAUTH_CLIENT_SECRET},,$(eval GOOGLE_OAUTH_CLIENT_SECRET := $(shell ${AWS_CLI_BASE} ssm get-parameter --name "/name-service/${APP_PROFILE}/google-oauth2-app-config/client-secret" --query "Parameter.Value" --output text --with-decryption)))
$(call check_defined, GOOGLE_OAUTH_CLIENT_SECRET, Check the defined APP_PROFILE value\
and ensure the AWS_PROFILE variable is appropriately defined)
.PHONY: ENV.CALTECH_API_URL
ENV.CALTECH_API_URL: \
$(call print-help,ENV.CALTECH_API_URL,\
Retrieve the CALTECH_API_URL env variable for make targets from aws ssm if undefined.)
$(eval ACTION_MSG := $(if ${CALTECH_API_URL},"Using predefined CALTECH_API_URL.","Retrieving CALTECH_API_URL from AWS SSM (APP_PROFILE '${APP_PROFILE}')."))
@echo ${ACTION_MSG}
$(if ${CALTECH_API_URL},,$(eval CALTECH_API_URL := $(shell ${AWS_CLI_BASE} ssm get-parameter --name "/name-service/${APP_PROFILE}/caltech-api-config/url" --query "Parameter.Value" --output text --with-decryption)))
$(call check_defined, CALTECH_API_URL, Check the defined APP_PROFILE value\
and ensure the AWS_PROFILE variable is appropriately defined)
.PHONY: ENV.CALTECH_API_USER
ENV.CALTECH_API_USER: \
$(call print-help,ENV.CALTECH_API_USER,\
Retrieve the CALTECH_API_USER env variable for make targets from aws ssm if undefined.)
$(eval ACTION_MSG := $(if ${CALTECH_API_USER},"Using predefined CALTECH_API_USER.","Retrieving CALTECH_API_USER from AWS SSM (APP_PROFILE '${APP_PROFILE}')."))
@echo ${ACTION_MSG}
$(if ${CALTECH_API_USER},,$(eval CALTECH_API_USER := $(shell ${AWS_CLI_BASE} ssm get-parameter --name "/name-service/${APP_PROFILE}/caltech-api-config/username" --query "Parameter.Value" --output text --with-decryption)))
$(call check_defined, CALTECH_API_USER, Check the defined APP_PROFILE value\
and ensure the AWS_PROFILE variable is appropriately defined)
.PHONY: ENV.CALTECH_API_PASSWORD
ENV.CALTECH_API_PASSWORD: \
$(call print-help,ENV.CALTECH_API_PASSWORD,\
Retrieve the CALTECH_API_PASSWORD env variable for make targets from aws ssm if undefined.)
$(eval ACTION_MSG := $(if ${CALTECH_API_PASSWORD},"Using predefined CALTECH_API_PASSWORD.","Retrieving CALTECH_API_PASSWORD from AWS SSM (APP_PROFILE '${APP_PROFILE}')."))
@echo ${ACTION_MSG}
$(if ${CALTECH_API_PASSWORD},,$(eval CALTECH_API_PASSWORD := $(shell ${AWS_CLI_BASE} ssm get-parameter --name "/name-service/${APP_PROFILE}/caltech-api-config/password" --query "Parameter.Value" --output text --with-decryption)))
$(call check_defined, CALTECH_API_PASSWORD, Check the defined APP_PROFILE value\
and ensure the AWS_PROFILE variable is appropriately defined)
.PHONY: google-oauth2-secrets
google-oauth2-secrets: ENV.GOOGLE_OAUTH_CLIENT_ID ENV.GOOGLE_OAUTH_CLIENT_SECRET \
$(call print-help,google-oauth2-secrets,\
Store the Google oauth2 client details as env variables.)
.PHONY: caltech-api-secrets
caltech-api-secrets: ENV.CALTECH_API_URL ENV.CALTECH_API_USER ENV.CALTECH_API_PASSWORD \
$(call print-help,caltech-api-secrets,\
Store the Caltech API details as env variables.)
${STORE_SECRETS_FILE}: google-oauth2-secrets
@install -m 600 /dev/null ${STORE_SECRETS_FILE}
@echo "GOOGLE_OAUTH_CLIENT_ID:=${GOOGLE_OAUTH_CLIENT_ID}" >> ${STORE_SECRETS_FILE}
@echo "GOOGLE_OAUTH_CLIENT_SECRET:=${GOOGLE_OAUTH_CLIENT_SECRET}" >> ${STORE_SECRETS_FILE}
# Check that given variables are set and all have non-empty values,
# die with an error otherwise.
#
# Params:
# 1. Variable name(s) to test.
# 2. (optional) Error message to print.
check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Failed to define $1. $(if $2, $2)))