/
Makefile
190 lines (150 loc) · 5.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
# Makefile for https://github.com/markosamuli/linux-machine
#
# Self-documented help from:
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
# Get paths to required commands
TRAVIS = $(shell command -v travis 2>/dev/null)
SHELLCHECK = $(shell command -v shellcheck 2>/dev/null)
SHFMT = $(shell command -v shfmt 2>/dev/null)
.PHONY: default
default: help
.PHONY: help
help: ## print this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: setup
setup: ## run setup with default options
@./setup
# Get paths to pyenv and Python commmands
PYENV_BIN = $(shell command -v pyenv 2>/dev/null)
PYTHON_BIN = $(shell command -v python 2>/dev/null)
# Python version to use for the virtualenv
PYTHON_VERSION = $(shell pyenv install --list | sed 's/ //g' | grep "^3\.7\.[0-9]*$$" | sort -r | head -1)
PYTHON_VERSION_PATH = $(HOME)/.pyenv/versions/$(PYTHON_VERSION)
# Virtualenv name will be generated from the repository name
PYENV_VIRTUALENV = $(shell basename "$(shell pwd)")
PYENV_VIRTUALENV_PATH = $(HOME)/.pyenv/versions/$(PYENV_VIRTUALENV)
# Get local pyenv version
PYENV_LOCAL = $(shell pyenv local 2>/dev/null)
.PHONY: setup-pyenv-virtualenv
setup-pyenv-virtualenv: ## setup virtualenv with pyenv for development
ifeq ($(PYENV_BIN),)
@echo "pyenv is not installed"
@exit 1
endif
ifeq ($(PYENV_LOCAL),)
# Local version is not defined
# 1. Install Python if missing
# 2. Create virtualenv if missing
# 3. Set local virtualenv
ifeq (,$(wildcard $(PYTHON_VERSION_PATH)))
@echo "Install Python $(PYTHON_VERSION)"
@pyenv install $(PYTHON_VERSION)
endif
ifeq (,$(wildcard $(PYENV_VIRTUALENV_PATH)))
@echo "Creating virtualenv '$(PYENV_VIRTUALENV)' with pyenv using Python $(PYTHON_VERSION)"
@pyenv virtualenv $(PYTHON_VERSION) $(PYENV_VIRTUALENV)
endif
@echo "Using existing virtualenv '$(PYENV_VIRTUALENV)'"
@pyenv local $(PYENV_VIRTUALENV)
else
# Local version is set
ifneq ($(PYENV_LOCAL),$(PYENV_VIRTUALENV))
@echo "WARNING: pyenv local version should be $(PYENV_VIRTUALENV), found $(PYENV_LOCAL)"
endif
endif
.PHONY: setup-requirements
setup-requirements: setup-pyenv-virtualenv ## setup requirements for running the scripts
@pip install -r requirements.txt
.PHONY: setup-dev-requirements
setup-dev-requirements: setup-pyenv-virtualenv ## setup development requirements
@pip install -r requirements.dev.txt
PRE_COMMIT_INSTALLED = $(shell pre-commit --version 2>&1 | head -1 | grep -q 'pre-commit 1' && echo true)
.PHONY: setup-pre-commit
setup-pre-commit: ## setup pre-commit if not installed
ifneq ($(PRE_COMMIT_INSTALLED),true)
@$(MAKE) setup-dev-requirements
endif
.PHONY: lint
lint: pre-commit ## lint source code
.PHONY: pre-commit
pre-commit: setup-pre-commit ## run pre-commit hooks on all files
ifndef SHELLCHECK
$(error "shellcheck not found, try: 'snap install shellcheck'")
endif
ifndef SHFMT
$(error "shfmt not found, try: 'snap install shfmt'")
endif
@pre-commit run -a -v
.PHONY: travis-lint
travis-lint: setup-pre-commit ## lint .travis.yml file
@pre-commit run -a travis-lint -v
.PHONY: setup-ansible
install-ansible: ## install Ansible without roles or running playbooks
@./setup \
--install-ansible \
--no-run-playbook \
--no-install-roles \
--print-versions \
--verbose
.PHONY: install-roles
install-roles: ## install Ansible roles
@./setup --no-run-playbook
.PHONY: clean-roles
clean-roles: setup-requirements ## remove outdated Ansible roles
@./scripts/clean-roles.py
.PHONY: update-roles
update-roles: setup-requirements ## update Ansible roles in the requirements.yml file
@./scripts/update-roles.py
.PHONY: latest-roles
latest-roles: update-roles clean-roles install-roles # update Ansible roles and install new versions
.PHONY: aws
aws: ## install AWS tools
@./setup -q -t aws
.PHONY: docker
docker: ## install Docker
@./setup -q -t docker
.PHONY: gcloud
gcloud: playbooks/roles/markosamuli.gcloud ## install Google Cloud SDK
@./setup -q -t gcloud
.PHONY: linuxbrew
linuxbrew: playbooks/roles/markosamuli.linuxbrew ## install Homebrew on Linux
@./setup -q -t linuxbrew
.PHONY: golang
golang: playbooks/roles/markosamuli.golang ## install Go programming language
@./setup -q -t golang
.PHONY: node
node: playbooks/roles/markosamuli.nvm ## install Node.js with NVM
@./setup -q -t node,nvm
.PHONY: python
python: playbooks/roles/markosamuli.pyenv ## install Python with pyenv
@./setup -q -t python,pyenv
.PHONY: ruby
ruby: playbooks/roles/zzet.rbenv # install Ruby with rbenv
@./setup -q -t ruby,rbenv
.PHONY: rust
rust: playbooks/roles/markosamuli.rust ## install Rust
@./setup -q -t rust
.PHONY: terraform
terraform: playbooks/roles/markosamuli.terraform ## install Terraform
@./setup -q -t terraform
.PHONY: tools
tools: ## install tools
@./setup -q -t tools
playbooks/roles/zzet.rbenv:
@./setup -n
playbooks/roles/markosamuli.%:
@./setup -n
.PHONY: permissions
permissions: ## fix permissions in user home directory
@USER_HOME_FIX_PERMISSIONS=true ./setup -q -t permissions
PRE_COMMIT_HOOKS = .git/hooks/pre-commit
PRE_PUSH_HOOKS = .git/hooks/pre-push
COMMIT_MSG_HOOKS = .git/hooks/commit-msg
.PHONY: install-git-hooks
install-git-hooks: $(PRE_COMMIT_HOOKS) $(PRE_PUSH_HOOKS) $(COMMIT_MSG_HOOKS) ## install Git hooks
$(PRE_COMMIT_HOOKS): setup-pre-commit ## install pre-commit hooks
@pre-commit install --install-hooks
$(PRE_PUSH_HOOKS): setup-pre-commit ## install pre-push hooks
@pre-commit install --install-hooks -t pre-push
$(COMMIT_MSG_HOOKS): setup-pre-commit ## install commit-msg hooks
@pre-commit install --install-hooks -t commit-msg