This repository has been archived by the owner on Apr 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
129 lines (105 loc) · 3.75 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
ifneq (,$(wildcard make_scripts/override_var.mk))
include make_scripts/override_var.mk
endif
.DEFAULT_GOAL := help
SHELL_PYTHON:= $(shell which python)
DOCKER_PROJECT_NAME=ndlm_leak_monitoring_app
DOCKER_COMPOSE_ENV=docker/compose.env
DOCKER_COMPOSE_FILE=docker/docker-compose.yml
DOCKER:=docker --config docker
DOCKER_COMPOSE:=docker-compose -p $(DOCKER_PROJECT_NAME) --env-file $(DOCKER_COMPOSE_ENV) -f $(DOCKER_COMPOSE_FILE)
SYS_SERV_WORKING_DIR=/etc/docker/compose/$(DOCKER_PROJECT_NAME)
miscellaneous_targets=format-py
export_targets=exports-py-deps exports-ufw-profile exports-static-files
docker_targets=docker-compose-up docker-compose-down
.PHONY: .FORCE_UPDATE $(miscellaneous_targets) $(export_targets) $(docker_targets)
.FORCE_UPDATE:
# reference: https://gist.github.com/prwhite/8168133#gistcomment-2749866
help:
@printf "Usage\n";
@awk '{ \
if ($$0 ~ /^.PHONY: [a-zA-Z\-\_0-9]+$$/) { \
helpCommand = substr($$0, index($$0, ":") + 2); \
if (helpMessage) { \
printf "\033[36m%-20s\033[0m %s\n", \
helpCommand, helpMessage; \
helpMessage = ""; \
} \
} else if ($$0 ~ /^[a-zA-Z\-\_0-9.]+:/) { \
helpCommand = substr($$0, 0, index($$0, ":")); \
if (helpMessage) { \
printf "\033[36m%-20s\033[0m %s\n", \
helpCommand, helpMessage; \
helpMessage = ""; \
} \
} else if ($$0 ~ /^##/) { \
if (helpMessage) { \
helpMessage = helpMessage"\n "substr($$0, 3); \
} else { \
helpMessage = substr($$0, 3); \
} \
} else { \
if (helpMessage) { \
print "\n "helpMessage"\n" \
} \
helpMessage = ""; \
} \
}' \
$(MAKEFILE_LIST)
## ===== Miscellaneous =====
## Formattin Python scripts by Black.
format-py:
@black .
## ===== Exports =====
## Exports `tool.poetry.dependencies` to `requirements.txt`
exports-py-deps:
@$(SHELL_PYTHON) -B -u scripts/dump_deps.py py
## Exports the application profile of UFW, copy to `/etc/ufw/applications.d`
exports-ufw-profile:
@$(SHELL_PYTHON) -B -u scripts/dump_deps.py ufw_profile
@echo "Copy to '/etc/ufw/applications.d'" && sudo cp "config/ufw/ndlm_leak_monitoring_app" "/etc/ufw/applications.d"
## Exports static files form Node.js modules
exports-static-files:
@$(SHELL_PYTHON) -B -u scripts/dump_deps.py static_files
## ===== Docker =====
## Docker compose build
## $ make docker-compose-build [no-cache=.]
docker-compose-build:
@if [ -z "$(no-cache)" ]; then \
$(DOCKER_COMPOSE) build; \
else \
$(DOCKER_COMPOSE) build --no-cache; \
fi
## Docker compose up
docker-compose-up:
@$(DOCKER_COMPOSE) up -d
## Docker compose down
docker-compose-down:
@$(DOCKER_COMPOSE) down
## Docker compose clean up
docker-compose-clean-up:
@$(DOCKER_COMPOSE) down --rmi local -v
## ===== systemd =====
## Deploy systemd service (on Raspberry Pi)
deploy-systemd-service:
@sudo $(DOCKER_COMPOSE) build
@if [ ! -d "$(SYS_SERV_WORKING_DIR)" ]; then sudo mkdir -p "$(SYS_SERV_WORKING_DIR)"; fi
@sudo cp $(DOCKER_COMPOSE_FILE) $(SYS_SERV_WORKING_DIR)
@sudo cp $(DOCKER_COMPOSE_ENV) $(SYS_SERV_WORKING_DIR)
@ sudo cp -r docker/env $(SYS_SERV_WORKING_DIR)
@sudo cp config/systemd/[email protected] /etc/systemd/system
## Start systemd service (on Raspberry Pi)
systemctl-start:
@sudo systemctl start docker-compose@$(DOCKER_PROJECT_NAME)
## Stop systemd service (on Raspberry Pi)
systemctl-stop:
@sudo systemctl stop docker-compose@$(DOCKER_PROJECT_NAME)
## Enable systemd service (on Raspberry Pi)
systemctl-enable:
@sudo systemctl enable docker-compose@$(DOCKER_PROJECT_NAME)
## Disable systemd service (on Raspberry Pi)
systemctl-disable:
@sudo systemctl disable docker-compose@$(DOCKER_PROJECT_NAME)
## Reload systemd service (on Raspberry Pi)
systemctl-reload:
@sudo systemctl daemon-reload