Skip to content

Commit 338fa2f

Browse files
krivarddshemetov
authored andcommitted
Local-development helper scripts
1 parent 80ae21b commit 338fa2f

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

dev/local/epidata-refresh.sh

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
3+
if [ -z "$1" ]; then
4+
echo "USAGE:"
5+
echo "$0 [database] [web] [python] [testdir|test.py ...]"
6+
echo "Docker control panel for delphi-epidata development"
7+
echo
8+
echo " Assumes you have installed your environment using"
9+
echo " delphi-epidata/dev/local/install.sh."
10+
echo
11+
echo " Cleans up dangling Docker images before starting."
12+
echo
13+
echo " Checks for the delphi-net bridge, and creates it if it doesn't exist."
14+
echo
15+
echo " Creates all prereq images (delphi_database, delphi_python) only if they don't"
16+
echo " exist. If you need to rebuild a prereq, you're probably doing something"
17+
echo " complicated, and can figure out the rebuild command on your own."
18+
echo
19+
echo " database: Stops currently-running delphi_database_epidata instances, if any."
20+
echo " Rebuilds delphi_database_epidata image."
21+
echo " Runs image in the background and pipes stdout to a log file."
22+
echo " Blocks until database is ready to receive connections."
23+
echo
24+
echo " web: Stops currently-running delphi_web_epidata instances, if any."
25+
echo " Rebuilds delphi_web_epidata image."
26+
echo " Runs image in the background and pipes stdout to a log file."
27+
echo
28+
echo " python: Rebuilds delphi_web_python image. You shouldn't need to do this"
29+
echo " often; only if you are installing a new environment, or have"
30+
echo " made changes to delphi-epidata/dev/docker/python/Dockerfile."
31+
echo
32+
echo " Loops through the remaining arguments and runs them as pytest within the"
33+
echo " delphi_web_python image. This uses bindmounts into the local filesystem,"
34+
echo " so any changes you have made to src/acquisition/, tests/, or integrations/"
35+
echo " will automatically take effect without having to rebuild delphi_web_python."
36+
echo " Saves all test output to output.txt for review, in case it excees your"
37+
echo " terminal buffer. Halts on first failure and lists failed tests."
38+
echo
39+
echo " Always run this from the `driver` directory. Never put anything other than"
40+
echo " code in the `driver` directory, since everything under the `driver` directory"
41+
echo " will get folded into the Docker images created. If it takes more than 1m to"
42+
echo " build Docker images, you have probably accidentally stored other data in the"
43+
echo " `driver` directory tree."
44+
echo
45+
echo " Depending on your operating system, you may need to be root or use sudo."
46+
exit 0
47+
fi
48+
49+
docker images -f "dangling=true" -q | xargs docker rmi >/dev/null 2>&1
50+
docker network ls | grep delphi-net || docker network create --driver bridge delphi-net
51+
52+
LOGS=../driver-logs
53+
NOW=`date "+%Y-%m-%d`
54+
55+
if [ "$1" == "database" ]; then
56+
shift
57+
LOGFILE=${LOGS}/delphi_database_epidata/${NOW}.log
58+
docker ps | grep delphi_database_epidata && docker stop delphi_database_epidata
59+
# only build prereqs if we need them
60+
docker images delphi_database | grep delphi || \
61+
docker build -t delphi_database -f repos/delphi/operations/dev/docker/database/Dockerfile . || exit 1
62+
docker build -t delphi_database_epidata -f repos/delphi/delphi-epidata/dev/docker/database/epidata/Dockerfile . || exit 1
63+
docker run --rm -p 127.0.0.1:13306:3306 --network delphi-net --name delphi_database_epidata delphi_database_epidata \
64+
>${LOGFILE} 2>&1 &
65+
while true; do
66+
sed -n '/Temporary server stopped/,/mysqld: ready for connections/p' ${LOGFILE} | grep "ready for connections" && break
67+
tail -1 ${LOGFILE}
68+
sleep 1
69+
done
70+
grep ERROR ${LOGFILE} && exit 1
71+
fi
72+
73+
if [ "$1" == "web" ]; then
74+
shift
75+
docker ps | grep delphi_web_epidata && docker stop delphi_web_epidata
76+
cd repos/delphi/delphi-epidata && docker build -t delphi_web_epidata -f ./devops/Dockerfile . && cd - || exit 1
77+
docker run --rm -p 127.0.0.1:10080:80 \
78+
--env "SQLALCHEMY_DATABASE_URI=mysql+mysqldb://user:pass@delphi_database_epidata:3306/epidata" \
79+
--env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" \
80+
--network delphi-net --name delphi_web_epidata delphi_web_epidata >>${LOGS}/delphi_web_epidata/${NOW}.log 2>&1 &
81+
fi
82+
if [ "$1" == "python" ]; then
83+
shift
84+
# only build prereqs if we need them
85+
docker images delphi_python | grep delphi || \
86+
docker build -t delphi_python -f repos/delphi/operations/dev/docker/python/Dockerfile . || exit 1
87+
docker build -t delphi_web_python \
88+
-f repos/delphi/delphi-epidata/dev/docker/python/Dockerfile . || exit 1
89+
fi
90+
rm -f output.txt
91+
for t in $@; do
92+
set -x
93+
docker run --rm --network delphi-net \
94+
--mount type=bind,source="$(pwd)"/repos/delphi/delphi-epidata,target=/usr/src/app/repos/delphi/delphi-epidata,readonly \
95+
--mount type=bind,source="$(pwd)"/repos/delphi/delphi-epidata/src,target=/usr/src/app/delphi/epidata,readonly \
96+
--env "SQLALCHEMY_DATABASE_URI=mysql+mysqldb://user:pass@delphi_database_epidata:3306/epidata" --env "FLASK_SECRET=abc" \
97+
delphi_web_python \
98+
python -m pytest --import-mode importlib $t | tee -a output.txt
99+
set +x
100+
[[ $? = "0" ]] || exit 1
101+
grep -e "FAIL" -e "tests did not pass" output.txt && exit 1
102+
done

dev/local/install.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
mkdir -p driver/repos/delphi driver-logs
4+
cd driver/repos/delphi
5+
git clone https://github.com/cmu-delphi/operations
6+
git clone https://github.com/cmu-delphi/delphi-epidata
7+
git clone https://github.com/cmu-delphi/utils
8+
cd ../../
9+
ln -s repos/delphi/delphi-epidata/dev/local/epidata-refresh.sh
10+
chmod a+x epidata-refresh.sh

0 commit comments

Comments
 (0)