-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
221 lines (184 loc) · 12.3 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
.PHONY: logo decrypt build deploy docs_build restore develop lint docs_local count_services develop
VERSION := $(cat VERSION)
# Deploy HomelabOS - `make`
deploy: logo build git_sync config
@printf "\033[92m========== Deploying HomelabOS ==========\033[0m\n"
./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/additional_services_config.yml" --extra-vars="@settings/vault.yml" -i inventory playbook.homelabos.yml
help: logo
@printf "\033[92m========== HomelabOS Commands ==========\033[0m\n"
@echo
@echo 'Usage:'
@echo ' make deploy Deploy HomelabOS.'
@echo ' make lint Runs the linter against the yaml in the project'
@echo
# Initial configuration
config: logo build
# If config.yml does not exist, populate it with a 'blank'
# yml file so the first attempt at parsing it succeeds
@printf "\033[92m========== Packaging configuration ==========\033[0m\n"
@./docker_helper.sh homelabos package
@printf "\033[92m========== Updating configuration files ==========\033[0m\n"
@mkdir -p settings/passwords
@[ -f ~/.homelabos_vault_pass ] || ./generate_ansible_pass.sh
@[ -f settings/vault.yml ] || cp config.yml.blank settings/vault.yml
@[ -f settings/additional_services_config.yml ] || cp config.yml.blank settings/additional_services_config.yml
@[ -f settings/config.yml ] || cp config.yml.blank settings/config.yml
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/additional_services_config.yml" --extra-vars="@settings/vault.yml" -i config_inventory playbook.config.yml
@printf "\033[92m========== Encrypting secrets ==========\033[0m\n"
@./docker_helper.sh ansible-vault encrypt settings/vault.yml || true
@printf "\033[92m========== Done with configuration ==========\033[0m\n"
# Display the HomelabOS logo and MOTD
logo:
@cat homelaboslogo.txt
@chmod +x check_version.sh
@$(eval VERSION=`cat VERSION`)
@./check_version.sh
@printf "MOTD:\n\n\033[92m" && curl -m 2 https://gitlab.com/NickBusey/HomelabOS/raw/master/MOTD || printf "Couldn't get MOTD"
@printf "\n\n\033[0m\n"
# Build the HomelabOS docker images
build:
@$(eval VERSION=`cat VERSION`)
@printf "\033[92m========== Preparing HomelabOS docker image ==========\033[0m\n"
# First build the docker images needed to deploy
@chmod +x docker_setup.sh
@./docker_setup.sh
@sudo docker pull nickbusey/homelabos:$(VERSION) || true
@sudo docker inspect --type=image nickbusey/homelabos:$(VERSION) > /dev/null && printf "\033[92m========== Docker image already built ==========\033[0m\n" || sudo docker build . -t nickbusey/homelabos:$(VERSION)
# Rebuild the docker image from the Dockerfile
rebuild:
@sudo docker build . -t nickbusey/homelabos:$(VERSION)
# Attempt to sync user settings to a git repo
git_sync:
@./git_sync.sh || true
# Reset all local settings
config_reset: logo build
@printf "\033[92m========== Reset local settings ==========\033[0m\n"
@printf "\n - First we'll make a backup of your current settings in case you actually needed them.\n"
mv settings settings.bak
mkdir settings
@printf "\n - Then we'll set up a blank config file.\n"
cp config.yml.blank settings/config.yml
@printf "\n\033[92m========== Configuration reset! Now just run 'make config' ==========\033[0m\n"
# Update just HomelabOS Services (skipping slower initial setup steps)
update: logo build git_sync config
@printf "\033[92m========== Update HomelabOS ==========\033[0m\n"
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/additional_services_config.yml" --extra-vars="@settings/vault.yml" -i inventory -t deploy playbook.homelabos.yml
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/additional_services_config.yml" --extra-vars="@settings/vault.yml" -i inventory playbook.restart.yml
@printf "\033[92m========== Update completed! ==========\033[0m\n"
# Update just one HomelabOS service `make update_one inventario`
update_one: logo build git_sync config
@printf "\033[92m========== Update $(filter-out $@,$(MAKECMDGOALS)) ==========\033[0m\n"
@./docker_helper_notty.sh ansible-playbook --extra-vars='{"services":["$(filter-out $@,$(MAKECMDGOALS))"]}' --extra-vars="@settings/config.yml" --extra-vars="@settings/additional_services_config.yml" --extra-vars="@settings/vault.yml" -i inventory -t deploy playbook.homelabos.yml
@printf "\033[92m========== Restart $(filter-out $@,$(MAKECMDGOALS)) ==========\033[0m\n"
@./docker_helper_notty.sh ansible-playbook --extra-vars='{"services":["$(filter-out $@,$(MAKECMDGOALS))"]}' --extra-vars="@settings/config.yml" --extra-vars="@settings/additional_services_config.yml" --extra-vars="@settings/vault.yml" -i inventory playbook.restart.yml
@printf "\033[92m========== Update completed! ==========\033[0m\n"
test_one:
@./docker_helper_notty.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/additional_services_config.yml" --extra-vars="@settings/vault.yml" --extra-vars='{"services":["$(filter-out $@,$(MAKECMDGOALS))"],"$(filter-out $@,$(MAKECMDGOALS))":{"enable":"true"}}' -i inventory -t deploy playbook.homelabos.yml
# Run sanity and deployment tests on all HomelabOS services.
# This is for developers of HomelabOS, users can ignore.
test:
@go run main.go test
# Remove HomelabOS services
uninstall: logo build
@printf "\033[92m========== Uninstall HomelabOS completely ==========\033[0m\n"
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/vault.yml" -i inventory -t deploy playbook.remove.yml
@printf "\033[92m========== Uninstall completed! ==========\033[0m\n"
# Remove one service
remove_one: logo build git_sync config
@printf "\033[92m========== Remove data for $(filter-out $@,$(MAKECMDGOALS)) ==========\033[0m\n"
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/vault.yml" --extra-vars='{"services":["$(filter-out $@,$(MAKECMDGOALS))"]}' -i inventory playbook.remove.yml
@printf "\033[92m========== Done removing $(filter-out $@,$(MAKECMDGOALS))! ==========\033[0m\n"
# Reset a service's data files
reset_one: logo build git_sync config
@printf "\033[92m========== Removing data for $(filter-out $@,$(MAKECMDGOALS)) ==========\033[0m\n"
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/vault.yml" --extra-vars='{"services":["$(filter-out $@,$(MAKECMDGOALS))"]}' -i inventory playbook.stop.yml
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/vault.yml" --extra-vars='{"services":["$(filter-out $@,$(MAKECMDGOALS))"]}' -i inventory playbook.remove.yml
@printf "\033[92m========== Redeploying $(filter-out $@,$(MAKECMDGOALS)) ==========\033[0m\n"
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/vault.yml" --extra-vars='{"services":["$(filter-out $@,$(MAKECMDGOALS))"]}' -i inventory -t deploy playbook.homelabos.yml
@printf "\033[92m========== Done resetting $(filter-out $@,$(MAKECMDGOALS))! ==========\033[0m\n"
# Run just items tagged with a specific tag `make tag tinc`
tag: logo build git_sync config
@printf "\033[92m========== Running tasks tagged with '$(filter-out $@,$(MAKECMDGOALS))' ==========\033[0m\n"
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/vault.yml" -i inventory -t $(filter-out $@,$(MAKECMDGOALS)) playbook.homelabos.yml
@printf "\033[92m========== Done running tasks tagged with '$(filter-out $@,$(MAKECMDGOALS))'! ==========\033[0m\n"
# Restore a server with the most recent backup. Assuming Backups were running.
restore: logo build git_sync config
@printf "\033[92m========== Restoring from backup ==========\033[0m\n"
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/vault.yml" -i inventory restore.yml
@printf "\033[92m========== Done restoring from backup! ==========\033[0m\n"
# Run linting scripts
lint:
@printf "\033[92m========== Running Lint on Yaml ==========\033[0m\n"
@./lint.sh
# Restart all enabled services
restart: logo build git_sync config
@printf "\033[92m========== Restarting all services ==========\033[0m\n"
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/vault.yml" -i inventory playbook.restart.yml
@printf "\033[92m========== Done restarting all services! ==========\033[0m\n"
# Restart one service
restart_one: logo build git_sync config
@printf "\033[92m========== Restarting '$(filter-out $@,$(MAKECMDGOALS))' ==========\033[0m\n"
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/vault.yml" --extra-vars='{"services":["$(filter-out $@,$(MAKECMDGOALS))"]}' -i inventory playbook.restart.yml
@printf "\033[92m========== Done restarting '$(filter-out $@,$(MAKECMDGOALS))'! ==========\033[0m\n"
# Stop all enabled services
stop: logo build git_sync config
@printf "\033[92m========== Stopping all services ==========\033[0m\n"
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/vault.yml" -i inventory playbook.stop.yml
@printf "\033[92m========== Done stopping all services! ==========\033[0m\n"
# Stop one service
stop_one: logo build git_sync config
@printf "\033[92m========== Stopping '$(filter-out $@,$(MAKECMDGOALS))' ==========\033[0m\n"
@./docker_helper.sh ansible-playbook --extra-vars="@settings/config.yml" --extra-vars="@settings/vault.yml" --extra-vars='{"services":["$(filter-out $@,$(MAKECMDGOALS))"]}' -i inventory playbook.stop.yml
@printf "\033[92m========== Done stopping '$(filter-out $@,$(MAKECMDGOALS))'! ==========\033[0m\n"
# Spin up cloud servers with Terraform https://homelabos.com/docs/setup/terraform/
terraform: logo build git_sync
@printf "\033[92m========== Deploying cloud server! ==========\033[0m\n"
@[ -f settings/config.yml ] || cp config.yml.blank settings/config.yml
@./terraform.sh
@printf "\033[92m========== Done deploying cloud servers! Run 'make' ==========\033[0m\n"
# Destroy servers created by Terraform
terraform_destroy: logo build git_sync
@printf "\033[92m========== Destroying cloud services! ==========\033[0m\n"
@./docker_helper.sh /bin/bash -c "cd settings; terraform destroy"
@printf "\033[92m========== Done destroying cloud services! ==========\033[0m\n"
decrypt:
@printf "\033[92m========== Decrypting Ansible Vault! ==========\033[0m\n"
@./docker_helper_notty.sh ansible-vault decrypt settings/vault.yml
@printf "\033[92m========== Vault decrypted! settings/vault.yml ==========\033[0m\n"
encrypt:
@./docker_helper_notty.sh ansible-vault encrypt settings/vault.yml
set:
@printf "\033[92m========== Setting '$(filter-out $@,$(MAKECMDGOALS))' ==========\033[0m\n"
@./set_setting.sh $(filter-out $@,$(MAKECMDGOALS))
@printf "\033[92m========== Done! ==========\033[0m\n"
get:
@printf "\033[92m========== Getting '$(filter-out $@,$(MAKECMDGOALS))' ==========\033[0m\n"
@./get_setting.sh $(filter-out $@,$(MAKECMDGOALS))
@printf "\033[92m========== Done! ==========\033[0m\n"
# Serve the HomelabOS website locally
web:
cd website && hugo serve
# Spin up a development stack
vagrant: logo build config
@printf "\033[92m========== Spinning up dev stack ==========\033[0m\n"
@[ -f settings/test_config.yml ] || cp settings/config.yml settings/test_config.yml
@vagrant up --provision
@printf "\033[92m========== Done spinning up dev stack! ==========\033[0m\n"
# Serve the HomelabOS Documentation locally
docs_local:
@docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material
# Build the HomelabOs Documentation - Requires mkdocs with the Material Theme
docs_build: logo build git_sync config
@printf "\033[92m========== Building docs ==========\033[0m\n"
@which mkdocs && mkdocs build || printf "Unable to build the documentation. Please install mkdocs."
@printf "\033[92m========== Done building docs ==========\033[0m\n"
# Return the amount of services included in this version of HomelabOS
count_services:
# This lists each folder in roles/ on it's own line, then excludes anything with homelabos or 'docs' in it, which are HomelabOS things and not services. Then it counts the number of lines.
@ls -l roles | grep -v -e "homelab" -e "docs" | wc -l
# Run sanity checks on services
develop:
@docker run -w /usr/src/app -v ${PWD}:/usr/src/app:Z golang go run main.go
# Hacky fix to allow make to accept multiple arguments
%:
@: