-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
executable file
·68 lines (55 loc) · 2.24 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
# For interactive prompt
SHELL = /bin/bash
# Help
help:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null \
| awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' \
| egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort -r
# Default settings
DEFAULT_REGION := europe-west1
DEFAULT_DEPLOYMENTS_PATH := ./deployments
# When setting DM_SOFT_MODE environment variable
# the update targets will not create neither delete resources,
# only ABANDON on deletion and ACQUIRE existing on creation
ifeq (${DM_SOFT_MODE},1)
SOFT_FLAGS := --delete-policy ABANDON --create-policy ACQUIRE
endif
gcloud-config-rael-base:
gcloud config set project rael-base
gcloud config set compute/region ${DEFAULT_REGION}
# Deployment list
DEPLOYMENTS=$(shell \
find ${DEFAULT_DEPLOYMENTS_PATH}/* -type f -name '*.yaml' \
| sed "s:${DEFAULT_DEPLOYMENTS_PATH}/\(.*\).yaml:\1:g" \
)
# Target for getting the deployment variables from the file path/name
# The convention is ${project-id}/${folder}/${deployment-name}.yaml
.PHONY+=$(addprefix .dm-set-,$(DEPLOYMENTS))
$(addprefix .dm-set-,$(DEPLOYMENTS)):.dm-set-%:
$(eval project_id := $(firstword $(subst /, ,$*)))
$(eval dm_name := ${project_id}-$(lastword $(subst /, ,$*)))
$(eval dm_config := ${DEFAULT_DEPLOYMENTS_PATH}/$*.yaml)
# Target for creating the deployment
.PHONY+=$(addprefix dm-create-,$(DEPLOYMENTS))
$(addprefix dm-create-,$(DEPLOYMENTS)):dm-create-%:.dm-set-%
gcloud deployment-manager deployments \
create ${dm_name} \
--config ${dm_config} \
--project ${project_id}
# Target for updating the deployment after previewing the changes
# Requires a manual user confirmation after the preview
.PHONY+=$(addprefix dm-update-,$(DEPLOYMENTS))
$(addprefix dm-update-,$(DEPLOYMENTS)):dm-update-%:.dm-set-% dm-preview-%
@echo -n "Ready to update, are you sure? Ctrl+C to cancel " \
&& read ans
gcloud deployment-manager deployments \
update ${dm_name} \
--project ${project_id} $(SOFT_FLAGS)
# Target for previewing the deployment
.PHONY+=$(addprefix dm-preview-,$(DEPLOYMENTS))
$(addprefix dm-preview-,$(DEPLOYMENTS)):dm-preview-%:.dm-set-%
gcloud deployment-manager deployments \
update ${dm_name} \
--config ${dm_config} \
--project ${project_id} \
--preview $(SOFT_FLAGS)