forked from wescale/hashistack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
215 lines (169 loc) · 8.57 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
##
## —————————————————————————————————— HASHISTACK ————————————————————————————————
##
.DEFAULT_GOAL = help
.PHONY: help header-env
help: ## Display help
@grep -E '(^[a-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: venv-check
venv-check: header-env
@[ -d "$${PWD}/.direnv" ] || (echo "Venv not found: $${PWD}/.direnv" && exit 1)
@direnv reload
.PHONY: install-requirements
install-requirements: ## Install system dependencies
@echo "—————————————————————————————— SYSTEM REQUIREMENTS ———————————————————————————"
@sudo apt-get install python3 python3-dev python3-venv python3-pip direnv bash lsb-release unzip curl sshpass -y
@grep -q 'eval "$$(direnv hook bash)"' ~/.bashrc || echo 'eval "$$(direnv hook bash)"' >> ~/.bashrc
.PHONY: prepare
prepare: venv-check ### Install workspace env dependencies
@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 ""
@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 "$(workspace)" ] && [ -n "$(parent_domain)" ] && [ -n "$(archi)" ] && \
ansible-playbook playbooks/00_init_instance.yml -e hs_workspace=$(workspace) -e hs_parent_domain=$(parent_domain) -e hs_archi=$(archi) || \
( \
echo ----------------------------------- HASHISTACK --------------------------------- && \
echo && \
echo "Usage:\n\tmake init_instance workspace=NAME parent_domain=DOMAIN archi=[mono|multi]\n" && \
exit 1 \
)
##
## —————————————————————————— STAGE_0 - INFRASTRUCTURE ——————————————————————————
##
.PHONY: stage_0_scaleway
stage_0_scaleway:
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
ansible-playbook ../../playbooks/12_core_setup_dns.yml
@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
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
stage_2_consul:
ansible-playbook ../../playbooks/21_consul_install.yml
stage_2: stage_2_vault stage_2_consul
##
## —————————————————————————————— STAGE_3 - NOMAD ———————————————————————————————
##
stage_3:
ansible-playbook ../../playbooks/30_nomad_install.yml
# ***************************************
# *************************************** CORE_AWS
# ***************************************
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/*