-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
260 lines (213 loc) · 11.7 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
##
## —————————————————————————————————— HASHISTACK ————————————————————————————————
##
.DEFAULT_GOAL = help
.PHONY: help header-env
help: ## Display help
@grep -E '(^[0-9a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | sed -e 's/Makefile://' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-22s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
header-env:
@echo "—————————————————————————————————— HASHISTACK —————————————————————————————————"
@echo
separator = "————————————————————————————————————————————————————————————————————————————————"
##
## —————————————————————————— ENVIRONMENT CONFIGURATION —————————————————————————
##
.PHONY: install-requirements
install-requirements: ## Install system dependencies
@echo "—————————————————————————————— SYSTEM REQUIREMENTS ———————————————————————————"
@sudo apt-get install -y \
ca-certificates python3 python3-dev python3-venv python3-pip direnv bash bash-completion \
lsb-release unzip curl sshpass skopeo librsync-dev
@grep -q 'eval "$$(direnv hook bash)"' ~/.bashrc || echo 'eval "$$(direnv hook bash)"' >> ${HOME}/.bashrc
@[ -d "${HOME}/.asdf" ] || git clone https://github.com/asdf-vm/asdf.git ${HOME}/.asdf --branch v0.14.0
@grep -q '. ${HOME}/.asdf/asdf.sh' ~/.bashrc || echo '. ${HOME}/.asdf/asdf.sh' >> ${HOME}/.bashrc
@grep -q '. ${HOME}/.asdf/completions/asdf.bash' ~/.bashrc || echo '. ${HOME}/.asdf/completions/asdf.bash' >> ${HOME}/.bashrc
.PHONY: prepare
prepare: ### Install workspace env dependencies
@echo "——————————————————————————————— ASDF REQUIREMENTS ————————————————————————————"
@asdf plugin-add terraform https://github.com/asdf-community/asdf-hashicorp.git > /dev/null && \
echo "[ ${Green}OK${Color_Off} ] ${Yellow}INSTALL${Color_Off} PLUGIN TERRAFORM" || \
echo "[${Red}FAILED${Color_Off}] ${Yellow}INSTALL${Color_Off} PLUGIN TERRAFORM"
@asdf plugin-add terraform-docs https://github.com/looztra/asdf-terraform-docs > /dev/null && \
echo "[ ${Green}OK${Color_Off} ] ${Yellow}INSTALL${Color_Off} PLUGIN TERRAFORM-DOCS" || \
echo "[${Red}FAILED${Color_Off}] ${Yellow}INSTALL${Color_Off} PLUGIN TERRAFORM-DOCS"
@asdf install && \
echo "[ ${Green}OK${Color_Off} ] ${Yellow}INSTALL${Color_Off} TOOLS" || \
echo "[${Red}FAILED${Color_Off}] ${Yellow}INSTALL${Color_Off} TOOLS"
@echo "—————————————————————————————— PYTHON REQUIREMENTS ———————————————————————————"
@pip3 install -U pip --no-cache-dir --quiet &&\
echo "[ ${Green}OK${Color_Off} ] ${Yellow}INSTALL${Color_Off} PIP3" || \
echo "[${Red}FAILED${Color_Off}] ${Yellow}INSTALL${Color_Off} PIP3"
@pip3 install -U wheel --no-cache-dir --quiet &&\
echo "[ ${Green}OK${Color_Off} ] ${Yellow}INSTALL${Color_Off} WHEEL" || \
echo "[${Red}FAILED${Color_Off}] ${Yellow}INSTALL${Color_Off} WHEEL"
@pip3 install -U setuptools --no-cache-dir --quiet &&\
echo "[ ${Green}OK${Color_Off} ] ${Yellow}INSTALL${Color_Off} SETUPTOOLS" || \
echo "[${Red}FAILED${Color_Off}] ${Yellow}INSTALL${Color_Off} SETUPTOOLS"
@pip3 install -U --no-cache-dir -q -r requirements.txt &&\
echo "[ ${Green}OK${Color_Off} ] ${Yellow}INSTALL${Color_Off} PIP REQUIREMENTS" || \
echo "[${Red}FAILED${Color_Off}] ${Yellow}INSTALL${Color_Off} PIP REQUIREMENTS"
@pip3 install -U --no-cache-dir -q -r ${PWD}/docs/requirements.txt &&\
cd docs/plugins/yaml2md &&\
pip3 install -q -e . &&\
echo "[ ${Green}OK${Color_Off} ] ${Yellow}INSTALL${Color_Off} PIP DOC REQUIREMENTS" || \
echo "[${Red}FAILED${Color_Off}] ${Yellow}INSTALL${Color_Off} PIP DOC REQUIREMENTS"
@echo "————————————————————————————— ANSIBLE REQUIREMENTS ———————————————————————————"
@ansible-galaxy collection install -fr ${PWD}/requirements.yml
@ansible-galaxy role install -fr ${PWD}/requirements.yml
.PHONY: doc
doc: ### Build project static html documentation
@echo ""
@rm -f docs/source/reference/terraform/*.md
@terraform-docs terraform/vault_kv_realm/ > docs/source/reference/terraform/vault_kv_realm.md
@terraform-docs terraform/vault_policy_management/ > docs/source/reference/terraform/vault_policy_management.md
@cd docs && make html
@echo $(separator)
@echo "Static documentation exported:"
@echo " file://${PWD}/docs/build/html/index.html"
@echo $(separator)
@echo ""
.PHONY: clean
clean = "Clean everything"
clean: clean-molecule
.PHONY: clean-molecule-cache
clean-molecule-cache-desc = "Clean molecule cache"
clean-molecule:
@echo ""
@echo $(clean-molecule-cache-desc)
@echo $(separator)
molecule destroy && molecule reset
.PHONY: clean-doc-desc
clean-doc-desc = "Clean project static html documentation"
clean-doc:
@echo ""
@echo $(clean-doc-desc)
@echo $(separator)
@cd docs && make clean
tf_fmt:
find terraform/* -maxdepth 1 -type d -exec bash -c 'cd {} && pwd && terraform fmt' \;
##
## ———————————————————————————————————— INIT ————————————————————————————————————
##
init_instance: ## Init inventory dir for instance
@ [ -n "$(name)" ] && [ -n "$(parent_domain)" ] && [ -n "$(archi)" ] && \
ansible-playbook playbooks/init.yml -e hs_base_dir=inventories -e hs_workspace=$(name) -e hs_parent_domain=$(parent_domain) -e hs_archi=$(archi) || \
( \
echo ----------------------------------- HASHISTACK --------------------------------- && \
echo && \
echo "Usage:\n\tmake init_instance name=NAME parent_domain=DOMAIN archi=[mono|multi]\n" && \
exit 1 \
)
##
## —————————————————————————— STAGE_99 - OFFLINE ——————————————————————————
##
stage_99: ### Download packages for offline install
ansible-playbook playbooks/11_core_bootstrap.yml -i inventory -t online
ansible-playbook playbooks/12_core_setup_dns.yml -i inventory -t online
ansible-playbook playbooks/15_core_rproxy.yml -i inventory -t online
ansible-playbook playbooks/20_vault_install.yml -i inventory -t online
ansible-playbook playbooks/21_consul_install.yml -i inventory -t online
ansible-playbook playbooks/30_nomad_install.yml -i inventory -t online
ansible-playbook playbooks/40_sre_tooling.yml -i inventory -t online
##
## —————————————————————————— STAGE_0 - INFRASTRUCTURE ——————————————————————————
##
.PHONY: stage_0_scaleway
stage_0_scaleway: ### Create infra and generate inventory
ansible-playbook ../../playbooks/01_infra_scaleway.yml
.PHONY: stage_0_scaleway_destroy
stage_0_scaleway_destroy:
ansible-playbook ../../playbooks/01_infra_scaleway.yml -e tf_action=destroy
##
## —————————————————————————————— STAGE_1 - SYSTEMS —————————————————————————————
##
.PHONY: stage_1_bootstrap
stage_1_bootstrap:
ansible-playbook ../../playbooks/11_core_bootstrap.yml $(ARGS)
ansible-playbook ../../playbooks/12_core_setup_dns.yml $(ARGS)
@echo ""
@echo "Next steps:"
@ echo " - create a delegation"
@ echo " - have your root certificate"
@ echo " - run:"
@ echo " make stage_1_rproxy"
@echo ""
stage_1_rproxy:
ansible-playbook ../../playbooks/15_core_rproxy.yml $(ARGS)
stage_1: stage_1_bootstrap stage_1_rproxy
stage_1_addon_delegation_scaleway:
ansible-playbook ../../playbooks/13_core_scaleway_dns_delegation.yml -e tf_action=apply
stage_1_addon_delegation_scaleway_destroy:
ansible-playbook ../../playbooks/13_core_scaleway_dns_delegation.yml -e tf_action=destroy
stage_1_addon_certs_letsencrypt:
ansible-playbook ../../playbooks/14_core_letsencrypt.yml
stage_1_auto_prerequisites: stage_1_bootstrap stage_1_addon_delegation_scaleway stage_1_addon_certs_letsencrypt stage_1_rproxy
##
## ——————————————————————————— STAGE_2 - VAULT+CONSUL ———————————————————————————
##
stage_2_vault:
ansible-playbook ../../playbooks/20_vault_install.yml $(ARGS)
stage_2_consul:
ansible-playbook ../../playbooks/21_consul_install.yml $(ARGS)
stage_2: stage_2_vault stage_2_consul ## Deploy Vault and Consul
##
## —————————————————————————————— STAGE_3 - NOMAD ———————————————————————————————
##
stage_3: ## Deploy Nomad
ansible-playbook ../../playbooks/30_nomad_install.yml $(ARGS)
##
## ——————————————————————————— STAGE_4 - SRE TOOLING ————————————————————————————
##
stage_4: ## Deploy SRE tooling
ansible-playbook ../../playbooks/40_sre_tooling.yml $(ARGS)
# ***************************************
# *************************************** CORE_AWS
# ***************************************
scaleway_destroy: stage_1_addon_delegation_scaleway_destroy stage_0_scaleway_destroy
core_aws_terraform_servers: header
ansible-playbook playbooks/01_core_aws.yml -e tf_action=apply
core_aws_terraform_servers_destroy: header
ansible-playbook playbooks/01_core_aws.yml -e tf_action=destroy
.PHONY: core_aws
core_aws: core_aws_terraform_servers core_setup letsencrypt core_aws_terraform_lb
core_aws_destroy: header
@echo ""
@echo $(separator)
@echo $(core-scw-destroy-desc)
@echo $(separator)
ansible-playbook rtnp.galaxie_clans.gandi_delegate_subdomain -e scope=${HS_WORKSPACE}-sre -e mode=destroy -e force=true && \
ansible-playbook playbooks/01_core_aws.yml -e tf_action=destroy
# ***************************************
# *************************************** SRE
# ***************************************
.PHONY: sre-tooling-install
sre-tooling-install-desc = "Install SRE tooling"
sre_tooling_install: header
@echo ""
@echo $(separator)
@echo "==> $(sre-tooling-install-desc)"
@echo $(separator)
[ -n "${HS_WORKSPACE}" ] || echo "Set the HS_WORKSPACE env variable" && \
ansible-playbook playbooks/04_sre_tooling.yml
.PHONY: sre_tooling
sre_tooling: sre_tooling_install
# ***************************************
# *************************************** VAULT
# ***************************************
encrypt:
ansible-vault encrypt group_vars/hashistack/secrets/*
decrypt:
ansible-vault decrypt group_vars/hashistack/secrets/*
container-installer:
@docker build --platform=linux/amd64 --target hs-installer \
-t hs-installer:latest -f docker/Dockerfile .
container-offline-installer:
@docker build --platform=linux/amd64 -t hs-offline:latest \
-f docker/Dockerfile .
container-run-offline-installer:
@docker run --rm -it \
--mount type=bind,source=${PWD}/inventories,target=/opt/hashistack/inventories \
--mount type=bind,source=${PWD}/.env.secrets,target=/opt/hashistack/.env.secrets \
-h hs-offline hs-offline:latest bash
get-creds:
ansible-playbook playbooks/99_get_creds.yml