This repository has been archived by the owner on Apr 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.Makefile
122 lines (91 loc) · 3.49 KB
/
app.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
ifndef __APP_MAKEFILE__
__APP_MAKEFILE__ := included
makefile_dir := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
include $(makefile_dir)/common.Makefile
include $(makefile_dir)/var.Makefile
# Extracts the name property from APP_PARAMETERS.
define name_parameter
$(shell echo '$(APP_PARAMETERS)' \
| docker run -i --entrypoint=/bin/print_config.py --rm $(APP_DEPLOYER_IMAGE) --values_mode stdin --xtype NAME)
endef
# Extracts the namespace property from APP_PARAMETERS.
define namespace_parameter
$(shell echo '$(APP_PARAMETERS)' \
| docker run -i --entrypoint=/bin/print_config.py --rm $(APP_DEPLOYER_IMAGE) --values_mode stdin --xtype NAMESPACE)
endef
# Combines APP_PARAMETERS and APP_TEST_PARAMETERS.
define combined_parameters
$(shell echo '$(APP_PARAMETERS)' '$(APP_TEST_PARAMETERS)' \
| docker run -i --entrypoint=/usr/bin/jq --rm $(APP_DEPLOYER_IMAGE) -s '.[0] * .[1]')
endef
##### Helper targets #####
.build/app: | .build
mkdir -p "$@"
# Always update the dev script to make sure it's up to date.
# There isn't currently a way to detect if the dev container has changed.
.PHONY: .build/app/dev
.build/app/dev: .build/var/MARKETPLACE_TOOLS_TAG \
| .build/app
docker run \
"gcr.io/cloud-marketplace-tools/k8s/dev:$(MARKETPLACE_TOOLS_TAG)" \
cat /scripts/dev > "$@"
chmod a+x "$@"
########### Main targets ###########
# Builds the application containers and push them to the registry.
# Including Makefile can extend this target. This target is
# a prerequisite for install.
.PHONY: app/build
app/build:: ;
# Installs the application into target namespace on the cluster.
.PHONY: app/install
app/install:: app/build \
.build/var/APP_DEPLOYER_IMAGE \
.build/var/APP_PARAMETERS \
.build/var/MARKETPLACE_TOOLS_TAG \
| .build/app/dev
$(call print_target)
.build/app/dev \
/scripts/install \
--deployer='$(APP_DEPLOYER_IMAGE)' \
--parameters='$(APP_PARAMETERS)' \
--entrypoint="/bin/deploy.sh"
# Installs the application into target namespace on the cluster.
.PHONY: app/install-test
app/install-test:: app/build \
.build/var/APP_DEPLOYER_IMAGE \
.build/var/APP_PARAMETERS \
.build/var/APP_TEST_PARAMETERS \
.build/var/MARKETPLACE_TOOLS_TAG \
| .build/app/dev
$(call print_target)
.build/app/dev \
/scripts/install \
--deployer='$(APP_DEPLOYER_IMAGE)' \
--parameters='$(call combined_parameters)' \
--entrypoint="/bin/deploy_with_tests.sh"
# Uninstalls the application from the target namespace on the cluster.
.PHONY: app/uninstall
app/uninstall: .build/var/APP_DEPLOYER_IMAGE \
.build/var/APP_PARAMETERS
$(call print_target)
kubectl delete 'application/$(call name_parameter)' \
--namespace='$(call namespace_parameter)' \
--ignore-not-found
# Runs the verification pipeline.
.PHONY: app/verify
app/verify: app/build \
.build/var/APP_DEPLOYER_IMAGE \
.build/var/APP_PARAMETERS \
.build/var/APP_TEST_PARAMETERS \
.build/var/MARKETPLACE_TOOLS_TAG \
| .build/app/dev
$(call print_target)
.build/app/dev \
/scripts/verify \
--deployer='$(APP_DEPLOYER_IMAGE)' \
--parameters='$(call combined_parameters)'
# Runs diagnostic tool to make sure your environment is properly setup.
app/doctor: | .build/app/dev
$(call print_target)
.build/app/dev /scripts/doctor.py
endif