-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
215 lines (166 loc) · 8.04 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
#!make
include .env
SHELL := /bin/bash
ROOT := ./deploy/develop/databases
ROOT_PROD := ./deploy/production/databases
SERVERCFS := $(ROOT)/configs/servers
SQLSCRIPTS := $(ROOT)/scripts
SCHEMA:= tableros
#####################
# DEVELOP INFRASTRUCTURE
#####################
envfile:
@echo ":::::: Generating envfile for infrastructure"
cp .env.example .env
start:
@echo ":::::: Starting dockerized infrastructure"
docker-compose -p arphai -f docker-compose.yml -f docker-compose.develop.yml up -d --remove-orphans
stop:
@echo ":::::: Stopping dockerized infrastructure"
docker-compose -p arphai -f docker-compose.yml -f docker-compose.develop.yml stop
down:
@echo ":::::: Stopping dockerized infrastructure"
docker-compose -p arphai -f docker-compose.yml -f docker-compose.develop.yml down
reset:
@echo ":::::: Resetting dockerized infrastructure"
make stop
make start
hard-reset:
@echo ":::::: Resetting volumes"
make full-down
make start
full-down:
@echo "::::::: Full Down"
make down
docker image rm arphai_backend
docker volume rm arphai_dashboard-psqlserver-volume arphai_pgadmin-service-volume
#####################
# DB-DEVELOP
#####################
recreate-db-develop:
make load-public-schema
make create-dashboard-schema
make load-data-dashboard
make load-csv-snvs
make cube-restart
create-dashboard-schema:
@echo ":::::: Create DASHBOARD DB Schema"
docker cp $(SQLSCRIPTS)/schemas/01-create-dashboard-schema.sql postgres-dashboard:/01-create-dashboard-schema.sql
docker exec -i postgres-dashboard psql -U $(PG_USER) -d $(PG_DBNAME) -f 01-create-dashboard-schema.sql
docker cp $(SQLSCRIPTS)/schemas/02-create-esquemasnvs.sql postgres-dashboard:/02-create-esquemasnvs.sql
docker exec -i postgres-dashboard psql -U $(PG_USER) -d $(PG_DBNAME) -f 02-create-esquemasnvs.sql
docker cp $(SQLSCRIPTS)/schemas/03-create-snvs-index.sql postgres-dashboard:/03-create-snvs-index.sql
docker exec -i postgres-dashboard psql -U $(PG_USER) -d $(PG_DBNAME) -f 03-create-snvs-index.sql
docker cp $(SQLSCRIPTS)/schemas/04-create-esquema-snvs-dengue.sql postgres-dashboard:/04-create-esquema-snvs-dengue.sql
docker exec -i postgres-dashboard psql -U $(PG_USER) -d $(PG_DBNAME) -f 04-create-esquema-snvs-dengue.sql
docker cp $(SQLSCRIPTS)/schemas/06-create-dashboard-views.sql postgres-dashboard:/06-create-dashboard-views.sql
docker exec -i postgres-dashboard psql -U $(PG_USER) -d $(PG_DBNAME) -f 06-create-dashboard-views.sql
load-public-schema:
@echo ":::::: Load Public DB Schema"
docker cp $(SQLSCRIPTS)/schemas/07-backup-public.sql postgres-dashboard:/07-backup-public.sql
docker exec -i postgres-dashboard psql -U $(PG_USER) -d $(PG_DBNAME) -f 07-backup-public.sql
load-dashboard-changes:
@echo ":::::: Create DASHBOARD DB Schema and load data"
make create-dashboard-schema
make load-public-schema
make load-data-dashboard
make cube-restart
load-data-dashboard:
@echo ":::::: Load SVNS table and DASHBOARD DB data "
docker cp $(SQLSCRIPTS)/onlydata/only-data-dashboard.sql postgres-dashboard:/only-data-dashboard.sql
docker exec -i postgres-dashboard psql -U $(PG_USER) -d $(PG_DBNAME) -f only-data-dashboard.sql
make load-csv-snvs-dengue
load-csv-snvs:
docker cp $(SQLSCRIPTS)/onlydata/snvs-covid19.csv postgres-dashboard:/snvs-covid19.csv
docker exec postgres-dashboard psql -U $(PG_USER) -d $(PG_DBNAME) -c "SET datestyle = 'ISO, DMY';COPY tableros.snvs FROM '/snvs-covid19.csv' WITH (FORMAT csv);"
load-csv-snvs-dengue:
docker cp $(SQLSCRIPTS)/onlydata/snvs-dengue.csv postgres-dashboard:/snvs-dengue.csv
docker exec postgres-dashboard psql -U $(PG_USER) -d $(PG_DBNAME) -c "SET datestyle = 'ISO, DMY';COPY tableros.snvs_dengue FROM '/snvs-dengue.csv' WITH (FORMAT csv);"
backup-snvs-table:
@echo ":::::: Dump SVNS table"
docker exec postgres-dashboard pg_dump -F c -U $(PG_USER) -d $(PG_DBNAME) --data-only -t tableros.snvs > $(SQLSCRIPTS)/dump/table-snvs.dump
restore-snvs-table:
@echo ":::::: Load SNVS table"
docker cp $(SQLSCRIPTS)/dump/table-snvs.dump postgres-dashboard:/table-snvs.dump
docker exec postgres-dashboard pg_restore -U $(PG_USER) --no-password -d $(PG_DBNAME) -t snvs --verbose table-snvs.dump
drop-dashboard-schema:
@echo ":::::: Dropping DASHBOARD DB Schema"
make backup-snvs-table
docker exec postgres-dashboard psql -U $(PG_USER) -d $(PG_DBNAME) -c "DROP SCHEMA IF EXISTS $(SCHEMA) CASCADE;"
restore-db-dump:
@echo ":::::: Restoring DUMP DB from file"
docker cp $(BACKUP_FILE) postgres-dashboard:/backup.dump
docker exec postgres-dashboard psql -h localhost -U $(PG_USER) -d $(PG_DBNAME) -f /backup.dump
drop-all-db:
@echo ":::::: Delete all DB in Postgres"
make down
docker volume rm arphai-dashboard_dashboard-psqlserver-volume
make start
#####################
# PRODUCTION DB
#####################
create-file-dashboard-prod:
PG_USER=$(PG_USER) envsubst < $(ROOT_PROD)/scripts/template/01-populate-dashboard-schema-prod-template > $(ROOT_PROD)/scripts/01-populate-dashboard-schema-prod.sql
PG_USER=$(PG_USER) envsubst < $(ROOT_PROD)/scripts/template/02-create-dashboard-views-prod-template > $(ROOT_PROD)/scripts/02-create-dashboard-views-prod.sql
recreate-data-dashboard-prod:
make create-file-dashboard-prod
PGPASSWORD=$(PG_PASSWORD) psql -h $(PG_HOST) -U $(PG_USER) -d $(PG_DBNAME) -p $(PG_PORT) -f $(ROOT_PROD)/scripts/01-populate-dashboard-schema-prod.sql
PGPASSWORD=$(PG_PASSWORD) psql -h $(PG_HOST) -U $(PG_USER) -d $(PG_DBNAME) -p $(PG_PORT) -f $(ROOT_PROD)/scripts/02-create-dashboard-views-prod.sql
PGPASSWORD=$(PG_PASSWORD) psql -h $(PG_HOST) -U $(PG_USER) -d $(PG_DBNAME) -p $(PG_PORT) -f $(ROOT_PROD)/scripts/onlydata/only-data-dashboard.sql
PGPASSWORD=$(PG_PASSWORD) psql -h $(PG_HOST) -U $(PG_USER) -d $(PG_DBNAME) -p $(PG_PORT) -f $(ROOT_PROD)/scripts/onlydata/only-data-snvs-dengue.sql
recreate-in-new-db:
@echo ":::::: Recreate DB"
PGPASSWORD=$(PG_PASSWORD) psql -h $(PG_HOST) -U $(PG_USER) -d $(PG_DBNAME) -p$(PG_PORT) -f $(SQLSCRIPTS)/schemas/03-create-snvs-index.sql
PGPASSWORD=$(PG_PASSWORD) psql -h $(PG_HOST) -U $(PG_USER) -d $(PG_DBNAME) -p$(PG_PORT) -f $(SQLSCRIPTS)/schemas/07-backup-public.sql
run-file-in-db:
@echo ":::::: File In DB"
PGPASSWORD=$(PG_PASSWORD) psql -h $(PG_HOST) -U $(PG_USER) -d $(PG_DBNAME) -p$(PG_PORT) -f $(FILE)
#####################
# PRODUCTION INFRASTRUCTURE
#####################
build-prod:
make build-frontend
docker-compose -p arphai -f docker-compose.yml -f docker-compose.production.yml build
start-prod:
@echo ":::::: Starting dockerized production infrastructure"
docker-compose -p arphai -f docker-compose.yml -f docker-compose.production.yml up -d
stop-prod:
@echo ":::::: Stopping dockerized production infrastructure"
docker-compose -p arphai -f docker-compose.yml -f docker-compose.production.yml down
reset-prod:
@echo ":::::: Resetting dockerized production infrastructure"
make stop-prod
make start-prod
down-prod:
docker-compose -p arphai -f docker-compose.yml -f docker-compose.production.yml down
#####################
# GENERALS
#####################
build-frontend:
@echo ":::::: Build Vite frontend"
npm install -g vite
npm install
npm run build
cube-restart:
@echo ":::::: Restart Cube"
docker restart cube-dashboard
cmd-dashboard:
docker exec -i postgres-dashboard bash -c "$(CMD)"
run-query:
docker exec -i postgres-dashboard psql -U $(PG_USER) -d $(PG_DBNAME) -c "$(QUERY)"
run-query-file:
docker cp $(SQLSCRIPTS)/$(FILE).sql postgres-dashboard:/$(FILE).sql
docker exec -i postgres-dashboard psql -U $(PG_USER) -d $(PG_DBNAME) -f $(FILE).sql
killALL:
docker-compose down && docker volume prune
change-password:
docker exec postgres-dashboard psql -h localhost -U $(PG_USER) -c "ALTER USER $(PG_USER) PASSWORD '$(PG_PASSWORD)';"
#####################
# DB-GENERALS
#####################
dump-schema:
@echo ":::::: Dumping DASHBOARD DB Schema"
docker exec postgres-dashboard pg_dump -F c -U $(PG_USER) -s $(PG_DBNAME) -n $(SCHEMA) > $(SQLSCRIPTS)/dump/schema-$(SCHEMA).dump
restore-schema:
@echo ":::::: Restoring DASHBOARD DB Schema"
docker exec postgres-dashboard pg_restore -U $(PG_USER) --no-password -d $(PG_DBNAME) --schema-only --verbose scripts/schema-$(SCHEMA).dump