-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
executable file
·215 lines (178 loc) · 5.34 KB
/
run.sh
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
#!/bin/bash
# CALL STRUCTURE: sh run.sh <command>
# EXAMPLE: sh run.sh start
# more docs are in the docs/run.md file
COMPOSE_CONFIG=docker-compose.yml
function all() {
start
}
function quickstart() {
start
add_foldseek
add_tmalign
}
function start() {
docker compose -f $COMPOSE_CONFIG up -d
}
function stop() {
docker compose -f $COMPOSE_CONFIG down
}
# generates the api bridge between frontend and backend
function gen_api() {
cd frontend
yarn openapi && docker compose -f $COMPOSE_CONFIG restart frontend
cd ..
}
# clears the postgres persistent storage
function rm_volume() {
stop
docker volume rm venome_postgres_data
start
}
function sql_date_backup() {
docker exec -t venome-postgres pg_dump --dbname=postgresql://myuser:mypassword@0.0.0.0:5432/venome --inserts > backend/backups/dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
}
function sql_dump() {
if [ "$1" != "" ]; then
docker exec -t venome-postgres pg_dump --dbname=postgresql://myuser:mypassword@0.0.0.0:5432/venome --inserts > $1
else
echo "ERROR: .sql file not specified."
fi
}
function sql_delete() {
rm_volume
}
function sql_source() {
# holy shit this is scuffed
# in production mode, need to copy over stuff
if [ "$1" != "" ]; then
temp_file=temp.sql
docker cp $1 venome-postgres:/$temp_file # send over the sql file to postgres server
docker exec -t venome-postgres psql --dbname=postgresql://myuser:mypassword@0.0.0.0:5432/venome -f $temp_file # execute the sql file
docker exec -t venome-postgres rm -f $temp_file
else
echo "ERROR: .sql file not specified."
fi
}
function sql_reload() {
sql_delete
sleep 5 # not sure why this works, but a delay is needed oddly sql_delete takes time to finish
sql_source $1
}
function backup() {
if [ "$1" != "" ]; then
mkdir $1
sql_dump $1/dump.sql
docker cp venome-backend:/app/src/data/stored_proteins/ $1
else
echo "ERROR: backup name not specified."
fi
}
function reload_from_backup() {
if [ "$1" != "" ]; then
docker exec -t venome-backend rm -fr src/data/stored_proteins # remove what's already there
docker cp $1/stored_proteins/ venome-backend:/app/src/data/stored_proteins/ # send over our backup files to docker
sleep 5
sql_reload $1/dump.sql # reload from the schema
else
echo "ERROR: backup name not specified."
fi
}
function restart_venv() {
cd backend
poetry config virtualenvs.in-project true
poetry env list; poetry env remove --all
poetry install
cd ..
}
# opens up the postgresql shell which directly accesses the db in the container
function psql() {
start # make sure the docker is running
docker exec -it venome-postgres bash -c 'psql postgresql://myuser:mypassword@0.0.0.0:5432/venome'
}
function test_backend() {
cd backend
poetry run pytest
cd ..
}
function install_frontend() {
docker exec -it venome-frontend yarn install
}
function install_backend() {
docker exec -it venome-backend poetry install
}
function restart() {
stop
start
}
# on the docker container, reinstall all packages listed in local env (package.json, poetry.lock)
function refresh_packages() {
start
install_frontend
install_backend
restart
}
# complete from scratch rebuild
function restart_from_scratch() {
stop
docker compose -f $COMPOSE_CONFIG up --build -d
}
function add_foldseek() {
docker exec -it venome-backend wget --no-check-certificate https://mmseqs.com/foldseek/foldseek-linux-sse2.tar.gz
docker exec -it venome-backend tar -xvf foldseek-linux-sse2.tar.gz
docker exec -it venome-backend rm -f foldseek-linux-sse2.tar.gz
}
function remove_foldseek() {
docker exec -it venome-backend rm -f foldseek-linux-sse2.tar.gz*
docker exec -it venome-backend rm -fr foldseek/
}
function add_tmalign() {
docker exec -it venome-backend wget --no-check-certificate https://seq2fun.dcmb.med.umich.edu//TM-align/TMalign_cpp.gz
docker exec -it venome-backend mkdir tmalign
docker exec -it venome-backend gzip -d TMalign_cpp.gz
docker exec -it venome-backend mv TMalign_cpp tmalign/tmalign
docker exec -it venome-backend chmod a+x tmalign/tmalign
docker exec -it venome-backend rm -f TMalign_cpp.gz
}
function remove_tmalign() {
docker exec -it venome-backend rm -f TMalign_cpp.gz*
docker exec -it venome-backend rm -fr tmalign/
}
function rebuild_venome_molstar_pkg() {
# build locally
cd frontend
yarn build:venome_molstar
# build on docker
docker exec -it venome-frontend cd frontend
docker exec -it venome-frontend yarn build:venome_molstar
}
function scrape_func_names() {
functions=($(grep -oE 'function[[:space:]]+[a-zA-Z_][a-zA-Z_0-9]*' ./run.sh | sed 's/function[[:space:]]*//'))
}
# CALL THE COMMAND FROM THE COMMAND LINE ARGUMENT
#
# for example `sh run.sh start` will run the start function
# if no command line args, just run the all function
if [ -z "$1" ]; then
all
exit 0
fi
# otherwise run the user specified command
scrape_func_names
for func in "${functions[@]}"; do
# if the func exists in this file, and the first cmd line arg matches the func name,
# run the func
if [ "$1" == "$func" ]; then
if [ "$2" == "-p" ]; then
# if you put a -p after the function name, indicates production config
COMPOSE_CONFIG=docker-compose-prod.yml
$1 $3 # $2 was -p so rest of arguments onwards $3 is second arg now
else
$1 $2 # $2 and on are arguments passed into the $1 function
fi
exit 0
fi
done
# if we get to this point, the command does not exist
echo "ERROR: command '$1' does not exist"
exit 1