From 552fa2ef7640c3bd23c14b1efaecb30699de0667 Mon Sep 17 00:00:00 2001 From: Muhammed Irfan K Date: Sat, 25 Sep 2021 11:35:30 +0530 Subject: [PATCH 1/2] Add release flag for Balance Filter Action --- actions/balance-filter/deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/balance-filter/deploy.sh b/actions/balance-filter/deploy.sh index 0b12a0ca..f9b8395b 100755 --- a/actions/balance-filter/deploy.sh +++ b/actions/balance-filter/deploy.sh @@ -39,7 +39,7 @@ mkdir -p ./temp/${ACTION} echo "Creating temporary directory" echo "$PACKAGE_HOME/main.zip" echo "Building Source" -zip -r - Cargo.toml src | docker run -i --rm ${DOCKER_IMAGE} -compile main > "$PACKAGE_HOME/main.zip" +zip -r - Cargo.toml src | docker run -e RELEASE=true -i --rm ${DOCKER_IMAGE} -compile main > "$PACKAGE_HOME/main.zip" cd ./temp/${ACTION} From e52ce2c19bee7423aec8854406b85db8a6ea009c Mon Sep 17 00:00:00 2001 From: Muhammed Irfan K Date: Sun, 26 Sep 2021 14:52:55 +0530 Subject: [PATCH 2/2] Refactor deploy script --- actions/balance-filter/deploy.sh | 50 +++++----------- .../deploy.sh | 50 +++++----------- actions/event-producer/deploy.sh | 28 +++------ actions/event-receiver/deploy.sh | 50 +++++----------- actions/event-registration/deploy.sh | 50 +++++----------- actions/kafka-provider-feed/deploy.sh | 54 +++++------------- actions/kafka-provider-web/deploy.sh | 53 ++++------------- actions/push-notification/deploy.sh | 57 +++++-------------- actions/substrate-event-processor/deploy.sh | 52 ++++------------- deploy.sh | 11 +--- register_event_source.sh | 29 ++-------- scripts/accept_params.sh | 10 ++++ scripts/build_action.sh | 19 +++++++ scripts/build_js_action.sh | 16 ++++++ scripts/build_rust_action.sh | 17 ++++++ scripts/check_dependencies.sh | 31 ++++++++++ 16 files changed, 209 insertions(+), 368 deletions(-) mode change 100644 => 100755 actions/event-producer/deploy.sh create mode 100644 scripts/accept_params.sh create mode 100644 scripts/build_action.sh create mode 100644 scripts/build_js_action.sh create mode 100644 scripts/build_rust_action.sh create mode 100644 scripts/check_dependencies.sh diff --git a/actions/balance-filter/deploy.sh b/actions/balance-filter/deploy.sh index f9b8395b..bfbeff05 100755 --- a/actions/balance-filter/deploy.sh +++ b/actions/balance-filter/deploy.sh @@ -7,46 +7,22 @@ openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} openwhiskNamespace=${openwhiskNamespace:-guest} actionHome=${actionHome:-actions/balance-filter} -WSK_CLI="wsk" -DOCKER_IMAGE="hugobyte/openwhisk-runtime-rust:v0.2" -if ! command -v $WSK_CLI &> /dev/null -then - echo "wsk cli not found in path. Please get the cli from https://github.com/apache/openwhisk-cli/releases" - exit -fi -ACTION="balance-filter" -PACKAGE_HOME="$PWD/${actionHome}/temp/$ACTION" - -while [ $# -gt 0 ]; do - if [[ $1 == *"--"* ]]; then - param="${1/--/}" - declare $param="${2%/}" - fi - - shift -done -set -e - -cd "$PWD/$actionHome" +ACTION="balance-filter" +ACTION_TYPE="rust" +SCRIPTS_DIR="$PWD/scripts" +SRC_DIR="$PWD/${actionHome}" +TEMP_DIR="$PWD/${actionHome}/temp" -if [ -e ./temp/${ACTION} ]; then - echo "Clearing previously packed action file." - rm -rf ./temp/${ACTION} -fi +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" +source "$SCRIPTS_DIR/build_action.sh" -mkdir -p ./temp/${ACTION} -echo "Creating temporary directory" -echo "$PACKAGE_HOME/main.zip" -echo "Building Source" -zip -r - Cargo.toml src | docker run -e RELEASE=true -i --rm ${DOCKER_IMAGE} -compile main > "$PACKAGE_HOME/main.zip" +check wsk -cd ./temp/${ACTION} +build -$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$PACKAGE_HOME/main.zip" --docker "$DOCKER_IMAGE" \ - --auth "$openwhiskApiKey" --param push_notification_trigger "send-push-notification" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --param db_name "balance_filter_db" -a provide-api-key true +$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --docker "$DOCKER_IMAGE" \ +--auth "$openwhiskApiKey" --param push_notification_trigger "send-push-notification" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --param db_name "balance_filter_db" -a provide-api-key true -if [ -e ./temp/${ACTION} ]; then - echo "Clearing temporary packed action file." - rm -rf ./temp/${ACTION} -fi \ No newline at end of file +clear_temp \ No newline at end of file diff --git a/actions/balance-notification-registration/deploy.sh b/actions/balance-notification-registration/deploy.sh index e3670b70..26a48e7b 100755 --- a/actions/balance-notification-registration/deploy.sh +++ b/actions/balance-notification-registration/deploy.sh @@ -7,46 +7,22 @@ openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} openwhiskNamespace=${openwhiskNamespace:-guest} actionHome=${actionHome:-actions/balance-notification-registration} -WSK_CLI="wsk" -DOCKER_IMAGE="hugobyte/openwhisk-runtime-rust:v0.2" -if ! command -v $WSK_CLI &> /dev/null -then - echo "wsk cli not found in path. Please get the cli from https://github.com/apache/openwhisk-cli/releases" - exit -fi -ACTION="balance-notification-registration" -PACKAGE_HOME="$PWD/${actionHome}/temp/$ACTION" - -while [ $# -gt 0 ]; do - if [[ $1 == *"--"* ]]; then - param="${1/--/}" - declare $param="${2%/}" - fi - - shift -done -set -e - -cd "$PWD/$actionHome" +ACTION="balance-notification-registration" +ACTION_TYPE="rust" +SCRIPTS_DIR="$PWD/scripts" +SRC_DIR="$PWD/${actionHome}" +TEMP_DIR="$PWD/${actionHome}/temp" -if [ -e ./temp/${ACTION} ]; then - echo "Clearing previously packed action file." - rm -rf ./temp/${ACTION} -fi +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" +source "$SCRIPTS_DIR/build_action.sh" -mkdir -p ./temp/${ACTION} -echo "Creating temporary directory" -echo "$PACKAGE_HOME/main.zip" -echo "Building Source" -zip -r - Cargo.toml src | docker run -e RELEASE=true -i --rm ${DOCKER_IMAGE} -compile main > "$PACKAGE_HOME/main.zip" +check wsk -cd ./temp/${ACTION} +build -$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$PACKAGE_HOME/main.zip" --docker "$DOCKER_IMAGE" \ - --auth "$openwhiskApiKey" --param event_registration_db "event_registration_db" --param balance_filter_db "balance_filter_db" --param db_name "balance_notification_registration_db" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --web true +$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --docker "$DOCKER_IMAGE" \ +--auth "$openwhiskApiKey" --param event_registration_db "event_registration_db" --param balance_filter_db "balance_filter_db" --param db_name "balance_notification_registration_db" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --web true -if [ -e ./temp/${ACTION} ]; then - echo "Clearing temporary packed action file." - rm -rf ./temp/${ACTION} -fi \ No newline at end of file +clear_temp \ No newline at end of file diff --git a/actions/event-producer/deploy.sh b/actions/event-producer/deploy.sh old mode 100644 new mode 100755 index 4c60d638..fa479e13 --- a/actions/event-producer/deploy.sh +++ b/actions/event-producer/deploy.sh @@ -7,27 +7,13 @@ openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} openwhiskNamespace=${openwhiskNamespace:-guest} actionHome=${actionHome:-actions/event-producer} -WSK_CLI="wsk" -if ! command -v $WSK_CLI &> /dev/null -then - echo "wsk cli not found in path. Please get the cli from https://github.com/apache/openwhisk-cli/releases" - exit -fi -ACTION="event-producer" - -while [ $# -gt 0 ]; do - if [[ $1 == *"--"* ]]; then - param="${1/--/}" - declare $param="${2%/}" - fi - - shift -done -set -e - -cd "$PWD/$actionHome" +ACTION="event-producer" +SCRIPTS_DIR="$PWD/scripts" +SRC_DIR="$PWD/${actionHome}" +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" -$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$PWD/event-producer.py" \ - --auth "$openwhiskApiKey" \ No newline at end of file +$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$SRC_DIR/event-producer.py" \ +--auth "$openwhiskApiKey" \ No newline at end of file diff --git a/actions/event-receiver/deploy.sh b/actions/event-receiver/deploy.sh index 81c30dd8..62f2bb1f 100755 --- a/actions/event-receiver/deploy.sh +++ b/actions/event-receiver/deploy.sh @@ -7,46 +7,22 @@ openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} openwhiskNamespace=${openwhiskNamespace:-guest} actionHome=${actionHome:-actions/event-receiver} -WSK_CLI="wsk" -DOCKER_IMAGE="hugobyte/openwhisk-runtime-rust:v0.2" -if ! command -v $WSK_CLI &> /dev/null -then - echo "wsk cli not found in path. Please get the cli from https://github.com/apache/openwhisk-cli/releases" - exit -fi -ACTION="event-receiver" -PACKAGE_HOME="$PWD/${actionHome}/temp/event-receiver" - -while [ $# -gt 0 ]; do - if [[ $1 == *"--"* ]]; then - param="${1/--/}" - declare $param="${2%/}" - fi - - shift -done -set -e - -cd "$PWD/$actionHome" - -if [ -e ./temp/${ACTION} ]; then - echo "Clearing previously packed action file." - rm -rf ./temp/${ACTION} -fi +ACTION="event-receiver" +ACTION_TYPE="rust" +SCRIPTS_DIR="$PWD/scripts" +SRC_DIR="$PWD/${actionHome}" +TEMP_DIR="$PWD/${actionHome}/temp" -mkdir -p ./temp/${ACTION} -echo "Creating temporary directory" +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" +source "$SCRIPTS_DIR/build_action.sh" -echo "Building Source" -zip -r - Cargo.toml src | docker run -e RELEASE=true -i --rm ${DOCKER_IMAGE} -compile main > "$PACKAGE_HOME/main.zip" +check wsk -cd ./temp/${ACTION} +build -$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$PACKAGE_HOME/main.zip" --docker "$DOCKER_IMAGE" \ - --auth "$openwhiskApiKey" -a provide-api-key true +$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --docker "$DOCKER_IMAGE" \ +--auth "$openwhiskApiKey" -a provide-api-key true -if [ -e ./temp/${ACTION} ]; then - echo "Clearing temporary packed action file." - rm -rf ./temp/${ACTION} -fi \ No newline at end of file +clear_temp \ No newline at end of file diff --git a/actions/event-registration/deploy.sh b/actions/event-registration/deploy.sh index d2f95c23..e351c661 100755 --- a/actions/event-registration/deploy.sh +++ b/actions/event-registration/deploy.sh @@ -7,46 +7,22 @@ openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} openwhiskNamespace=${openwhiskNamespace:-guest} actionHome=${actionHome:-actions/event-registration} -WSK_CLI="wsk" -DOCKER_IMAGE="hugobyte/openwhisk-runtime-rust:v0.2" -if ! command -v $WSK_CLI &> /dev/null -then - echo "wsk cli not found in path. Please get the cli from https://github.com/apache/openwhisk-cli/releases" - exit -fi -ACTION="event-registration" -PACKAGE_HOME="$PWD/${actionHome}/temp/$ACTION" - -while [ $# -gt 0 ]; do - if [[ $1 == *"--"* ]]; then - param="${1/--/}" - declare $param="${2%/}" - fi - - shift -done -set -e - -cd "$PWD/$actionHome" +ACTION="event-registration" +ACTION_TYPE="rust" +SCRIPTS_DIR="$PWD/scripts" +SRC_DIR="$PWD/${actionHome}" +TEMP_DIR="$PWD/${actionHome}/temp" -if [ -e ./temp/${ACTION} ]; then - echo "Clearing previously packed action file." - rm -rf ./temp/${ACTION} -fi +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" +source "$SCRIPTS_DIR/build_action.sh" -mkdir -p ./temp/${ACTION} -echo "Creating temporary directory" -echo "$PACKAGE_HOME/main.zip" -echo "Building Source" -zip -r - Cargo.toml src | docker run -e RELEASE=true -i --rm ${DOCKER_IMAGE} -compile main > "$PACKAGE_HOME/main.zip" +check wsk -cd ./temp/${ACTION} +build -$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$PACKAGE_HOME/main.zip" --docker "$DOCKER_IMAGE" \ - --auth "$openwhiskApiKey" --param db_name "event_registration_db" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --param feed "kafka-provider-feed" --param brokers "[\"172.17.0.1:9092\"]" -a provide-api-key true +$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --docker "$DOCKER_IMAGE" \ +--auth "$openwhiskApiKey" --param db_name "event_registration_db" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --param feed "kafka-provider-feed" --param brokers "[\"172.17.0.1:9092\"]" -a provide-api-key true -if [ -e ./temp/${ACTION} ]; then - echo "Clearing temporary packed action file." - rm -rf ./temp/${ACTION} -fi \ No newline at end of file +clear_temp \ No newline at end of file diff --git a/actions/kafka-provider-feed/deploy.sh b/actions/kafka-provider-feed/deploy.sh index b39b0fb4..a423bbf5 100755 --- a/actions/kafka-provider-feed/deploy.sh +++ b/actions/kafka-provider-feed/deploy.sh @@ -7,50 +7,22 @@ openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} openwhiskNamespace=${openwhiskNamespace:-guest} actionHome=${actionHome:-actions/kafka-provider-feed} -WSK_CLI="wsk" -if ! command -v $WSK_CLI &> /dev/null -then - echo "wsk cli not found in path. Please get the cli from https://github.com/apache/openwhisk-cli/releases" - exit -fi -ACTION="kafka-provider-feed" -PACKAGE_HOME="$PWD/${actionHome}/temp/$ACTION" - -while [ $# -gt 0 ]; do - if [[ $1 == *"--"* ]]; then - param="${1/--/}" - declare $param="${2%/}" - fi - - shift -done - -set -e - -cd "$PWD/$actionHome" -if [ -e ./temp/${ACTION} ]; then - echo "Clearing previously packed action file." - rm -rf ./temp/${ACTION} -fi - -mkdir -p ./temp/${ACTION} -echo "Creating temporary directory" - - -cp -r ./package.json ./lib ./main.js ./temp/${ACTION} -echo "Copying files to temporary directory" +ACTION="kafka-provider-feed" +ACTION_TYPE="js" +SCRIPTS_DIR="$PWD/scripts" +SRC_DIR="$PWD/${actionHome}" +TEMP_DIR="$PWD/${actionHome}/temp" -cd ./temp/${ACTION} +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" +source "$SCRIPTS_DIR/build_action.sh" -yarn install --production=true +check wsk -zip -r main.zip * +build -$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$PACKAGE_HOME/main.zip" --kind nodejs:default \ - --auth "$openwhiskApiKey" -a feed true --param endpoint "http://172.17.0.1:8888" --param web_action "kafka-provider-web" -a provide-api-key true +$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --kind nodejs:default \ +--auth "$openwhiskApiKey" -a feed true --param endpoint "http://172.17.0.1:8888" --param web_action "kafka-provider-web" -a provide-api-key true -if [ -e ./temp/${ACTION} ]; then - echo "Clearing temporary packed action file." - rm -rf ./temp/${ACTION} -fi \ No newline at end of file +clear_temp \ No newline at end of file diff --git a/actions/kafka-provider-web/deploy.sh b/actions/kafka-provider-web/deploy.sh index 32cf94a4..d1cb2317 100755 --- a/actions/kafka-provider-web/deploy.sh +++ b/actions/kafka-provider-web/deploy.sh @@ -7,51 +7,22 @@ openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} openwhiskNamespace=${openwhiskNamespace:-guest} actionHome=${actionHome:-actions/kafka-provider-web} -WSK_CLI="wsk" -if ! command -v $WSK_CLI &> /dev/null -then - echo "wsk cli not found in path. Please get the cli from https://github.com/apache/openwhisk-cli/releases" - exit -fi ACTION="kafka-provider-web" -PACKAGE_HOME="$PWD/${actionHome}/temp/$ACTION" +ACTION_TYPE="js" +SCRIPTS_DIR="$PWD/scripts" +SRC_DIR="$PWD/${actionHome}" +TEMP_DIR="$PWD/${actionHome}/temp" -while [ $# -gt 0 ]; do - if [[ $1 == *"--"* ]]; then - param="${1/--/}" - declare $param="${2%/}" - fi +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" +source "$SCRIPTS_DIR/build_action.sh" - shift -done +check wsk -set -e +build -cd "$PWD/$actionHome" +$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --kind nodejs:default \ +--auth "$openwhiskApiKey" --param endpoint "http://172.17.0.1:8888" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --param db_name "ow_kafka_triggers" -a provide-api-key true --web true -if [ -e ./temp/${ACTION} ]; then - echo "Clearing previously packed action file." - rm -rf ./temp/${ACTION} -fi - -mkdir -p ./temp/${ACTION} -echo "Creating temporary directory" - - -cp -r ./package.json ./lib ./main.js ./temp/${ACTION} -echo "Copying files to temporary directory" - -cd ./temp/${ACTION} - -yarn install --production=true - -zip -r main.zip * - -$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$PACKAGE_HOME/main.zip" --kind nodejs:default \ - --auth "$openwhiskApiKey" --param endpoint "http://172.17.0.1:8888" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --param db_name "ow_kafka_triggers" -a provide-api-key true --web true - -if [ -e ./temp/${ACTION} ]; then - echo "Clearing temporary packed action file." - rm -rf ./temp/${ACTION} -fi \ No newline at end of file +clear_temp \ No newline at end of file diff --git a/actions/push-notification/deploy.sh b/actions/push-notification/deploy.sh index 2a8ef439..36e6963e 100755 --- a/actions/push-notification/deploy.sh +++ b/actions/push-notification/deploy.sh @@ -7,57 +7,26 @@ openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} openwhiskNamespace=${openwhiskNamespace:-guest} actionHome=${actionHome:-actions/push-notification} -WSK_CLI="wsk" -DOCKER_IMAGE="hugobyte/openwhisk-runtime-rust:v0.2" -if ! command -v $WSK_CLI &> /dev/null -then - echo "wsk cli not found in path. Please get the cli from https://github.com/apache/openwhisk-cli/releases" - exit -fi - -if [ -z "$FIREBASE_API_KEY" ] -then - echo "FIREBASE_API_KEY env is not defined, Generate server token from https://console.firebase.google.com/project//settings/cloudmessaging and add as env FIREBASE_API_KEY" - exit -fi ACTION="push-notification" -PACKAGE_HOME="$PWD/${actionHome}/temp/$ACTION" +ACTION_TYPE="rust" +SCRIPTS_DIR="$PWD/scripts" +SRC_DIR="$PWD/${actionHome}" +TEMP_DIR="$PWD/${actionHome}/temp" -while [ $# -gt 0 ]; do - if [[ $1 == *"--"* ]]; then - param="${1/--/}" - declare $param="${2%/}" - fi +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" +source "$SCRIPTS_DIR/build_action.sh" - shift -done +check wsk +check firebase_api_key -set -e +build -cd "$PWD/$actionHome" - -if [ -e ./temp/${ACTION} ]; then - echo "Clearing previously packed action file." - rm -rf ./temp/${ACTION} -fi - -mkdir -p ./temp/${ACTION} -echo "Creating temporary directory" -echo "$PACKAGE_HOME/main.zip" -echo "Building Source" -zip -r - Cargo.toml src | docker run -e RELEASE=true -i --rm ${DOCKER_IMAGE} -compile main > "$PACKAGE_HOME/main.zip" - -cd ./temp/${ACTION} - -$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$PACKAGE_HOME/main.zip" --docker "$DOCKER_IMAGE" \ - --auth "$openwhiskApiKey" --param api_key "$FIREBASE_API_KEY" +$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --docker "$DOCKER_IMAGE" \ +--auth "$openwhiskApiKey" --param api_key "$FIREBASE_API_KEY" $WSK_CLI -i --apihost "$openwhiskApiHost" trigger update "send-${ACTION}" --auth "$openwhiskApiKey" - $WSK_CLI -i --apihost "$openwhiskApiHost" rule update "${ACTION}-rule" "send-${ACTION}" ${ACTION} --auth "$openwhiskApiKey" -if [ -e ./temp/${ACTION} ]; then - echo "Clearing temporary packed action file." - rm -rf ./temp/${ACTION} -fi \ No newline at end of file +clear_temp \ No newline at end of file diff --git a/actions/substrate-event-processor/deploy.sh b/actions/substrate-event-processor/deploy.sh index badfd6de..691eb9bf 100755 --- a/actions/substrate-event-processor/deploy.sh +++ b/actions/substrate-event-processor/deploy.sh @@ -7,53 +7,25 @@ openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} openwhiskNamespace=${openwhiskNamespace:-guest} actionHome=${actionHome:-actions/substrate-event-processor} -WSK_CLI="wsk" -DOCKER_IMAGE="hugobyte/openwhisk-runtime-rust:v0.2" -if ! command -v $WSK_CLI &> /dev/null -then - echo "wsk cli not found in path. Please get the cli from https://github.com/apache/openwhisk-cli/releases" - exit -fi - ACTION="substrate-event-processor" -PACKAGE_HOME="$PWD/${actionHome}/temp/$ACTION" - -while [ $# -gt 0 ]; do - if [[ $1 == *"--"* ]]; then - param="${1/--/}" - declare $param="${2%/}" - fi - - shift -done - -set -e +ACTION_TYPE="rust" +SCRIPTS_DIR="$PWD/scripts" +SRC_DIR="$PWD/${actionHome}" +TEMP_DIR="$PWD/${actionHome}/temp" -cd "$PWD/$actionHome" +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" +source "$SCRIPTS_DIR/build_action.sh" -if [ -e ./temp/${ACTION} ]; then - echo "Clearing previously packed action file." - rm -rf ./temp/${ACTION} -fi +check wsk -mkdir -p ./temp/${ACTION} -echo "Creating temporary directory" -echo "$PACKAGE_HOME/main.zip" -echo "Building Source" -zip -r - Cargo.toml src | docker run -e RELEASE=true -i --rm ${DOCKER_IMAGE} -compile main > "$PACKAGE_HOME/main.zip" - -cd ./temp/${ACTION} - -$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$PACKAGE_HOME/main.zip" --docker "$DOCKER_IMAGE" \ - --auth "$openwhiskApiKey" --param event_producer_trigger "produce-event" -a provide-api-key true +build +$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --docker "$DOCKER_IMAGE" \ +--auth "$openwhiskApiKey" --param event_producer_trigger "produce-event" -a provide-api-key true $WSK_CLI -i --apihost "$openwhiskApiHost" trigger update "produce-event" --auth "$openwhiskApiKey" - $WSK_CLI -i --apihost "$openwhiskApiHost" rule update "produce-event-rule" "produce-event" "event-producer" --auth "$openwhiskApiKey" -if [ -e ./temp/${ACTION} ]; then - echo "Clearing temporary packed action file." - rm -rf ./temp/${ACTION} -fi \ No newline at end of file +clear_temp \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index b4f1099b..9212c450 100755 --- a/deploy.sh +++ b/deploy.sh @@ -9,16 +9,7 @@ openwhiskNamespace=${openwhiskNamespace:-guest} actions=("actions/push-notification" "actions/balance-filter" "actions/event-receiver" "actions/event-registration" "actions/balance-notification-registration" "actions/event-producer" "actions/kafka-provider-feed" "actions/kafka-provider-web" "actions/substrate-event-processor") -while [ $# -gt 0 ]; do - if [[ $1 == *"--"* ]]; then - param="${1/--/}" - declare $param="${2%/}" - fi - - shift -done - -set -e +source ./scripts/accept_params.sh for index in ${!actions[@]}; do diff --git a/register_event_source.sh b/register_event_source.sh index b8c6a7e8..fe2add82 100755 --- a/register_event_source.sh +++ b/register_event_source.sh @@ -9,33 +9,16 @@ openwhiskNamespace=${openwhiskNamespace:-guest} eventRegistrationAction=${eventRegistrationAction:-event-registration} name=${name:-polkadot-balance} balanceFilterAction=${balanceFilterAction:-balance-filter} -WSK_CLI="wsk" -JSON_PARSER="jq" +SCRIPTS_DIR="$PWD/scripts" -if ! command -v $WSK_CLI &> /dev/null -then - echo "wsk cli not found in path. Please get the cli from https://github.com/apache/openwhisk-cli/releases" - exit -fi - -if ! command -v $JSON_PARSER &> /dev/null -then - echo "jq found in path. jq is needed to parse the json response kindly install it" - exit -fi - -while [ $# -gt 0 ]; do - if [[ $1 == *"--"* ]]; then - param="${1/--/}" - declare $param="${2%/}" - fi - - shift -done +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" +check wsk +check jq TRIGGER=$($WSK_CLI -i --apihost "$openwhiskApiHost" action invoke "/${openwhiskNamespace}/${eventRegistrationAction}" \ - --auth "$openwhiskApiKey" --param name "$name" --blocking --result | $JSON_PARSER -r '.trigger') +--auth "$openwhiskApiKey" --param name "$name" --blocking --result | $JSON_PARSER -r '.trigger') $WSK_CLI -i --apihost "$openwhiskApiHost" rule update "$TRIGGER-balance-filter" $TRIGGER $balanceFilterAction --auth "$openwhiskApiKey" diff --git a/scripts/accept_params.sh b/scripts/accept_params.sh new file mode 100644 index 00000000..3942e547 --- /dev/null +++ b/scripts/accept_params.sh @@ -0,0 +1,10 @@ +while [ $# -gt 0 ]; do + if [[ $1 == *"--"* ]]; then + param="${1/--/}" + declare $param="${2%/}" + fi + + shift +done + +set -e \ No newline at end of file diff --git a/scripts/build_action.sh b/scripts/build_action.sh new file mode 100644 index 00000000..92da7deb --- /dev/null +++ b/scripts/build_action.sh @@ -0,0 +1,19 @@ +function build { + if [ $ACTION_TYPE = "rust" ] + then + source "$SCRIPTS_DIR/build_rust_action.sh" + elif [ $ACTION_TYPE = "js" ] + then + source "$SCRIPTS_DIR/build_js_action.sh" + else + echo "Action type not supported" + exit + fi +} + +function clear_temp { + if [ -e $TEMP_DIR ]; then + echo "Clearing temporary packed action file." + rm -rf $TEMP_DIR + fi +} \ No newline at end of file diff --git a/scripts/build_js_action.sh b/scripts/build_js_action.sh new file mode 100644 index 00000000..de5e472e --- /dev/null +++ b/scripts/build_js_action.sh @@ -0,0 +1,16 @@ +if [ -e $TEMP_DIR ]; then + echo "Clearing previously packed action files." + rm -rf $TEMP_DIR +fi + +mkdir -p $TEMP_DIR +echo "Creating temporary directory" + +echo "Copying files to temporary directory" +cp -r "$SRC_DIR/package.json" "$SRC_DIR/lib" "$SRC_DIR/main.js" $TEMP_DIR + +cd $TEMP_DIR + +yarn install --production=true + +zip -r "$TEMP_DIR/main.zip" * \ No newline at end of file diff --git a/scripts/build_rust_action.sh b/scripts/build_rust_action.sh new file mode 100644 index 00000000..798134c7 --- /dev/null +++ b/scripts/build_rust_action.sh @@ -0,0 +1,17 @@ +DOCKER_IMAGE="hugobyte/openwhisk-runtime-rust:v0.2" + +if [ -e $TEMP_DIR ]; then + echo "Clearing previously packed action files." + rm -rf $TEMP_DIR +fi + +mkdir -p $TEMP_DIR +echo "Creating temporary directory" + +echo "Building Source to $TEMP_DIR/main.zip" + +cd $SRC_DIR + +zip -r - Cargo.toml src | docker run -e RELEASE=true -i --rm $DOCKER_IMAGE -compile main > "$TEMP_DIR/main.zip" + +cd $TEMP_DIR diff --git a/scripts/check_dependencies.sh b/scripts/check_dependencies.sh new file mode 100644 index 00000000..89164538 --- /dev/null +++ b/scripts/check_dependencies.sh @@ -0,0 +1,31 @@ +WSK_CLI="wsk" +JSON_PARSER="jq" + +function check { + DEPENDENCY="$1" + if [ $DEPENDENCY = "wsk" ] + then + if ! command -v $WSK_CLI &> /dev/null + then + echo "wsk cli not found in path. Please get the cli from https://github.com/apache/openwhisk-cli/releases" + exit + fi + elif [ $DEPENDENCY = "firebase_api_key" ] + then + if [ -z "$FIREBASE_API_KEY" ] + then + echo "FIREBASE_API_KEY env is not defined, Generate server token from https://console.firebase.google.com/project//settings/cloudmessaging and add as env FIREBASE_API_KEY" + exit + fi + elif [ $DEPENDENCY = "jq"] + then + if ! command -v $JSON_PARSER &> /dev/null + then + echo "jq found in path. jq is needed to parse the json response kindly install it" + exit + fi + else + echo "dependency $DEPENDENCY not supported" + exit + fi +} \ No newline at end of file