Skip to content

Commit

Permalink
complete docker example with commented out db feature
Browse files Browse the repository at this point in the history
  • Loading branch information
salivian committed Sep 18, 2020
1 parent 88f76f9 commit c77d259
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
13 changes: 8 additions & 5 deletions docker-app/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ cd /nanocube-src
bash -c '/nanocube/bin/nanocube create <(gunzip -c ./data/crime50k.csv.gz) ./data/crime50k.map /data/crime50k.nanocube -header'

#sample database
apt-get install --no-install-recommends --no-install-suggests -y \
python3-pip python3
pip3 install --no-cache-dir fastapi uvicorn pandas sqlalchemy
python3 -c 'import pandas as pd;from sqlalchemy import create_engine; pd.read_csv("data/crime50k.csv.gz").to_sql("crimes",create_engine("sqlite:////data/crimes50k.db"))'
#apt-get install --no-install-recommends --no-install-suggests -y \
# python3-pip python3
#pip3 install --no-cache-dir fastapi uvicorn gunicorn \
# python-multipart pandas sqlalchemy

#python3 -c 'import pandas as pd;from sqlalchemy import create_engine; d=pd.read_csv("data/crime50k.csv.gz");d=d.rename(columns={"Date":"time","Primary Type":"type"}); d.time=pd.to_datetime(d.time); d.to_sql("crime",create_engine("sqlite:////data/crime50k.db"),index=False)'


#cleanup
apt-get remove --purge -y build-essential git python3-pip
apt-get remove --purge -y build-essential git
apt-get autoremove -y && apt-get clean
rm -rf /var/lib/apt/lists/*
rm -rf /nanocube-src
2 changes: 2 additions & 0 deletions docker-app/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"sqldb_url": "/dbrest/data",
"sqldb_url": null,
"nanocube": {
"nc": {
"url": "/nanocube"
Expand Down
6 changes: 6 additions & 0 deletions docker-app/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ http {
rewrite ^/nanocube/(.*)$ /$1 break;
proxy_pass http://localhost:54321;
}

#run nanocubes on 54322
location ~* /dbrest/(.*)$ {
rewrite ^/dbrest/(.*)$ /$1 break;
proxy_pass http://localhost:54322;
}
}
}
9 changes: 8 additions & 1 deletion docker-app/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ export NCDIR=$2
export WEBCONFIG=$3
export DBFILE=$4

echo NAME=$NAME
echo NCDIR=$NCDIR
echo WEBCONFIG=$WEBCONFIG
echo DBFILE=$DBFILE

#link custom web config to /www
ln -s $WEBCONFIG /www/config.json

#start webserver
nginx -c /app/nginx.conf

#start db rest server
uvicorn /nanocube/bin/db_rest_server:app --port 54322 &
cd /nanocube/bin
gunicorn -D -w 4 -k uvicorn.workers.UvicornWorker -b 127.0.0.1:54322 \
db_rest_server:app

#start nanocubes server with all the nanocube files
/nanocube/bin/nanocube serve 54321 $NAME=`ls -1 $NCDIR/*.nanocube|paste -sd ':'`

0 comments on commit c77d259

Please sign in to comment.