-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
157 lines (143 loc) · 5.56 KB
/
Makefile
File metadata and controls
157 lines (143 loc) · 5.56 KB
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
SHELL := /bin/bash
VERSION_TXT := version.txt
FILE_VERSION := $(shell cat $(VERSION_TXT))
VERSION ?= $(FILE_VERSION)
RELEASE := v$(VERSION)
TEMPLATES := $(notdir $(wildcard templates/*))
SEMVER_REGEX := ^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+[0-9A-Za-z-]+)?$
FLAVORS := eks doks
MODULES := eks/argocd \
eks/cert-manager \
eks/ecr-credentials-sync \
eks/eks \
eks/external-dns \
eks/external-secrets-operator \
eks/flux \
eks/istio \
eks/loki \
eks/opencost \
eks/rds \
eks/tempo \
eks/velero \
eks/vpc_peering \
doks/doks \
doks/flux \
doks/velero \
doks/loki \
doks/tempo
COMMON_TARGETS := tf-init tf-validate
TERRAFORM ?= terraform
.ONESHELL:
.PHONY: examples $(COMMON_TARGETS) $(TFVARS)
all help:
@echo Available targets
echo
echo " examples Build each ./examples/[FLAVOR] from ./modules/[FLAVOR]"
echo " release Build a new version release, commit and push to git repo"
echo " fmt Executes 'terraform fmt'"
echo " lint Executes 'tflint'"
echo " test Test all modules"
echo " test-[FLAVOR] Test modules ./test/[FLAVOR] only"
echo " clean Remove test files"
echo " template Creates new module based on ./templates/"
echo
init validate:
@echo "This repo is not supposed to be executed. If you are trying to run tests, use 'tf-$@' instead"
exit 1
$(COMMON_TARGETS):
@for dir in $(addprefix modules/,$(MODULES)) $(addprefix examples/,$(MODULES)); do
$(MAKE) -C $$dir $@ || exit 1
done
clean:
@for dir in tests/* $(addprefix modules/,$(MODULES)) $(addprefix examples/,$(MODULES)); do
$(MAKE) -C $$dir $@ || exit 1
done
test: test-eks test-doks
test-%:
$(MAKE) -C tests/$* test MODULES="$(MODULES)"
lint:
@echo Linting modules:
pushd modules && tflint --recursive
popd
echo
echo Linting examples:
pushd examples && tflint --recursive
fmt:
$(TERRAFORM) fmt -recursive modules examples
examples: MODULE_SOURCE_URL ?= git@github.com:getupcloud/getup-modules//modules/{cluster_flavor}/{module_name}?ref={tag}
examples:
@echo Generating examples/common
for i in examples/common/variables-*.tf; do
n=$${i%.tf}
n=$${n#*/variables-}
cat $$i | bin/make-example tfvars all common $(RELEASE) | terraform fmt - > examples/common/terraform-$${n}.auto.tfvars.example
done
for module in $(MODULES); do
cluster_flavor=$${module%%/*}
module_name=$${module#*/}
source_module_dir=modules/$$module
example_module_dir=examples/$$module
echo Generating $$example_module_dir
mkdir -p $$example_module_dir
if [ -e $$source_module_dir/variables.tf ]; then
cat $$source_module_dir/variables.tf | ./bin/make-example main $$cluster_flavor $$module_name $(RELEASE) | terraform fmt - > $$example_module_dir/main-$$module_name.tf || exit 1
cat $$source_module_dir/variables.tf | ./bin/make-example vars $$cluster_flavor $$module_name $(RELEASE) | terraform fmt - > $$example_module_dir/variables-$$module_name.tf || exit 1
cat $$source_module_dir/variables.tf | ./bin/make-example tfvars $$cluster_flavor $$module_name $(RELEASE) | terraform fmt - > $$example_module_dir/terraform-$$module_name.auto.tfvars.example || exit 1
fi
if [ -e $$source_module_dir/outputs.tf ]; then
cat $$source_module_dir/outputs.tf | ./bin/outputs $$module_name > $$example_module_dir/outputs-$$module_name.tf
fi
ln -fs ../../Makefile.example $$example_module_dir/Makefile
ln -fs ../Makefile.conf $$example_module_dir/Makefile.conf
done
\
for cluster_flavor in $(FLAVORS); do
versions_tf=examples/$$cluster_flavor/versions.tf.example
echo Generating $$versions_tf
find modules/$$cluster_flavor -name versions.tf | sort | xargs bin/make-example versions $$cluster_flavor all $(RELEASE) | terraform fmt - > $$versions_tf || exit 1
modules_yaml=examples/$$cluster_flavor/modules.yaml
\
echo Generating $$modules_yaml
modules_yaml=examples/$$cluster_flavor/modules.yaml
echo 'modules:' > $$modules_yaml
printf "%s\n" $(MODULES) | grep ^$$cluster_flavor/ | cut -f2 -d/ | sort | sed -e 's/^/- /' >> $$modules_yaml
done
$(MAKE) fmt
release: fmt update-version
$(MAKE) build-release
update-version:
@if git status --porcelain | grep '^[^?]' | grep -vq $(VERSION_TXT); then
git status
echo -e "\n>>> Tree is not clean. Please commit and try again <<<\n"
exit 1
fi
[ -n "$$BUILD_VERSION" ] || read -e -i "$(FILE_VERSION)" -p "New version: " BUILD_VERSION
echo $$BUILD_VERSION > $(VERSION_TXT)
build-release: examples
git pull --tags
git commit -m "Auto-generated examples $(RELEASE)" examples
git commit -m "Built release $(RELEASE)" $(VERSION_TXT)
git tag $(RELEASE)
git push
git push --tags
template:
@select source in $(TEMPLATES); do
break
done
while true; do
PS3='Cluster flavor: '; select FLAVOR in $(FLAVORS); do break; done
read -e -p "Name of new module: " NAME
if [ -d modules/$$FLAVOR/$$NAME ]; then
echo Already exists: modules/$$NAME
else
read -e -p "Display Name of new module: " DISPLAY_NAME
export NAME DISPLAY_NAME name=$${NAME,,} name_=$${NAME//-/_}
mkdir -p modules/$$FLAVOR/$$NAME
for i in templates/$$source/*; do
envsubst < $$i >> modules/$$FLAVOR/$$NAME/$${i##*/}
done
ln -s ../../Makefile.common modules/$$FLAVOR/$$NAME/Makefile
ls -la modules/$$FLAVOR/$$NAME/
break
fi
done