Skip to content

Commit

Permalink
Merge pull request #74 from Aquila-Network/develop
Browse files Browse the repository at this point in the history
improved script + Added Dockerfile
  • Loading branch information
admin-adb authored Dec 26, 2020
2 parents 62c30e7 + d3d604a commit e322375
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 30 deletions.
42 changes: 38 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
FROM ubuntu:latest
# start a new build stage
FROM ubuntu:latest as builder

RUN apt update && apt install -y curl && curl -s -L https://gist.githubusercontent.com/freakeinstein/52694e6c30cb120e4b9325eab02a1bc7/raw/35869c7da5da9a1e0a8835c9de6e25ec7fa31c66/ADB3 | /bin/bash
# set work directory
ENV ROOT_DIR /home/root
WORKDIR $ROOT_DIR

EXPOSE 5000
# install aquiladb
RUN apt update && apt install -y curl && \
curl -s -L https://raw.githubusercontent.com/Aquila-Network/AquilaDB/master/install.sh | /bin/bash

CMD ["source /root/env/bin/activate && cd /root/adb/src && pm2 start index.py && pm2 logs -f"]

# start a new runner stage
FROM ubuntu:latest as runner

# set work directory
ENV ROOT_DIR /home/root
WORKDIR $ROOT_DIR

RUN echo "$ROOT_DIR"

# copy required files from builder stage
COPY --from=builder $ROOT_DIR/env $ROOT_DIR/env
COPY --from=builder $ROOT_DIR/adb $ROOT_DIR/adb
COPY --from=builder /ossl /ossl

# preperations
ENV PATH="$ROOT_DIR/env/bin:$PATH"
WORKDIR $ROOT_DIR
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# install and start demon
RUN export DEBIAN_FRONTEND=noninteractive && mkdir -p /data && apt update && \
apt install -y python3 libgomp1 libblas-dev liblapack-dev && \
printf "#!/bin/bash\nsource env/bin/activate && cd adb/src && \
python3 index.py" > /bin/init.sh && chmod +x /bin/init.sh

# expose port
EXPOSE 5001

ENTRYPOINT ["init.sh"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ If you are serious and wanna dive down the rabbit hole, read our **[whitepapers]
# Install
### Debian

Run `curl -s -L https://raw.githubusercontent.com/Aquila-Network/AquilaDB/master/install.sh | /bin/bash`.
Run `curl -s -L https://raw.githubusercontent.com/Aquila-Network/AquilaDB/master/install.sh | /bin/bash -s -- -d 1 `.

### Docker

**You need docker installed in your system**

Build image (one time process): `docker build https://raw.githubusercontent.com/Aquila-Network/AquilaDB/master/Dockerfile -t aquiladb:local`

Run image (to deploy Aquila DB): `docker run -p 5000:5000 -d aquiladb:local`
Run image (to deploy Aquila DB): `docker run -p 5001:5001 -d aquiladb:local`

# Client SDKs
We currently have multiple client libraries in progress to abstract the communication between deployed Aquila DB and your applications.
Expand Down
47 changes: 25 additions & 22 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
#!/bin/bash -e

# To install from web: apt update && apt install -y curl && curl -s https://gist.githubusercontent.com/freakeinstein/8d39f4e433925753a76922f69af09461/raw/a48b3674c79c205ca187127fb7e128d13fbbb32d/adb_install.sh | bash

export DEBIAN_FRONTEND=noninteractive
apt update

export USER=$(whoami)
export ROOT_DIR=/home/$USER

mkdir -p /data/
cd ~
mkdir -p $ROOT_DIR
cd $ROOT_DIR

gpu=0
test=0
logs=0
demon=0

while getopts g:t:l: flag
while getopts g:t:d: flag
do
case "${flag}" in
g) gpu=${OPTARG};;
t) test=${OPTARG};;
l) logs=${OPTARG};;
d) demon=${OPTARG};;
esac
done

# system packs install
apt install -y git wget nano python3.8 python3-pip libblas-dev liblapack-dev swig libssl-dev nodejs npm
apt install -y git wget nano python3.8 python3-pip libblas-dev liblapack-dev swig libssl-dev

# setup venv
pip3 install virtualenv
virtualenv env
source ./env/bin/activate
virtualenv $ROOT_DIR/env
source $ROOT_DIR/env/bin/activate

# install python packages
pip3 install numpy pycryptodome base58 chardet Flask requests flask_cors PyYAML bson fastjsonschema annoy plyvel

# install pm2
npm i pm2 -g

# install cmake
apt purge --auto-remove cmake

version=3.19
build=1
mkdir -p ~/temp
cd ~/temp
mkdir -p $ROOT_DIR/temp
cd $ROOT_DIR/temp
wget https://cmake.org/files/v$version/cmake-$version.$build.tar.gz
tar -xzvf cmake-$version.$build.tar.gz
cd cmake-$version.$build/
Expand All @@ -53,7 +52,7 @@ make install
cmake --version

# install faiss
cd ~
cd $ROOT_DIR
mkdir -p faiss
cd faiss
git clone https://github.com/facebookresearch/faiss.git .
Expand All @@ -72,10 +71,10 @@ make -C build
cd build/faiss/python
python setup.py install

cp -r ~/faiss/build/faiss/python/ /root/env/lib/python3.8/site-packages/faiss
cp -r $ROOT_DIR/faiss/build/faiss/python/ $ROOT_DIR/env/lib/python3.8/site-packages/faiss

# clone & test AquilaDB
cd ~
cd $ROOT_DIR
mkdir -p adb
cd adb
git clone https://github.com/Aquila-Network/AquilaDB.git .
Expand All @@ -85,7 +84,7 @@ openssl genrsa -passout pass:1234 -des3 -out /ossl/private.pem 2048
openssl rsa -passin pass:1234 -in /ossl/private.pem -outform PEM -pubout -out /ossl/public.pem
openssl rsa -passin pass:1234 -in /ossl/private.pem -out /ossl/private_unencrypted.pem -outform PEM

cd ~/adb/src
cd $ROOT_DIR/adb/src
if [[ $test -eq 1 ]]; # if tests enabled
then
chmod +x run_tests.sh
Expand All @@ -94,15 +93,19 @@ else
echo "Not running tests"
fi

# start server
pm2 start index.py

echo "=========================================="
echo " AquilaDB installation complete. "
echo "=========================================="

if [[ $logs -eq 1 ]]; # if demon run enabled
if [[ $demon -eq 1 ]]; # if demon run enabled
then
# install node
apt install -y nodejs npm
# install pm2
npm i pm2 -g

# start server
pm2 start index.py
# Keep logs alive
pm2 logs -f
fi
2 changes: 1 addition & 1 deletion src/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def flaskserver ():
"""
start server
"""
app.run(host='0.0.0.0', port=80, debug=False)
app.run(host='0.0.0.0', port=5001, debug=False)

if __name__ == "__main__":
server = Process(target=flaskserver)
Expand Down
2 changes: 1 addition & 1 deletion src/test/apis/auth_fns.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_1_auth_create_db (self):
signature = signer.sign(hash)
signature = base58.b58encode(signature).decode("utf-8")

url = "http://127.0.0.1:5000/db/create"
url = "http://127.0.0.1:5001/db/create"

headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/json"
Expand Down

0 comments on commit e322375

Please sign in to comment.