-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
184 lines (143 loc) · 3.93 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
SHELL := /bin/bash
#
# Errors:
#
# Makefile:2: *** missing separator. Stop.
# https://stackoverflow.com/questions/18936337/makefile1-missing-separator-stop
#
#
# Repository
#
repository.message: info
@echo "Have a look at the README.md"
repository.git_add_all:
git add .
repository.git_commit_all: repository.git_add_all
git commit -m "ADD $(git status)"
repository.push: repository.git_commit_all
git push
repository.open:
chromium-browser "https://github.com/nk-designz/distributed_prometheus"
#
# Project
#
project.install:
apt-add-repository --yes --update ppa:ansible/ansible && \
apt update && \
apt install -y \
graphviz \
chromium-browser \
texlive-full \
python3-pip \
libssl-dev \
software-properties-common \
ansible \
jq && \
ansible-galaxy collection install containers.podman && \
ansible-galaxy collection install ansible.posix
project.billing: infrastructure.check_token
@echo -e -n "\nThe costs of this month are:\t" && \
curl -s -X GET \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DO_PAT}" \
"https://api.digitalocean.com/v2/customers/my/balance" \
| jq .month_to_date_balance \
| sed 's/"//g'
#
# Infrastructure
#
infrastructure.check_token:
@scripts/check_do_token.sh
infrastructure.validate_terraform: infrastructure.init
cd infra && \
terraform validate
infrastructure.plan: infrastructure.validate_terraform infrastructure.check_token
cd infra && \
echo "${DO_PAT}" && \
terraform plan \
-var "do_token=${DO_PAT}" \
-var "pvt_key=${HOME}/.ssh/id_rsa"
infrastructure.graph: infrastructure.plan
terraform graph | dot -Tsvg > graph.svg
infrastructure.apply: infrastructure.plan
cd infra && \
terraform apply \
-var "do_token=${DO_PAT}" \
-var "pvt_key=${HOME}/.ssh/id_rsa" \
-auto-approve && \
git add terraform.tfstat*
infrastructure.destroy: infrastructure.plan
cd infra && \
terraform destroy \
-var "do_token=${DO_PAT}" \
-var "pvt_key=${HOME}/.ssh/id_rsa" \
-auto-approve && \
git add terraform.tfstat*
infrastructure.state:
cd infra && \
terraform show terraform.tfstate
infrastructure.init:
cd infra && \
terraform init
#
# Documentation
#
documentation.compile:
cd docs && \
latexmk -pdf \
distributed_prometheus.tex > /dev/null
documentation.review_compile: documentation.compile
cd docs && \
pandoc \
distributed_prometheus.tex \
-o distributed_prometheus.docx
documentation.get_log:
[ -e "docs/distributed_prometheus.log" ] && cat docs/*.log || exit 0
documentation.clean: documentation.get_log
@ echo "Removing files:" && \
cd docs && \
ls \
| grep . \
| grep -E -v '*.tex|*.pdf|*.docx|assets|dist|css|gulpfile.js|index.html|js|package.json|package-lock.json|plugin|REVEALJS_LICENSE|test' \
| tee /dev/tty \
| xargs rm -f
documentation.open: documentation.compile documentation.clean
chromium-browser ${PWD}/docs/distributed_prometheus.pdf
#
# Presentation
#
presentation.open:
chromium-browser ${PWD}/docs/index.html
#
# Ansible
#
ansible.manual_inventory:
@vim inventory/hosts.ini
ansible.galaxy_get_roles:
ansible-galaxy install -p roles -r roles/requirements.yml
ansible.run: ansible.galaxy_get_roles inventory/hosts.ini
ANSIBLE_HOST_KEY_CHECKING=false \
ansible-playbook \
-e 'ansible_python_interpreter=/usr/bin/python3' \
-i inventory/hosts.ini \
main.yml
#
# Project
#
install: repository.install
@echo "Installed Project"
apply-all: infrastructure.apply ansible.run
@echo "Initialized Project"
apply: ansible.manual_inventory ansible.run
@echo "Initialized Project"
destroy: infrastructure.destroy
@echo "Destroyed Project"
redeploy: destroy apply-all
@echo "Redeployed Project"
push: documentation.review_compile documentation.clean repository.push
@echo "Pushed project"
billing: project.billing
info:
@echo -e "Available plans:\n\tapply:\t\tInitialize Project\n\tdestroy:\tDestroy Project\n\tpush:\t\tPush Project\n\tinstall:\tInstall Project\n"
web: repository.open
@echo "Opening in browser"