-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
371 lines (284 loc) · 8.35 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# Makefile for https://github.com/markosamuli/macos-machine
#
# Self-documented help from:
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
###
# Makefile configuration
###
.DEFAULT_GOAL := help
# We want our output silent by default, use VERBOSE=1 make <command> ...
# to get verbose output.
ifndef VERBOSE
.SILENT:
endif
###
# Define environment variables in the beginning of the file
###
UNAME_S := $(shell uname -s)
ANSIBLE_BIN = $(shell ansible --version 2>&1 | head -1 | grep -q 'ansible 2' && command -v ansible)
BREW_BIN = $(shell command -v brew 2>/dev/null)
GO_BIN = $(shell command -v go 2>/dev/null)
PYENV_BIN = $(shell command -v pyenv 2>/dev/null)
PRE_COMMIT_BIN = $(shell pre-commit --version 2>&1 | head -1 | grep -q 'pre-commit [12]\.' && command -v pre-commit)
PYLINT_BIN = $(shell pylint --version 2>&1 | head -1 | grep -q 'pylint 2' && command -v pylint)
SHELLCHECK_BIN = $(shell command -v shellcheck 2>/dev/null)
SHFMT_BIN = $(shell command -v shfmt 2>/dev/null)
###
# Define local variables after environment variables
###
# Paths to supported Git hooks
pre_commit_hooks = .git/hooks/pre-commit
pre_push_hooks = .git/hooks/pre-push
commit_msg_hooks = .git/hooks/commit-msg
git_hooks = $(pre_commit_hooks) $(pre_push_hooks) $(commit_msg_hooks)
###
# Setup
###
.PHONY: setup
setup: setup-ansible setup-requirements ## setup requirements for running playbooks
.PHONY: setup-development
setup-development: setup setup-git-hooks ## setup requirements for local development
###
# Setup: Python, pyenv and virtualenv
###
requirements.txt: requirements.in
pip-compile requirements.in
requirements.dev.txt: requirements.txt requirements.dev.in
pip-compile requirements.dev.in
.PHONY: setup-pyenv
setup-pyenv:
ifeq ($(PYENV_BIN),)
$(MAKE) python
endif
.PHONY: setup-pyenv-virtualenv
setup-pyenv-virtualenv: | setup-pyenv
./scripts/create_virtualenv.sh
.PHONY: setup-requirements
setup-requirements: requirements.txt | setup-pyenv-virtualenv
pip-sync requirements.txt
.PHONY: setup-dev-requirements
setup-dev-requirements: requirements.dev.txt | setup-pyenv-virtualenv
pip-sync requirements.dev.txt
###
# Setup: Homebrew
###
.PHONY: setup-homebrew
setup-homebrew:
ifeq ($(BREW_BIN),)
ifeq ($(UNAME_S),Linux)
$(MAKE) linuxbrew
endif
ifeq ($(UNAME_S),Darwin)
./setup --no-install-ansible --no-run-playbook --no-install-roles
endif
endif
./setup -t homebrew
###
# Setup: pre-commit and Git hooks
###
.PHONY: setup-pre-commit
setup-pre-commit:
ifeq ($(PRE_COMMIT_BIN),)
$(MAKE) setup-dev-requirements
endif
.PHONY: setup-git-hooks
setup-git-hooks: $(git_hooks)
$(pre_commit_hooks): | setup-pre-commit
pre-commit install --install-hooks
$(pre_push_hooks): | setup-pre-commit
pre-commit install --install-hooks -t pre-push
$(commit_msg_hooks): | setup-pre-commit
pre-commit install --install-hooks -t commit-msg
###
# Setup: Go
###
.PHONY: setup-golang
setup-golang:
ifeq ($(GO_BIN),)
$(MAKE) golang
endif
###
# Setup: Shellcheck and shfmt
###
.PHONY: setup-shellcheck
setup-shellcheck:
ifeq ($(SHELLCHECK_BIN),)
./setup -q -t shellcheck
endif
.PHONY: setup-shfmt
setup-shfmt: setup-golang
ifeq ($(SHFMT_BIN),)
GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt
endif
###
# Setup: pylint
###
.PHONY: setup-pylint
setup-pylint:
ifeq ($(PYLINT_BIN),)
$(MAKE) setup-dev-requirements
endif
###
# Setup: Ansible roles
###
playbooks/roles/zzet.rbenv:
./setup --no-run-playbook
playbooks/roles/markosamuli.%:
./setup --no-run-playbook
###
# Linting and formatting
###
.PHONY: lint
lint: setup-pre-commit setup-shfmt setup-shellcheck setup-pylint ## run pre-commit hooks on all files
pre-commit run -a
.PHONY: format-python
format-python: setup-pre-commit ## format Python files
-pre-commit run -a requirements-txt-fixer
-pre-commit run -a black
.PHONY: lint-python
lint-python: setup-pre-commit setup-pylint format-python ## lint and format Python files
pre-commit run -a check-ast
pre-commit run -a flake8
pre-commit run -a pylint
.PHONY: lint-travis
lint-travis: setup-pre-commit ## lint .travis.yml file
pre-commit run -a travis-lint
###
# Setup: Ansible
###
.PHONY: setup-ansible
setup-ansible:
ifeq ($(ANSIBLE_BIN),)
$(MAKE) install-ansible
endif
.PHONY: install-ansible
install-ansible: ## install Ansible without roles or running playbooks
./setup \
--install-ansible \
--no-run-playbook \
--no-install-roles
.PHONY: install-roles
install-roles: ## install Ansible roles
./setup --no-run-playbook
.PHONY: list-tags
list-tags: # list Ansible tags
./setup --no-run-playbook --no-install-roles -l
.PHONY: clean-roles
clean-roles: setup-requirements ## remove outdated Ansible roles
python -m machine.scripts.clean_roles
.PHONY: update-roles
update-roles: setup-ansible ## update Ansible roles in the requirements.yml file
./setup --no-install-ansible --update-roles --no-run-playbook
.PHONY: latest-roles
latest-roles: update-roles clean-roles install-roles # update Ansible roles and install new versions
###
# Tools
###
.PHONY: permissions
permissions: fix-permissions
.PHONY: fix-permissions
fix-permissions: setup ## fix permissions in user home directory
USER_HOME_FIX_PERMISSIONS=true ./setup -q -t permissions
###
# Configure system with the playbooks
###
.PHONY: install
install: ## install everything with default options
./setup
.PHONY: aws
aws: install-aws
.PHONY: install-aws
install-aws: setup playbooks/roles/markosamuli.aws_tools ## install AWS tools
python -m machine.scripts.configure install_aws true
./setup -q -t aws
.PHONY: docker
docker: install-docker
.PHONY: install-docker
install-docker: setup ## install Docker
python -m machine.scripts.configure install_docker true
./setup -q -t docker
.PHONY: editors
editors: install-editors
.PHONY: install-editors
install-editors: setup ## install IDEs and code editors
./setup -q -t editors
.PHONY: gcloud
gcloud: install-gcloud
.PHONY: install-gcloud
install-gcloud: setup playbooks/roles/markosamuli.gcloud ## install Google Cloud SDK
python -m machine.scripts.configure install_gcloud true
./setup -q -t gcloud
.PHONY: go
go: install-golang
.PHONY: golang
golang: install-golang
.PHONY: install-golang
install-golang: setup playbooks/roles/markosamuli.golang ## install Go programming language
python -m machine.scripts.configure install_golang true
./setup -q -t golang
.PHONY: lua
lua: install-lua
.PHONY: install-lua
install-lua: setup ## install Lua programming language
python -m machine.scripts.configure install_lua true
./setup -q -t lua
.PHONY: node
node: install-node
.PHONY: install-node
install-node: setup playbooks/roles/markosamuli.nvm ## install Node.js with NVM
python -m machine.scripts.configure install_nodejs true
./setup -q -t node,nvm
.PHONY: python
python: install-python
# Do not create virtualenv if Python is not installed yet
.PHONY: install-python
install-python: setup-ansible playbooks/roles/markosamuli.pyenv ## install Python with pyenv
./setup -q -t python,pyenv
.PHONY: ruby
ruby: install-ruby
.PHONY: install-ruby
install-ruby: setup playbooks/roles/zzet.rbenv ## install Ruby with rbenv
python -m machine.scripts.configure install_ruby true
./setup -q -t ruby,rbenv
.PHONY: rust
rust: install-rust
.PHONY: install-rust
install-rust: setup playbooks/roles/markosamuli.rust ## install Rust programming language
python -m machine.scripts.configure install_rust true
./setup -q -t rust
.PHONY: shellcheck
shellcheck: install-shellcheck
.PHONY: install-shellcheck
install-shellcheck: setup ## install shellcheck
./setup -q -t shellcheck
.PHONY: terraform
terraform: install-terraform
.PHONY: install-terraform
install-terraform: setup ## install Terraform
python -m machine.scripts.configure install_terraform true
./setup -q -t terraform
.PHONY: tools
tools: install-tools
.PHONY: install-tools
install-tools: setup ## install tools
./setup -q -t tools
.PHONY: zsh
zsh: install-zsh
.PHONY: install-zsh
install-zsh: setup ## install zsh
python -m machine.scripts.configure install_zsh true
./setup -q -t zsh
###
# Clean
###
.PHONY: clean
clean: ## delete local development dependencies
-rm -rf playbooks/roles/markosamuli.*
-rm -rf playbooks/roles/zzet.rbenv
./scripts/delete_virtualenv.sh
###
# This Makefile uses self-documenting help commands
###
.PHONY: help
help: ## print this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort -d | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'