-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
198 lines (163 loc) · 7.05 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
###############################################################################
#
# Copyright (c) 2019. Ontario Institute for Cancer Research
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
###############################################################################
#####################################################################
# Project Configuration
#####################################################################
# Project Info
SOURCE_COMMIT := $$(git show | grep commit | head -1 | tr -s ' ' | cut -d ' ' -f 2 | cut -c 1-8)
DOCKER_PROJ := $$(sed -n -e 's/.*<name>\(.*\)<\/name>.*/\1/p' ./pom.xml)
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
# Required System files
DOCKER_EXE := $(shell which docker)
DOCKER_COMPOSE_EXE := $(shell which docker-compose)
# Required Project files
DOCKERFILE_SERVER := Dockerfile
MVNW_EXE := $(ROOT_DIR)/mvnw
POM_XML_FILE := $(ROOT_DIR)/pom.xml
DOCKER_COMPOSE_FILE := $(ROOT_DIR)/docker-compose.yml
# Commands
MVN_COMMAND := $(MVNW_EXE) -f $(POM_XML_FILE)
DOCKER_COMPOSE_COMMAND := $(DOCKER_COMPOSE_EXE) -f $(DOCKER_COMPOSE_FILE) -p $(DOCKER_PROJ)
# Version Info
DOCKER_EXE_VERSION := $$($(DOCKER_EXE) version --format '{{.Server.Version}}')
DOCKER_COMPOSE_EXE_VERSION := $$($(DOCKER_COMPOSE_EXE) version --short)
MVNW_EXE_VERSION := $$($(MVNW_EXE) -version | head -1 | tr -s ' ' | cut -d ' ' -f 3)
JAVA_VERSION := $$($(MVNW_EXE) -version | grep 'Java version' | sed 's/,//g' | tr -s ' ' | cut -d ' ' -f 3)
#####################################################################
# Internal
#####################################################################
# STDOUT Formatting
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)
.PHONY:
.SILENT: docker-server-ps docker-server-logs
# Internal Targets
$(DOCKER_EXE):
$(error $(ERROR_HEADER) The docker executable "$(DOCKER_EXE)" does not exist)
$(DOCKER_COMPOSE_EXE):
$(error $(ERROR_HEADER) The docker-compose executable "$(DOCKER_COMPOSE_EXE)" does not exist)
$(POM_XML_FILE):
$(error $(ERROR_HEADER) The could not find the pom.xml file at $(POM_XML_FILE) )
$(MVNW_EXE):
$(error $(ERROR_HEADER) The mvnw executable "$(MVNW_EXE)" does not exist)
_check_docker_software_exists: $(DOCKER_EXE) $(DOCKER_COMPOSE_EXE)
_check_mvn_software_exists: $(POM_XML_FILE) $(MVNW_EXE)
@chmod +x $(MVNW_EXE)
#####################################################################
# User Targets
#####################################################################
help:
@echo
@echo "**************************************************************"
@echo " Help"
@echo "**************************************************************"
@echo "To dry-execute a target run: make -n <target> "
@echo
@echo "Available Targets: "
@grep '^[A-Za-z][A-Za-z0-9_-]\+:.*' ./Makefile | sed 's/:.*//' | sed 's/^/\t/'
@echo
info:
@echo
@echo "**************************************************************"
@echo " Info"
@echo "**************************************************************"
@echo " ROOT_DIR: $(ROOT_DIR)"
@echo " JAVA_HOME: ${JAVA_HOME}"
@echo " DOCKER_PROJ: $(DOCKER_PROJ)"
@echo " SOURCE_COMMIT: $(SOURCE_COMMIT)"
@echo " JAVA_VERSION: $(JAVA_VERSION)"
@echo " MVNW_VERSION: $(MVNW_EXE_VERSION)"
@echo " DOCKER_VERSION: $(DOCKER_EXE_VERSION)"
@echo " DOCKER_COMPOSE_EXE: $(DOCKER_COMPOSE_EXE)"
@echo " MVNW_EXE: $(MVNW_EXE)"
@echo " DOCKER_EXE: $(DOCKER_EXE)"
@echo " DOCKER_COMPOSE_VERSION: $(DOCKER_COMPOSE_EXE_VERSION)"
@echo " DOCKERFILE_SERVER: $(DOCKERFILE_SERVER)"
@echo " DOCKER_COMPOSE_FILE: $(DOCKER_COMPOSE_FILE)"
@echo
# Local developement related targets
clean: _check_mvn_software_exists
@echo $(YELLOW)$(INFO_HEADER) "Cleaning local project" $(END)
@$(MVNW_EXE) clean
@echo $(DONE_MESSAGE)
format: _check_mvn_software_exists
@echo $(YELLOW)$(INFO_HEADER) "Formatting local project" $(END)
@$(MVNW_EXE) fmt:format
@echo $(DONE_MESSAGE)
proto: _check_mvn_software_exists
@echo $(YELLOW)$(INFO_HEADER) "Compiling proto files only" $(END)
@$(MVNW_EXE) protobuf:compile protobuf:compile-custom
@echo $(DONE_MESSAGE)
compile: _check_mvn_software_exists
@echo $(YELLOW)$(INFO_HEADER) "Cleaning and compiling everything" $(END)
@$(MVNW_EXE) clean compile
@echo $(DONE_MESSAGE)
package: _check_mvn_software_exists
@echo $(YELLOW)$(INFO_HEADER) "Cleaning and packaging" $(END)
@$(MVNW_EXE) clean package
@echo $(DONE_MESSAGE)
#######################################
dev-start: _check_docker_software_exists
@echo $(YELLOW)$(INFO_HEADER) "Starting DEV mode with ego and admin services"$(END)
@$(DOCKER_COMPOSE_COMMAND) up --no-deps -d ego-api ego-postgres admin
@echo $(DONE_MESSAGE)
dev-stop: _check_docker_software_exists
@echo $(YELLOW)$(INFO_HEADER) "Stopping DEV mode ego and admin services"$(END)
@$(DOCKER_COMPOSE_COMMAND) kill ego-api ego-postgres admin
@$(DOCKER_COMPOSE_COMMAND) rm -f ego-api ego-postgres admin
@echo $(DONE_MESSAGE)
dev-ps: demo-ps
dev-logs: demo-logs
fresh-ego: _check_docker_software_exists
@echo $(YELLOW)$(INFO_HEADER) "Restarting a fresh empty instance of the ego service"$(END)
@$(DOCKER_COMPOSE_COMMAND) kill ego-postgres ego-api
@$(DOCKER_COMPOSE_COMMAND) rm -f ego-postgres ego-api
@$(DOCKER_COMPOSE_COMMAND) up --no-deps -d ego-postgres ego-api
@echo $(DONE_MESSAGE)
run-unit-test: _check_mvn_software_exists
@echo $(YELLOW)$(INFO_HEADER) "Running unit tests" $(END)
@$(MVNW_EXE) clean package
@echo $(DONE_MESSAGE)
demo-start:
@echo $(YELLOW)$(INFO_HEADER) "Starting demo"$(END)
@$(DOCKER_COMPOSE_COMMAND) up --build -d
@echo $(DONE_MESSAGE)
demo-ps:
@echo $(YELLOW)$(INFO_HEADER) "Showing running services"$(END)
@$(DOCKER_COMPOSE_COMMAND) ps
@echo $(DONE_MESSAGE)
demo-logs:
@echo $(YELLOW)$(INFO_HEADER) "Showing logs for demo services"$(END)
@$(DOCKER_COMPOSE_COMMAND) logs
@echo $(DONE_MESSAGE)
demo-stop:
@echo $(YELLOW)$(INFO_HEADER) "Stopping demo"$(END)
@$(DOCKER_COMPOSE_COMMAND) down
@echo $(DONE_MESSAGE)
#######################################
publish-npm:
@echo $(YELLOW)$(INFO_HEADER) "Publishing Protocol Buffers to NPM"$(END)
@echo $(YELLOW)$(INFO_HEADER) " --- Logging into NPM"$(END)
@npm login
@npm publish ./src/main/proto --access public
@echo $(DONE_MESSAGE)