-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
178 lines (143 loc) · 6.13 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
.PHONY:
# Required System files
CURL_EXE := $(shell which curl)
DOCKER_COMPOSE_EXE := $(shell which docker-compose)
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
# STDOUT Formatting
BLUE := $$(echo "\033[0;34m")
GREEN := $$(echo "\033[0;32m")
MAGENTA := $$(echo "\033[0;35m")
RED := $$(echo "\033[0;31m")
YELLOW := $$(echo "\033[0;33m")
END := $$(echo "\033[0m")
ERROR_HEADER := [ERROR]:
INFO_HEADER := "**************** "
DONE_MESSAGE := $(YELLOW)$(INFO_HEADER) "- done\n" $(END)
# Variables
DOCKER_DIR := $(ROOT_DIR)/docker
ES_DATA_DIR := $(DOCKER_DIR)/elasticsearch
ES_DOCS_DIR := $(ES_DATA_DIR)/documents
ES_HOST := http://localhost:9200
ES_INDEX := file_centric_1.0
ES_LOAD_SCRIPT := $(ES_DATA_DIR)/load-es-data.sh
ES_PASS := myelasticpassword
ES_USER := elastic
RETRY_CMD := $(ROOT_DIR)/scripts/retry-command.sh
ES_BASIC_AUTH := $(shell printf "$(ES_USER):$(ES_PASS)" | base64)
# Commands
DOCKER_COMPOSE_CMD := \
ES_USER=$(ES_USER) \
ES_PASS=$(ES_PASS) \
$(DOCKER_COMPOSE_EXE) -f \
$(ROOT_DIR)/docker-compose.yml
DC_UP_CMD := COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 $(DOCKER_COMPOSE_CMD) up -d --build
#############################################################
# Internal Targets
#############################################################
_ping_elasticsearch_server:
@echo $(YELLOW)$(INFO_HEADER) "Pinging ElasticSearch on $(ES_HOST)" $(END)
@sh $(RETRY_CMD) "curl --retry 10 \
--retry-delay 0 \
--retry-max-time 40 \
--retry-connrefused \
-H \"Authorization: Basic $(ES_BASIC_AUTH)\" \
\"$(ES_HOST)/_cluster/health?wait_for_status=yellow&timeout=100s&wait_for_no_initializing_shards=true\""
@echo ""
#############################################################
# Help
#############################################################
# Help menu, displaying all available targets
help:
@echo
@echo "**************************************************************"
@echo "**************************************************************"
@echo "To dry-execute a target run: make -n <target> "
@echo
@echo "Available Targets: "
@grep '^[A-Za-z][A-Za-z0-9_-]\+:.*' $(ROOT_DIR)/Makefile | sed 's/:.*//' | sed 's/^/\t/'
@echo
#############################################################
# Cleaning targets
#############################################################
# Kills running services and removes created files/directories
clean-docker:
@echo $(YELLOW)$(INFO_HEADER) "Destroying running docker services" $(END)
@$(DOCKER_COMPOSE_CMD) down -v
# Destroy all non-arranger and non-kibana elasticsearch indices
clean-elastic:
@echo $(YELLOW)$(INFO_HEADER) "Removing ElasticSearch indices" $(END)
@$(CURL_EXE) \
-H "Authorization: Basic $(ES_BASIC_AUTH)" \
-X GET "$(ES_HOST)/_cat/indices" \
| grep -v kibana \
| grep -v arranger \
| grep -v configuration \
| awk '{ print $$3 }' \
| xargs -I {} $(CURL_EXE) -H "Authorization: Basic $(ES_BASIC_AUTH)" -X DELETE "$(ES_HOST)/{}?pretty"
@echo $(GREEN)$(INFO_HEADER) "ElasticSearch indices removed" $(END)
clean-log-dirs:
@echo $(YELLOW)$(INFO_HEADER) "Cleaning log directories" $(END);
@rm -rf $(OUTPUT_DIRS)
clean-output-dirs:
@echo $(YELLOW)$(INFO_HEADER) "Cleaning output directories" $(END);
@rm -rf $(LOG_DIRS)
# Clean everything. Kills all services, maven cleans and removes generated files/directories
clean: clean-elastic clean-docker
#############################################################
# Indexing and ES Targets
#############################################################
# Just delete the documents, not the entire index.
clear-es-documents:
@echo $(YELLOW)$(INFO_HEADER) "Deleting elasticsearch documents" $(END)
@$(CURL_EXE) -s -X GET \
-H "Authorization: Basic $(ES_BASIC_AUTH)" \
"$(ES_HOST)/_cat/indices" \
| grep -v kibana \
| grep -v arranger \
| grep -v configuration \
| awk '{ print $$3 }' \
| sed 's#^#$(ES_HOST)/#' \
| sed 's#$$#/_delete_by_query#' \
| xargs $(CURL_EXE) -XPOST \
-H "Authorization: Basic $(ES_BASIC_AUTH)" \
-H 'Content-Type: application/json' \
-d '{"query":{"match_all":{}}}'
seed-es:
@echo $(YELLOW)$(INFO_HEADER) "Initializing file_centric index" $(END)
@$(ES_LOAD_SCRIPT) $(ES_USER) $(ES_PASS) $(ES_HOST) $(ES_INDEX) $(ES_DATA_DIR) $(ES_DOCS_DIR)
get-es-indices:
@echo $(YELLOW)$(INFO_HEADER) "Available indices:" $(END)
@$(CURL_EXE) -X GET -H "Authorization: Basic $(ES_BASIC_AUTH)" "$(ES_HOST)/_cat/indices"
get-es-filecentric-content:
@echo $(YELLOW)$(INFO_HEADER) "file_centric content:" $(END)
@$(CURL_EXE) -X GET -H "Authorization: Basic $(ES_BASIC_AUTH)" "$(ES_HOST)/file_centric/_search?size=100" | ${JQ_EXE} -e
get-es-info: get-es-indices get-es-filecentric-content
#############################################################
# Docker targets
#############################################################
ps:
@echo $(YELLOW)$(INFO_HEADER) "Showing running services" $(END)
@$(DOCKER_COMPOSE_CMD) ps
start:
@echo $(YELLOW)$(INFO_HEADER) "Starting the following services: Elasticsearch, Kibana, and Arranger Server" $(END)
@$(DC_UP_CMD)
@echo $(GREEN)$(INFO_HEADER) Succesfully started all Arranger services! $(GREEN)
@echo $(MAGENTA) "You may have to populate ES and restart the Server container. (Use 'make seed-es' for mock data)" $(END)
start-es:
@echo $(YELLOW)$(INFO_HEADER) "Starting the following service: Elasticsearch" $(END)
@COMPOSE_PROJECT_NAME=arranger_es $(DC_UP_CMD) elasticsearch
@echo $(GREEN)$(INFO_HEADER) Succesfully started this service! $(GREEN)
@echo $(MAGENTA) "You may have to populate it before using it with the Server. (Use 'make seed-es' for mock data)" $(END)
start-server:
@echo $(YELLOW)$(INFO_HEADER) "Starting the following service: Arranger Server" $(END)
@COMPOSE_PROJECT_NAME=arranger_server $(DC_UP_CMD) arranger-server
@echo $(GREEN)$(INFO_HEADER) Succesfully started this service! $(GREEN)
test:
@echo $(YELLOW)$(INFO_HEADER) "Testing all services and integrations" $(END)
@ES_USER=$(ES_USER) ES_PASS=$(ES_PASS) npm run test
@echo $(GREEN)$(INFO_HEADER) Finished testing! $(GREEN)
#############################################################
# Dev targets
#############################################################
format:
@./scripts/format-all.sh