-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
247 lines (189 loc) · 6.51 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# Makefile for Gohan
#>>>
# set default shell
#<<<
SHELL = bash
# export host user IDs for more secure
# containerization and volume mounting
export HOST_USER_UID=$(shell id -u)
export HOST_USER_GID=$(shell id -g)
export OS_NAME=$(shell uname -s | tr A-Z a-z)
export GOOS=${OS_NAME}
export GOARCH=$(shell if [ "$(uname -m)" == "aarch64" ]; then echo arm64; else echo $(uname -m); fi | tr A-Z a-z)
# import global variables
env ?= .env
include $(env)
export $(shell sed 's/=.*//' $(env))
# initialize services
init:
@# Gateway:
@# - DRS Authentication
@htpasswd -cb gateway/drs.htpasswd ${GOHAN_DRS_BASIC_AUTH_USERNAME} ${GOHAN_DRS_BASIC_AUTH_PASSWORD}
@echo
@# Authorization:
@# - API OPA policies
@echo Configuring authorzation policies
@envsubst < ./etc/api.policy.rego.tpl > ./authorization/api.policy.rego
@$(MAKE) init-data-dirs
@$(MAKE) init-networks
init-dev:
@$(MAKE) init
@$(MAKE) init-vendor
init-networks:
docker network create ${GOHAN_DOCKER_NET} &
init-vendor:
@echo "Initializing Go Module Vendor"
cd src/api && go mod tidy && go mod vendor
init-data-dirs:
mkdir -p ${GOHAN_API_DRS_BRIDGE_HOST_DIR}
chown -R ${HOST_USER_UID}:${HOST_USER_GID} ${GOHAN_API_DRS_BRIDGE_HOST_DIR}
chmod -R 777 ${GOHAN_API_DRS_BRIDGE_HOST_DIR}
mkdir -p ${GOHAN_DRS_DATA_DIR}
mkdir -p ${GOHAN_DRS_DATA_DIR}/db
mkdir -p ${GOHAN_DRS_DATA_DIR}/obj
chown -R ${HOST_USER_UID}:${HOST_USER_GID} ${GOHAN_DRS_DATA_DIR}
chmod -R 777 ${GOHAN_DRS_DATA_DIR}
mkdir -p ${GOHAN_ES_DATA_DIR}
chown -R ${HOST_USER_UID}:${HOST_USER_GID} ${GOHAN_ES_DATA_DIR}
chmod -R 777 ${GOHAN_ES_DATA_DIR}
@# tmp:
@# (setup for when gohan needs to preprocess vcf's at ingestion time):
mkdir -p ${GOHAN_API_VCF_PATH}
mkdir -p ${GOHAN_API_VCF_PATH}/tmp
chown -R ${HOST_USER_UID}:${HOST_USER_GID} ${GOHAN_API_VCF_PATH}
chmod -R 777 ${GOHAN_API_VCF_PATH}
mkdir -p ${GOHAN_API_GTF_PATH}
mkdir -p ${GOHAN_API_GTF_PATH}/tmp
chown -R ${HOST_USER_UID}:${HOST_USER_GID} ${GOHAN_API_GTF_PATH}
chmod -R 777 ${GOHAN_API_GTF_PATH}
@echo ".. done!"
# Run
run-all:
docker-compose -f docker-compose.yaml up -d
run-dev-all:
docker-compose -f docker-compose.dev.yaml up -d --force-recreate
run-dev-%:
docker-compose -f docker-compose.dev.yaml up -d --force-recreate $*
run-%:
docker-compose -f docker-compose.yaml up -d $*
# Build
build-gateway: stop-gateway clean-gateway
echo "-- Building Gateway Container --"
docker-compose -f docker-compose.yaml build gateway
build-api-local-binaries:
@echo "-- Building Golang-Api-Alpine Binaries --"
cd src/api && \
export CGO_ENABLED=0 && \
\
go build -ldflags="-s -w" -o ../../bin/api_${GOOS}_${GOARCH} && \
\
cd ../..
# Temporarily disabling:
# && \
# upx --brute bin/api_${GOOS}_${GOARCH}
build-api: stop-api clean-api
@echo "-- Building Golang-Api-Alpine Container --"
docker-compose -f docker-compose.yaml build api
build-authz: stop-authz clean-authz
@echo "-- Building Authorization Container --"
docker-compose -f docker-compose.yaml build authorization
# Stop
stop-all:
docker-compose -f docker-compose.yaml down
stop-%:
docker-compose -f docker-compose.yaml stop $*
# Clean up
clean-all: clean-networks clean-api clean-gateway
clean-networks:
docker network remove ${GOHAN_DOCKER_NET} &
clean-gateway:
docker rm ${GOHAN_GATEWAY_CONTAINER_NAME} --force; \
docker rmi ${GOHAN_GATEWAY_IMAGE}:${GOHAN_GATEWAY_VERSION} --force;
clean-api:
rm -f bin/api_${GOOS}_${GOARCH}
docker rm ${GOHAN_API_CONTAINER_NAME} --force; \
docker rmi ${GOHAN_API_IMAGE}:${GOHAN_API_VERSION} --force;
clean-authz:
docker rm ${GOHAN_AUTHZ_OPA_CONTAINER_NAME} --force; \
docker rmi ${GOHAN_AUTHZ_OPA_IMAGE}:${GOHAN_AUTHZ_OPA_IMAGE_VERSION} --force;
## -- WARNING: DELETES ALL LOCAL ELASTICSEARCH DATA
clean-all-data:
@read -p "Are you sure you want to clean out all data? (yes/no) : " answer; \
if [ "$$answer" == "yes" ]; then \
echo "-- Cleaning! --" ; \
docker-compose -f docker-compose.yaml down && \
sudo rm -rf ${GOHAN_DATA_ROOT} ; \
echo "-- Done! --" ; \
else \
echo "-- Skipping.. --" ; \
fi
clean-elastic-data:
@read -p "Are you sure you want to clean out all elasticsearch data? (yes/no) : " answer; \
if [ "$$answer" == "yes" ]; then \
echo "-- Cleaning! --" ; \
docker-compose -f docker-compose.yaml down && \
sudo rm -rf ${GOHAN_ES_DATA_DIR} ; \
echo "-- Done! --" ; \
else \
echo "-- Skipping.. --" ; \
fi
## -- WARNING: DELETES ALL LOCAL DRS DATA
clean-drs-data:
@read -p "Are you sure you want to clean out all drs data? (yes/no) : " answer; \
if [ "$$answer" == "yes" ]; then \
echo "-- Cleaning! --" ; \
docker-compose -f docker-compose.yaml down && \
sudo rm -rf ${GOHAN_DRS_DATA_DIR} ; \
echo "-- Done! --" ; \
else \
echo "-- Skipping.. --" ; \
fi
## -- WARNING: DELETES ALL LOCAL API-DRS-BRIDGE DATA
clean-api-drs-bridge-data:
@read -p "Are you sure you want to clean out all api-drs-bridge data? (yes/no) : " answer; \
if [ "$$answer" == "yes" ]; then \
echo "-- Cleaning! --" ; \
docker-compose -f docker-compose.yaml down && \
sudo rm -rf ${GOHAN_API_DRS_BRIDGE_HOST_DIR} ; \
echo "-- Done! --" ; \
else \
echo "-- Skipping.. --" ; \
fi
## Tests
test-api: init prepare-test-config
# # @# Run the tests directly from the api source directory
# # cd src/api && \
# # go clean -cache && \
# # go test ./tests/unit/... -v
@# restart any running containers and print
docker compose -f docker-compose.test.yaml down
docker compose -f docker-compose.test.yaml up -d
@# run build tests
@# - print api and drs logs in the
@# event of a failued
cd src/api && \
go clean -cache && \
(go test ./tests/build/... -v || ((docker logs gohan-api | tail -n 100) && (docker logs gohan-drs | tail -n 100) && exit 1)) && \
cd ../..
@# shut down the containers and print
@# the tail end of the
@# api and elasticsearch logs
docker compose -f docker-compose.test.yaml stop
docker logs gohan-api | tail -n 50
docker logs elasticsearch | tail -n 50
test-api-dev: prepare-dev-config
@# Run the tests
cd src/api && \
go clean -cache && \
go test ./tests/integration/... -v
prepare-test-config:
@# Prepare environment variables dynamically via a JSON file
@# since xUnit doens't support loading env variables natively
envsubst < ./etc/test.yml.tpl > ./src/api/tests/common/test.config.yml
prepare-dev-config:
@# Prepare environment variables dynamically via a JSON file
@# since xUnit doens't support loading env variables natively
envsubst < ./etc/test.config.yml.tpl > ./src/api/tests/common/test.config.yml
clean-tests:
@# Clean up
rm ./src/api/tests/common/test.config.yml