forked from avni-bahmni-integration/integration-service
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
194 lines (145 loc) · 6.19 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
include bahmni/bahmni.mk
include externalDB.mk
include util/util.mk
help:
@IFS=$$'\n' ; \
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//'`); \
for help_line in $${help_lines[@]}; do \
IFS=$$'#' ; \
help_split=($$help_line) ; \
help_command=`echo $${help_split[0]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
help_info=`echo $${help_split[2]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
printf "%-30s %s\n" $$help_command $$help_info ; \
done
SU:=$(shell id -un)
DB=avni_int
ADMIN_USER=avni_int
postgres_user := $(shell id -un)
application_jar=integrator-0.0.2-SNAPSHOT.jar
dbPort=5432
define _build_db
-psql -h localhost -p $(dbPort) -U $(SU) -d postgres -c "create user $(ADMIN_USER) with password 'password' createrole";
-psql -h localhost -p $(dbPort) -U $(SU) -d postgres -c 'create database $1 with owner $(ADMIN_USER)';
-psql -h localhost -p $(dbPort) -U $(SU) -d $1 -c 'create extension if not exists "uuid-ossp"';
endef
define _drop_db
-psql -h localhost -p $(dbPort) -U $(SU) -d postgres -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$1' AND pid <> pg_backend_pid()"
-psql -h localhost -p $(dbPort) -U $(SU) -d postgres -c 'drop database $1';
endef
define _run_server
java -jar --enable-preview integrator/build/libs/$(application_jar) --app.cron.main="0/3 * * * * ?" --app.cron.full.error="0 1 * * * ?" --avni.api.url=https://staging.avniproject.org/ --avni.impl.username=test-user@bahmni_ashwini --avni.impl.password=password
endef
define _debug_server
java -Xmx2048m -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar --enable-preview integrator/build/libs/$(application_jar) --app.cron.main="0/3 * * * * ?" --app.cron.full.error="0 1 * * * ?" --avni.api.url=https://staging.avniproject.org/ --avni.impl.username=test-user@bahmni_ashwini --avni.impl.password=password
endef
define _run_migrator
. ./conf/local-test.conf
java -jar --enable-preview metadata-migrator/build/libs/metadata-migrator-0.0.2-SNAPSHOT.jar run
endef
define _alert_success
$(call _alert_message,Script Completed)
endef
######## DATABASE LOCAL
# hashed password when password is password = $2a$10$RipvsoEJg4PtXOExTjg7Eu2WzHH1SBntIkuR.bzmZeU2TrbQoFtMW
# kept here for emergency purposes as we are not developing the entire login functionality
rebuild-db: drop-db build-db
rebuild-db-schema: rebuild-db build-db-schema
build-db:
$(call _build_db,avni_int)
build-test-db:
$(call _build_db,avni_int_test)
build-db-schema:
./gradlew --stacktrace :integration-data:migrateDb
psql -h localhost -p $(dbPort) -U avni_int -d avni_int < integration-data/src/main/resources/db/util/superadmin.sql;
drop-db:
$(call _drop_db,avni_int)
create-test-db:
$(call _build_db,avni_int_test)
drop-test-db:
$(call _drop_db,avni_int_test)
rebuild-test-db: drop-test-db build-test-db
drop-roles:
-psql -h localhost -p $(dbPort) -U $(SU) -d postgres -c 'drop role $(ADMIN_USER)';
#######
####### BUILD, TEST, LOCAL RUN
build-server: ## Builds the jar file
./gradlew clean build -x test
setup-log-dir:
-sudo mkdir /var/log/avni-int-service
-sudo chown $(SU) /var/log/avni-int-service
run-server: build-db build-server
$(call _run_server)
debug-server: build-db build-server
$(call _debug_server)
run-server-without-background: build-server
java -jar --enable-preview integrator/build/libs/$(application_jar) --app.cron.main="0 0 6 6 9 ? 2035" --avni.api.url=https://example.com/ --avni.impl.username=foo --avni.impl.password=bar
run-migrator: build-server
$(call _run_migrator)
test-server-only:
-touch amrit/src/test/resources/amrit-secret.properties
-touch goonj/src/test/resources/goonj-secret.properties
-touch goonj/src/test/resources/avni-secret.properties
./gradlew clean build
test-server-starts:
AVNI_INT_DATASOURCE=jdbc:postgresql://localhost:5432/avni_int_test AVNI_INT_AUTO_CLOSE=true java -jar integrator/build/libs/$(application_jar)
test-server: drop-test-db build-test-db test-server-only test-server-starts
setup-external-test-db: drop-test-db create-test-db
sudo -u ${postgres_user} psql avni_int_test -f dump.sql
test-server-external: drop-test-db setup-external-test-db
./gradlew clean build
open-test-results-integrator:
open integrator/build/reports/tests/test/index.html
open-test-results-util:
open util/build/reports/tests/test/index.html
open-test-results-bahmni:
open bahmni/build/reports/tests/test/index.html
open-test-results-avni:
open avni/build/reports/tests/test/index.html
open-test-results-goonj:
open goonj/build/reports/tests/test/index.html
open-test-results-amrit:
open amrit/build/reports/tests/test/index.html
open-test-results-lahi:
open lahi/build/reports/tests/test/index.html
open-test-results-migrator:
open metadata-migrator/build/reports/tests/test/index.html
open-test-results-integration-data:
open integration-data/build/reports/tests/test/index.html
#######
####### Tunnels
tunnel-staging-db:
ssh avni-int -L 6015:stagingdb.openchs.org:5432
tunnel-server-debug-vagrant:
ssh -p 2222 -i ~/.vagrant.d/insecure_private_key vagrant@127.0.0.1 -L 6031:localhost:6031
#######
####### SOURCE CONTROL
tag-release:
ifndef version
$(error ERROR: version not provided.)
endif
git tag -a v$(version) -m "version $(version)"
git push origin --tags
#######
####### Deployment
deploy-to-vagrant-only:
echo vagrant | pbcopy
scp -P 2222 -i ~/.vagrant.d/insecure_private_key integrator/build/libs/$(application_jar) root@127.0.0.1:/root/source/abi-host/
deploy-to-vagrant: build-server deploy-to-vagrant-only
#######
### Setup
setup: setup-log-dir
touch goonj/src/test/resources/goonj-secret.properties
touch goonj/src/test/resources/avni-secret.properties
touch bahmni/src/test/resources/bahmni-secret.properties
touch amrit/src/test/resources/amrit-secret.properties
touch lahi/src/test/resources/lahi-secret.properties
create-test-db-extensions:
-psql -h localhost -Uavni_int avni_int_test -c 'create extension if not exists "uuid-ossp"';
generatePasswordHash:
ifndef password
$(error ERROR: password not provided.)
endif
ifndef base_url
$(error ERROR: base_url not provided.)
endif
curl -d '{"password":"$(password)"}' -H "Content-Type: application/json" -X POST $(base_url)/int/test/passwordHash