forked from avniproject/avni-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
196 lines (146 loc) · 7.59 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
# <makefile>
# Objects: db, schema, server, package, env (code environment)
# Actions: clean, build, deploy, test
include makefiles/staging.mk
include makefiles/prerelease.mk
include makefiles/util.mk
include makefiles/externalDB.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
# </makefile>
define _deploy_schema
flyway -validateOnMigrate=false -user=openchs -password=password -url=jdbc:postgresql://localhost:5432/$1 -schemas=public -locations=filesystem:./avni-server-api/src/main/resources/db/migration/ -table=schema_version migrate
endef
SU ?= $(shell id -un)
su:=$(SU)
DB=openchs
dbServer=localhost
dbPort=5432
# <postgres>
clean_db_server: _clean_db_server _clean_test_server _drop_roles
_clean_db_server:
make _clean_db database=$(DB)
_clean_test_server:
make _clean_db database=openchs_test
_drop_roles:
-psql -h $(dbServer) -p $(dbPort) -U $(su) -d postgres -c 'drop role openchs';
-psql -h $(dbServer) -p $(dbPort) -U $(su) -d postgres -c 'drop role demo';
-psql -h $(dbServer) -p $(dbPort) -U $(su) -d postgres -c 'drop role openchs_impl';
-psql -h $(dbServer) -p $(dbPort) -U $(su) -d postgres -c 'drop role organisation_user';
_clean_db:
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$(database)' AND pid <> pg_backend_pid()"
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'drop database $(database)';
_build_db:
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c "create user openchs with password 'password' createrole";
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'create database $(database) with owner openchs';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d $(database) -c 'create extension if not exists "uuid-ossp"';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d $(database) -c 'create extension if not exists "ltree"';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d $(database) -c 'create extension if not exists "hstore"';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'create role demo with NOINHERIT NOLOGIN';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'grant demo to openchs';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'create role openchs_impl';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'grant openchs_impl to openchs';
-psql -h $(dbServer) -p $(dbPort) -U ${su} -d postgres -c 'create role organisation_user createrole admin openchs_impl';
# </postgres>
# <db>
## Drops the database
clean_db: _clean_db_server
build_db: ## Creates new empty database
make _build_db database=$(DB)
orgId:= $(if $(orgId),$(orgId),0)
delete_org_meta_data:
psql -h $(dbServer) -p $(dbPort) -U $(su) $(DB) -f avni-server-api/src/main/resources/database/deleteOrgMetadata.sql -v orgId=$(orgId)
delete_org_data:
@echo 'Delete for Organisation ID = $(orgId)'
psql -h $(dbServer) -p $(dbPort) -U $(su) $(DB) -f avni-server-api/src/main/resources/database/deleteOrgData.sql -v orgId=$(orgId)
create_base_local_test_data:
@echo 'Creating base data'
psql -h $(dbServer) -p $(dbPort) -U $(su) $(DB) -f avni-server-api/src/main/resources/database/createBaseLocalTestData.sql
create_local_test_data_only:
newman run postman/local_test_data_setup.json -e postman/localhost.postman_environment.json
create_local_test_data: create_base_local_test_data create_local_test_data_only
recreate_local_test_data: rebuild_db deploy_schema create_local_test_data
rebuild_db: clean_db build_db ## clean + build db
rebuild_dev_db: rebuild_db deploy_schema
restore_db:
psql -U openchs $(DB) -f $(sqlfile)
# </db>
# <testdb>
backup_db:
sudo -u $(su) pg_dump openchs > avni-server-api/target/backup.sql
clean_testdb: ## Drops the test database
make _clean_db database=openchs_test
_create_demo_organisation:
-psql -h $(dbServer) -p $(dbPort) -U $(su) -d $(database) -f make-scripts/create_demo_organisation.sql
build_testdb: ## Creates new empty database of test database
make _build_db database=openchs_test
# make _create_demo_organisation database=openchs_test
rebuild_testdb: clean_testdb build_testdb ## clean + build test db
# </testdb>
# <schema>
deploy_schema: ## Runs all migrations to create the schema with all the objects
$(call _deploy_schema,$(DB))
deploy_test_schema: ## Runs all migrations to create the schema with all the objects
$(call _deploy_schema,openchs_test)
# </schema>
# <server>
start_server: build_server
OPENCHS_DATABASE=$(DB) AVNI_IDP_TYPE=none java -jar avni-server-api/build/libs/avni-server-0.0.1-SNAPSHOT.jar
start_server_keycloak: build_server
OPENCHS_MODE=on-premise OPENCHS_DATABASE=$(DB) AVNI_IDP_TYPE=keycloak java -jar avni-server-api/build/libs/avni-server-0.0.1-SNAPSHOT.jar
start_server_remote_db: build_server
OPENCHS_DATABASE_URL=jdbc:postgresql://192.168.33.11:5432/openchs?currentSchema=public java -jar avni-server-api/build/libs/avni-server-0.0.1-SNAPSHOT.jar
debug_server: build_server
AVNI_IDP_TYPE=none OPENCHS_DATABASE=$(DB) java -Xmx2048m -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar avni-server-api/build/libs/avni-server-0.0.1-SNAPSHOT.jar
debug_server_remote_db: build_server
OPENCHS_DATABASE_URL=jdbc:postgresql://192.168.33.11:5432/openchs?currentSchema=public java -Xmx2048m -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar avni-server-api/build/libs/avni-server-0.0.1-SNAPSHOT.jar
build_server: ## Builds the jar file
./gradlew clean build -x test
boot_run:
OPENCHS_DATABASE=$(DB) ./gradlew bootRun
test_server: rebuild_testdb ## Run tests
GRADLE_OPTS="-Xmx256m" ./gradlew clean test
test_server_with_remote_db:
make rebuild_testdb su=$(DBUSER) dbServer=$(DBSERVER)
OPENCHS_DATABASE_URL=jdbc:postgresql://$(DBSERVER):5432/openchs_test GRADLE_OPTS="-Xmx256m" ./gradlew clean test
test_external:
./gradlew externalTest
start_server_wo_gradle:
AVNI_IDP_TYPE=none java -jar avni-server-api/build/libs/avni-server-0.0.1-SNAPSHOT.jar
# LIVE
log_live:
tail -f /var/log/openchs/openchs.log
# /LIVE
tail-local-log:
tail -f -n1000 /var/log/openchs/openchs.log
debug_server_live: build_server
OPENCHS_MODE=live OPENCHS_CLIENT_ID=$(STAGING_APP_CLIENT_ID) OPENCHS_USER_POOL=$(STAGING_USER_POOL_ID) java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar avni-server-api/build/libs/avni-server-0.0.1-SNAPSHOT.jar
# <server>
ci-test:
-psql -h $(dbServer) -p $(dbPort) -Uopenchs openchs_test -c 'create extension if not exists "uuid-ossp"';
-psql -h $(dbServer) -p $(dbPort) -Uopenchs openchs_test -c 'create extension if not exists "ltree"';
-psql -h $(dbServer) -p $(dbPort) -Uopenchs openchs_test -c 'create extension if not exists "hstore"';
make test_server
open_test_results:
open avni-server-api/build/reports/tests/test/index.html
build-rpm:
./gradlew clean avni-server-api:buildRpm -x test --info --stacktrace
upload-rpm:
@openssl aes-256-cbc -a -md md5 -in infra/rpm/keys/openchs.asc.enc -d -out infra/rpm/keys/openchs.asc -k ${ENCRYPTION_KEY}
-rm -rf avni-server-api/build
./gradlew clean avni-server-api:uploadRpm -x test --info --stacktrace --rerun-tasks
# <exec-sql>
exec-sql: ## Usage: make exec-sql sqlfile=</path/to/sql>
psql -Uopenchs -f $(sqlfile)
# </exec-sql>
# remote
tail-prod:
ssh avni-server-prod "tail -f /var/log/openchs/openchs.log"