From 9f9b69e1530bbb20d7389a922c0b3a92663c8caa Mon Sep 17 00:00:00 2001 From: Poorna Chandra Tejasvi Date: Thu, 22 Aug 2019 22:36:26 +0530 Subject: [PATCH] Added quick install option --- .travis.yml | 4 +- misc/download_asset.sh | 40 ++++++++++++ setup/broker/broker_install.sh | 10 --- setup/broker/broker_reset.sh | 12 ---- setup/broker/broker_start.sh | 6 -- setup/dbconnector/dbconnector_install.sh | 9 --- .../dbconnector/dbconnector_quick_install.sh | 12 ---- setup/dbconnector/dbconnector_start.sh | 12 ---- setup/elk/elk_install.sh | 5 -- setup/elk/elk_start.sh | 13 ---- setup/pgsql/daemon.py | 64 ------------------- setup/pgsql/pgsql_install.sh | 20 ------ setup/pgsql/pgsql_reset.sh | 3 - setup/pgsql/pgsql_start.sh | 9 --- setup/vertx/vertx_install.sh | 9 --- setup/vertx/vertx_quick_install.sh | 12 ---- setup/vertx/vertx_start.sh | 13 ---- single-node/quick_install | 38 +++++++++-- 18 files changed, 76 insertions(+), 215 deletions(-) create mode 100755 misc/download_asset.sh delete mode 100755 setup/broker/broker_install.sh delete mode 100755 setup/broker/broker_reset.sh delete mode 100755 setup/broker/broker_start.sh delete mode 100755 setup/dbconnector/dbconnector_install.sh delete mode 100755 setup/dbconnector/dbconnector_quick_install.sh delete mode 100755 setup/dbconnector/dbconnector_start.sh delete mode 100755 setup/elk/elk_install.sh delete mode 100755 setup/elk/elk_start.sh delete mode 100644 setup/pgsql/daemon.py delete mode 100755 setup/pgsql/pgsql_install.sh delete mode 100755 setup/pgsql/pgsql_reset.sh delete mode 100755 setup/pgsql/pgsql_start.sh delete mode 100755 setup/vertx/vertx_install.sh delete mode 100755 setup/vertx/vertx_quick_install.sh delete mode 100755 setup/vertx/vertx_start.sh diff --git a/.travis.yml b/.travis.yml index 4d71d961..e1c63a1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,10 +10,10 @@ language: python python: 2.7 install: - - ./single-node/install + - ./single-node/quick_install before_script: - - sleep 300 + - sleep 10 script: - ./tests/single-node/test functional --random diff --git a/misc/download_asset.sh b/misc/download_asset.sh new file mode 100755 index 00000000..de376853 --- /dev/null +++ b/misc/download_asset.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# Script to download asset file from tag release using GitHub API v3. +# See: http://stackoverflow.com/a/35688093/55075 +CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" + +# Check dependencies. +set -e +type curl grep sed tr >&2 +xargs=$(which gxargs || which xargs) + +# Validate settings. +[ -f ~/.secrets ] && source ~/.secrets +[ "$GITHUB_API_TOKEN" ] || { echo "Error: Please define GITHUB_API_TOKEN variable." >&2; exit 1; } +[ $# -ne 4 ] && { echo "Usage: $0 [owner] [repo] [tag] [name]"; exit 1; } +[ "$TRACE" ] && set -x +read owner repo tag name <<<$@ + +# Define variables. +GH_API="https://api.github.com" +GH_REPO="$GH_API/repos/$owner/$repo" +GH_TAGS="$GH_REPO/releases/tags/$tag" +AUTH="Authorization: token $GITHUB_API_TOKEN" +WGET_ARGS="--content-disposition --auth-no-challenge --no-cookie" +CURL_ARGS="-LJO#" + +# Validate token. +curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or network issue!"; exit 1; } + +# Read asset tags. +response=$(curl -sH "$AUTH" $GH_TAGS) +# Get ID of the asset based on given name. +eval $(echo "$response" | grep -C3 "name.:.\+$name" | grep -w id | tr : = | tr -cd '[[:alnum:]]=') +#id=$(echo "$response" | jq --arg name "$name" '.assets[] | select(.name == $name).id') # If jq is installed, this can be used instead. +[ "$id" ] || { echo "Error: Failed to get asset id, response: $response" | awk 'length($0)<100' >&2; exit 1; } +GH_ASSET="$GH_REPO/releases/assets/$id" + +# Download asset file. +echo "Downloading asset..." >&2 +curl $CURL_ARGS -H 'Accept: application/octet-stream' "$GH_ASSET?access_token=$GITHUB_API_TOKEN" +echo "$0 done." >&2 diff --git a/setup/broker/broker_install.sh b/setup/broker/broker_install.sh deleted file mode 100755 index 3b67db9c..00000000 --- a/setup/broker/broker_install.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/ash -cd authenticator -kodev build > /dev/null 2>/dev/null -tmux new-session -d -s authenticator 'cd /authenticator && kodev run' -rabbitmq-server -detached > /dev/null 2>&1 - -while ! nc -z localhost 5672 - do - sleep 0.1 - done diff --git a/setup/broker/broker_reset.sh b/setup/broker/broker_reset.sh deleted file mode 100755 index f2238769..00000000 --- a/setup/broker/broker_reset.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/ash - -rabbitmqctl stop -rabbitmqctl reset -tmux kill-server -fuser -k 80/tcp - -cd authenticator -kodev build > /dev/null 2>/dev/null -tmux new-session -d -s authenticator 'cd /authenticator && kodev run' -rabbitmq-server -detached > /dev/null 2>&1 - diff --git a/setup/broker/broker_start.sh b/setup/broker/broker_start.sh deleted file mode 100755 index 7a910739..00000000 --- a/setup/broker/broker_start.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/ash - -rm -r /tmp/tmux-* > /dev/null 2>&1 -kodev build > /dev/null 2>/dev/null -tmux new-session -d -s authenticator 'cd /authenticator && kodev run' -rabbitmq-server -detached > /dev/null 2>&1 diff --git a/setup/dbconnector/dbconnector_install.sh b/setup/dbconnector/dbconnector_install.sh deleted file mode 100755 index cf71101e..00000000 --- a/setup/dbconnector/dbconnector_install.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -cd iudx-dbconnector - -mvn clean compile assembly:single - -cp target/iudx-dbconnector-0.0.1-SNAPSHOT-jar-with-dependencies.jar . - -tmux new-session -d -s dbconnector 'java -jar iudx-dbconnector-0.0.1-SNAPSHOT-jar-with-dependencies.jar -d64 -Xms512m -Xmx4g' diff --git a/setup/dbconnector/dbconnector_quick_install.sh b/setup/dbconnector/dbconnector_quick_install.sh deleted file mode 100755 index 49ff031b..00000000 --- a/setup/dbconnector/dbconnector_quick_install.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -cd iudx-dbconnector - -if [ -e iudx-dbconnector-0.0.1-SNAPSHOT-jar-with-dependencies.jar ] -then -rm iudx-dbconnector-0.0.1-SNAPSHOT-jar-with-dependencies.jar -fi - -cp target/iudx-dbconnector-0.0.1-SNAPSHOT-jar-with-dependencies.jar . - -tmux new-session -d -s dbconnector 'java -jar iudx-dbconnector-0.0.1-SNAPSHOT-jar-with-dependencies.jar -d64 -Xms512m -Xmx4g' diff --git a/setup/dbconnector/dbconnector_start.sh b/setup/dbconnector/dbconnector_start.sh deleted file mode 100755 index 9c11d348..00000000 --- a/setup/dbconnector/dbconnector_start.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -rm -r /tmp/tmux-* > /dev/null 2>&1 - -cd iudx-dbconnector - -mvn clean compile assembly:single - -cp target/iudx-dbconnector-0.0.1-SNAPSHOT-jar-with-dependencies.jar . - -tmux new-session -d -s dbconnector 'java -jar iudx-dbconnector-0.0.1-SNAPSHOT-jar-with-dependencies.jar -d64 -Xms512m -Xmx4g' - diff --git a/setup/elk/elk_install.sh b/setup/elk/elk_install.sh deleted file mode 100755 index b192a3db..00000000 --- a/setup/elk/elk_install.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/ash - -tmux new-session -d -s es 'su ideam -c "/home/ideam/elasticsearch-6.2.4/bin/elasticsearch"' - -tmux new-session -d -s kibana '/home/ideam/kibana-6.2.4-linux-x86_64/bin/kibana' diff --git a/setup/elk/elk_start.sh b/setup/elk/elk_start.sh deleted file mode 100755 index cce4449c..00000000 --- a/setup/elk/elk_start.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/ash - -rm -r /tmp/tmux-* - -if ! nc -z localhost 9200 -then -tmux new-session -d -s elasticsearch 'su ideam -c "/home/ideam/elasticsearch-6.2.4/bin/elasticsearch"' -fi - -if ! nc -z localhost 5601 -then -tmux new-session -d -s kibana '/home/ideam/kibana-6.2.4-linux-x86_64/bin/kibana' -fi diff --git a/setup/pgsql/daemon.py b/setup/pgsql/daemon.py deleted file mode 100644 index 69cf0655..00000000 --- a/setup/pgsql/daemon.py +++ /dev/null @@ -1,64 +0,0 @@ -import os -import psycopg2 -import pika -import time -import sys - -conn = None -cur = None -channel = None - -def run(): - - admin_passwd = os.getenv("ADMIN_PWD") - postgres_passwd = os.getenv("POSTGRES_PWD") - - conn = psycopg2.connect(database="postgres", user = "postgres", password = postgres_passwd, host = "127.0.0.1", port = "5432") - - cur = conn.cursor() - credentials = pika.PlainCredentials('admin', admin_passwd) - parameters = pika.ConnectionParameters('broker',5672, '/', credentials) - - while True: - try: - print("Connecting to broker ...") - connection = pika.BlockingConnection(parameters) - print("Connected") - break - except Exception: - sys.stderr.write("Failed to connect to broker\n") - - channel = connection.channel() - - queue = "" - exchange = "" - topic = "" - - while True: - - print("Looking for expired entries ...") - cur.execute("SELECT from_id, exchange, topic FROM acl WHERE valid_till < NOW()") - rows = cur.fetchall() - - if rows: - for row in rows: - queue = row[0] - exchange = row[1] - topic = row[2] - - try: - channel.queue_unbind(exchange=exchange, queue=queue, routing_key = topic) - channel.queue_unbind(exchange=exchange, queue=queue+".priority", routing_key = topic) - channel.queue_unbind(exchange=queue+".publish", queue=exchange, routing_key = exchange+"."+topic) - except Exception: - sys.stderr.write("Failed to unbind q="+queue+" e="+exchange+" t="+topic) - - cur.execute("DELETE FROM acl WHERE from_id = %s AND exchange = %s AND topic = %s",(queue, exchange, topic,)) - conn.commit() - - print("Deleted acl entry and binding between "+queue+" and "+exchange) - - time.sleep(60) - -if __name__ == '__main__': - run() diff --git a/setup/pgsql/pgsql_install.sh b/setup/pgsql/pgsql_install.sh deleted file mode 100755 index 147acc4d..00000000 --- a/setup/pgsql/pgsql_install.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/ash - -set -e - -salt="$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w ${1:-32} | head -n 1)" - -string=$ADMIN_PWD$salt"admin" -hash=$(echo -n $string | sha256sum | cut -d ' ' -f 1) - -su postgres -c "postgres -D /var/lib/postgresql > /var/lib/postgresql/logfile 2>&1 &" - -until su postgres -c 'pg_isready' >/dev/null 2>&1 -do -sleep 0.1 -done - -echo $POSTGRES_PWD - -psql -U postgres -c "alter user postgres with password '$POSTGRES_PWD'" > /dev/null 2>&1 -psql -U postgres -c "insert into users values('admin','$hash',NULL,'$salt','f', 't')" > /dev/null 2>&1 diff --git a/setup/pgsql/pgsql_reset.sh b/setup/pgsql/pgsql_reset.sh deleted file mode 100755 index 92c76390..00000000 --- a/setup/pgsql/pgsql_reset.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/ash - -psql -U postgres -c "delete from acl; delete from follow; delete from users where id not like 'admin'" diff --git a/setup/pgsql/pgsql_start.sh b/setup/pgsql/pgsql_start.sh deleted file mode 100755 index fd8a5496..00000000 --- a/setup/pgsql/pgsql_start.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/ash - -rm -r /tmp/tmux-* > /dev/null 2>&1 -su postgres -c "postgres -D /var/lib/postgresql > /var/lib/postgresql/logfile 2>&1 &" - -until su postgres -c 'pg_isready' >/dev/null 2>&1 -do -sleep 0.1 -done diff --git a/setup/vertx/vertx_install.sh b/setup/vertx/vertx_install.sh deleted file mode 100755 index 5eeef838..00000000 --- a/setup/vertx/vertx_install.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -cd iudx-api-server - -mvn package - -cp target/iudx-api-server-0.0.1-SNAPSHOT-fat.jar . - -tmux new-session -d -s vertx 'java -jar iudx-api-server-0.0.1-SNAPSHOT-fat.jar -d64 -Xms512m -Xmx4g' diff --git a/setup/vertx/vertx_quick_install.sh b/setup/vertx/vertx_quick_install.sh deleted file mode 100755 index 91e107f3..00000000 --- a/setup/vertx/vertx_quick_install.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -cd iudx-api-server - -if [ -e iudx-api-server-0.0.1-SNAPSHOT-fat.jar ] -then -rm iudx-api-server-0.0.1-SNAPSHOT-fat.jar -fi - -cp target/iudx-api-server-0.0.1-SNAPSHOT-fat.jar . - -tmux new-session -d -s vertx 'java -jar iudx-api-server-0.0.1-SNAPSHOT-fat.jar -d64 -Xms512m -Xmx4g' diff --git a/setup/vertx/vertx_start.sh b/setup/vertx/vertx_start.sh deleted file mode 100755 index eeea9187..00000000 --- a/setup/vertx/vertx_start.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -rm -r /tmp/tmux-* > /dev/null 2>&1 - -fuser -k 8443/tcp - -cd iudx-api-server - -mvn package - -cp target/iudx-api-server-0.0.1-SNAPSHOT-fat.jar . - -tmux new-session -d -s vertx 'java -jar iudx-api-server-0.0.1-SNAPSHOT-fat.jar' diff --git a/single-node/quick_install b/single-node/quick_install index 23209175..654f6417 100755 --- a/single-node/quick_install +++ b/single-node/quick_install @@ -3,6 +3,10 @@ set -e YELLOW='\033[1;33m' NC='\033[0m' +GITHUB_API_TOKEN="80cdc31286b3aabd3b7e82ac010b7e45cde0efd2" +owner="rbccps-iisc" +repo="iudx-resource-server" +name="jars.tar.gz" directory=`dirname $0` cd $directory @@ -23,10 +27,36 @@ echo "SINGLE_NODE=true" >> .env echo "MONGO_INITDB_ROOT_USERNAME=root" >> .env echo "MONGO_INITDB_ROOT_PASSWORD="$mongo_passwd >> .env -#if [ ! -f ../iudx-api-server/target/iudx-api-server-0.0.1-SNAPSHOT-fat.jar ] -#then -##wget from release here -#fi +if [ ! -f ../iudx-api-server/target/iudx-api-server-0.0.1-SNAPSHOT-fat.jar ] +then + GH_API="https://api.github.com" + GH_REPO="$GH_API/repos/$owner/$repo" + GH_TAGS="$GH_REPO/releases/latest" + AUTH="Authorization: token $GITHUB_API_TOKEN" + WGET_ARGS="--content-disposition --auth-no-challenge --no-cookie" + CURL_ARGS="-LJ#" + + # Validate token. + curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or network issue!"; exit 1; } + + # Read asset tags. + response=$(curl -sH "$AUTH" $GH_TAGS) + # Get ID of the asset based on given name. + eval $(echo "$response" | grep -C3 "name.:.\+$name" | grep -w id | tr : = | tr -cd '[[:alnum:]]=') + [ "$id" ] || { echo "Error: Failed to get asset id, response: $response" | awk 'length($0)<100' >&2; exit 1; } + GH_ASSET="$GH_REPO/releases/assets/$id" + + # Download asset file. + echo "Downloading jar files from the latest release..." >&2 + curl $CURL_ARGS -H 'Accept: application/octet-stream' "$GH_ASSET?access_token=$GITHUB_API_TOKEN" > jars.tar.gz + tar -zxf jars.tar.gz + mkdir -p ../iudx-api-server/target/ + mkdir -p ../iudx-authenticator/target/ + mv jars/iudx-api-server-0.0.1-SNAPSHOT-fat.jar ../iudx-api-server/target/ + mv jars/iudx-authenticator-0.0.1-SNAPSHOT-fat.jar ../iudx-authenticator/target/ + rm -rf jars + rm jars.tar.gz +fi docker-compose down -v docker-compose up -d