From fe3628f70b863bea4673ae3799c4316f1f4c3b03 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Wed, 3 May 2023 21:20:58 +0000 Subject: [PATCH 01/20] wip local hub-spoke docker Signed-off-by: Reinis Martinsons --- packages/serverless-orchestration/README.md | 2 + .../local-docker/README.md | 47 +++++++++++++++++++ .../local-docker/hub.env.template | 31 ++++++++++++ .../local-docker/scripts/json-to-env.sh | 9 ++++ .../local-docker/scripts/update-bot-config.sh | 23 +++++++++ .../local-docker/spoke.env.template | 22 +++++++++ .../local-docker/uma.yml | 12 +++++ 7 files changed, 146 insertions(+) create mode 100644 packages/serverless-orchestration/local-docker/README.md create mode 100644 packages/serverless-orchestration/local-docker/hub.env.template create mode 100644 packages/serverless-orchestration/local-docker/scripts/json-to-env.sh create mode 100644 packages/serverless-orchestration/local-docker/scripts/update-bot-config.sh create mode 100644 packages/serverless-orchestration/local-docker/spoke.env.template create mode 100644 packages/serverless-orchestration/local-docker/uma.yml diff --git a/packages/serverless-orchestration/README.md b/packages/serverless-orchestration/README.md index 0295cc886d..8653719988 100644 --- a/packages/serverless-orchestration/README.md +++ b/packages/serverless-orchestration/README.md @@ -9,3 +9,5 @@ The two serverless orchestration scripts are: 1. The `ServerlessHub` script which reads in a global configuration file stored and executes parallel serverless instances for each configured bot. This enables one global config file to define all bot instances. This drastically simplifying the devops and management overhead for spinning up new instances as this can be done by simply updating a single config file. 1. The `ServerlessSpoke` script which enables serverless functions to execute any arbitrary command from the UMA Docker container. This can be run on a local machine, within GCP cloud run or GCP cloud function environments. + +Please see the [instructions](./local-docker/README.md) on how to run serverless orchestration scripts when testing locally. diff --git a/packages/serverless-orchestration/local-docker/README.md b/packages/serverless-orchestration/local-docker/README.md new file mode 100644 index 0000000000..075225b6bc --- /dev/null +++ b/packages/serverless-orchestration/local-docker/README.md @@ -0,0 +1,47 @@ +# Running UMA Serverless Orchestration Locally With Docker + +This document describes how to run the UMA Serverless Orchestration scripts locally using Docker. This is useful for +testing and debugging bots locally before deploying them to the cloud. + +The instructions below assume you have [Docker](https://www.docker.com/) installed and its server daemon is running on +the local machine. Also make sure to add your user to `docker` group in order to avoid running commands as root. + +Start by enabling swarm mode so that hub and spoke services can be configured in a single [compose file](./uma.yml): + +```sh +docker swarm init +``` + +## Build UMA Protocol Docker Image + +This step is only required if you are testing against a local development branch of the UMA protocol. If you are +testing bot configuration against the published protocol docker image, you can skip this step. + +Start the `registry` service: + +```sh +docker service create --name registry --publish published=5000,target=5000 registry:2 +``` + +Start the docker build from the root of `protocol` repository: + +```sh +docker build -t localhost:5000/protocol:dev . +``` + +Once build is complete, push it to the local registry service: + +```sh +docker push localhost:5000/protocol:dev +``` + +## Service configuration + +In the same directory where `uma.yml` compose file is located create the required `hub.env` and `spoke.env` files using +the provided templates in [hub.env.template](./hub.env.template) and [spoke.env.template](./spoke.env.template) +respectively. + +Place all the tested bot configuration files under the [./bot-configs/serverless-bots](./bot-configs/serverless-bots) +directory. Configuration files must be formatted as JSON and have a `.json` extension. + +## Start UMA Serverless Orchestration diff --git a/packages/serverless-orchestration/local-docker/hub.env.template b/packages/serverless-orchestration/local-docker/hub.env.template new file mode 100644 index 0000000000..11fb973691 --- /dev/null +++ b/packages/serverless-orchestration/local-docker/hub.env.template @@ -0,0 +1,31 @@ +# Note on formatting: Do not enclose variable values in quotes. + +# Entry point for the hub service. +COMMAND=node packages/serverless-orchestration/src/ServerlessHub.js + +# Default spoke URL. Docker stack automatically adds all services to the same network, thus we can use the service name +# as the hostname. +SPOKE_URL=http://spoke:8080 + +# Spoke URLs for different spoke services. This is only required if the tested bot configuration includes spokeUrlName +# property. Since the included uma.yml compose file runs only one spoke service we point all named spoke URLs to the +# same spoke service. +SPOKE_URLS={"large":"http://spoke:8080","small":"http://spoke:8080"} + +# Provide fallback RPC node URL. +CUSTOM_NODE_URL= + +# Hub service name as it appears in logs. +BOT_IDENTIFIER=serverless-hub-mainnet + +# Hub configuration. Provide default timeout for how long to wait for spoke calls to respond. +HUB_CONFIG={"rejectSpokeDelay":900} + +# Stringified JSON configuration in the form of {"defaultWebHookUrl":""} where should be +# replaced with the URL of Slack webhook for the channel to which the hub should send notifications. +SLACK_CONFIG= + +# Stringified JSON configuration in the form of {"integrationKey":""} where +# should be replaced with the integration key of PagerDuty service to which the hub should +# send notifications. +PAGER_DUTY_V2_CONFIG= \ No newline at end of file diff --git a/packages/serverless-orchestration/local-docker/scripts/json-to-env.sh b/packages/serverless-orchestration/local-docker/scripts/json-to-env.sh new file mode 100644 index 0000000000..809b415206 --- /dev/null +++ b/packages/serverless-orchestration/local-docker/scripts/json-to-env.sh @@ -0,0 +1,9 @@ +# Script to stringify json file $1 and append to env file $2. +# This is used by update-bot-config.sh script. +# Requires jq being installed. + +echo "Processing $1 ..." +BUCKET=$(basename $(dirname "$1")) +FILE=$(basename "$1") +CONFIG=$(cat "$1" | jq tostring | sed -e 's/\\//g' -e 's/^\"//' -e 's/\"$//') +echo $BUCKET-$FILE="$CONFIG" >> "$2" diff --git a/packages/serverless-orchestration/local-docker/scripts/update-bot-config.sh b/packages/serverless-orchestration/local-docker/scripts/update-bot-config.sh new file mode 100644 index 0000000000..e5c0a855ab --- /dev/null +++ b/packages/serverless-orchestration/local-docker/scripts/update-bot-config.sh @@ -0,0 +1,23 @@ +# Script to convert JSON bot-configs to environment variables passed to the hub service. + +# Resolve provided uma directory. Defaults to current directory if not provided. +if [ "$1" == "" ]; then + UMA_DIR=$(pwd) +else + [ ! -d "$1" ] && { echo "Error: $1 is not a directory"; exit 1; } + UMA_DIR=$(realpath "$1") +fi + +# Verify required files and directories exist. +[ ! -d "$UMA_DIR/bot-configs" ] && { echo "Error: bot-configs directory not found"; exit 1; } +[ ! -f "$UMA_DIR/scripts/json-to-env.sh" ] && { echo "Error: scripts/json-to-env.sh file not found"; exit 1; } + +# Convert JSON files under bot-configs to bot-config.env file. +CONVERT_SCRIPT="$UMA_DIR/scripts/json-to-env.sh" +CONFIG_DIR="$UMA_DIR/bot-configs" +ENV_FILE="$UMA_DIR/bot-config.env" +echo "Processing JSON files in $CONFIG_DIR and storing environment in $ENV_FILE ..." +rm -f "$ENV_FILE" +find "$CONFIG_DIR" -name "*.json" -exec sh "$CONVERT_SCRIPT" {} "$ENV_FILE" \; + +exit 0 diff --git a/packages/serverless-orchestration/local-docker/spoke.env.template b/packages/serverless-orchestration/local-docker/spoke.env.template new file mode 100644 index 0000000000..73efb5714e --- /dev/null +++ b/packages/serverless-orchestration/local-docker/spoke.env.template @@ -0,0 +1,22 @@ +# Note on formatting: Do not enclose variable values in quotes. + +# Entry point for the spoke service. +COMMAND=node packages/serverless-orchestration/src/ServerlessSpoke.js + +# Spoke service name as it appears in logs. +BOT_IDENTIFIER=serverless-spoke + +# Make sure spoke calls are not executed in a loop if this parameter is missing in bot configuration. +POLLING_DELAY=0 + +# Time in seconds to wait for logger to flush. +WAIT_FOR_LOGGER_DELAY=30 + +# Stringified JSON configuration in the form of {"defaultWebHookUrl":""} where should be +# replaced with the URL of Slack webhook for the channel to which the spoke should send notifications. +SLACK_CONFIG= + +# Stringified JSON configuration in the form of {"integrationKey":""} where +# should be replaced with the integration key of PagerDuty service to which the spoke should +# send notifications. +PAGER_DUTY_V2_CONFIG= \ No newline at end of file diff --git a/packages/serverless-orchestration/local-docker/uma.yml b/packages/serverless-orchestration/local-docker/uma.yml new file mode 100644 index 0000000000..d37ef6f081 --- /dev/null +++ b/packages/serverless-orchestration/local-docker/uma.yml @@ -0,0 +1,12 @@ +version: "3.9" +services: + hub: + image: localhost:5000/protocol:dev + env_file: + - hub.env + - bot-config.env + ports: + - "8080:8080" + spoke: + image: localhost:5000/protocol:dev + env_file: spoke.env From 1f95805ecedba9b4ab6c21e41d768706fb0ef2e6 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Wed, 10 May 2023 22:14:02 +0000 Subject: [PATCH 02/20] wip Signed-off-by: Reinis Martinsons --- .dockerignore | 3 ++- packages/serverless-orchestration/.gitignore | 1 + .../local-docker/compose.yml | 22 +++++++++++++++ .../local-docker/scheduler/Dockerfile | 19 +++++++++++++ .../local-docker/scripts/docker-build.sh | 18 +++++++++++++ .../local-docker/scripts/docker-down.sh | 18 +++++++++++++ .../local-docker/scripts/docker-up.sh | 27 +++++++++++++++++++ .../local-docker/scripts/run-bots.sh | 23 ++++++++++++++++ .../local-docker/scripts/update-bot-config.sh | 18 ++++++------- .../local-docker/uma.yml | 12 --------- .../serverless-orchestration/package.json | 6 ++++- 11 files changed, 144 insertions(+), 23 deletions(-) create mode 100644 packages/serverless-orchestration/.gitignore create mode 100644 packages/serverless-orchestration/local-docker/compose.yml create mode 100644 packages/serverless-orchestration/local-docker/scheduler/Dockerfile create mode 100644 packages/serverless-orchestration/local-docker/scripts/docker-build.sh create mode 100644 packages/serverless-orchestration/local-docker/scripts/docker-down.sh create mode 100644 packages/serverless-orchestration/local-docker/scripts/docker-up.sh create mode 100644 packages/serverless-orchestration/local-docker/scripts/run-bots.sh delete mode 100644 packages/serverless-orchestration/local-docker/uma.yml diff --git a/.dockerignore b/.dockerignore index 2bff7dfe77..fdac50c707 100644 --- a/.dockerignore +++ b/.dockerignore @@ -22,4 +22,5 @@ antora.yml app.yaml .gae_deploy *-env.txt -.env +**/*.env +packages/serverless-orchestration/local-docker/bot-configs \ No newline at end of file diff --git a/packages/serverless-orchestration/.gitignore b/packages/serverless-orchestration/.gitignore new file mode 100644 index 0000000000..e95b7b5645 --- /dev/null +++ b/packages/serverless-orchestration/.gitignore @@ -0,0 +1 @@ +local-docker/bot-configs diff --git a/packages/serverless-orchestration/local-docker/compose.yml b/packages/serverless-orchestration/local-docker/compose.yml new file mode 100644 index 0000000000..92a218e907 --- /dev/null +++ b/packages/serverless-orchestration/local-docker/compose.yml @@ -0,0 +1,22 @@ +version: "3.9" +services: + hub: + image: umaprotocol/protocol:local + build: ../../.. + env_file: + - hub.env + - bot-config.env + ports: + - "8081:8080" + spoke: + image: umaprotocol/protocol:local + build: ../../.. + env_file: spoke.env + scheduler: + image: scheduler:local + build: scheduler + configs: + - crontab +configs: + crontab: + file: scheduler/crontab diff --git a/packages/serverless-orchestration/local-docker/scheduler/Dockerfile b/packages/serverless-orchestration/local-docker/scheduler/Dockerfile new file mode 100644 index 0000000000..03bc9f2459 --- /dev/null +++ b/packages/serverless-orchestration/local-docker/scheduler/Dockerfile @@ -0,0 +1,19 @@ +# Pulling Alpine image +FROM alpine:latest + +# Setting up work directory +WORKDIR /scheduler + +# Updating the packages +RUN apk update && \ +apk upgrade --available && sync + +# Installing curl +RUN apk add curl + +# Copying bot runner script into container +#COPY scripts/run-bots.sh . + +# Creating entry point for crond with crontab config +#ENTRYPOINT ["crond", "-f", "-c", "/scheduler/", "-l", "0", "-L", "/dev/stdout"] +ENTRYPOINT ["crond", "-f"] diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-build.sh b/packages/serverless-orchestration/local-docker/scripts/docker-build.sh new file mode 100644 index 0000000000..7b8c868f1e --- /dev/null +++ b/packages/serverless-orchestration/local-docker/scripts/docker-build.sh @@ -0,0 +1,18 @@ +# Script to build local docker image. + +# Resolve provided root directory. Defaults to current directory if not provided. +if [ -z "$1" ]; then + ROOT_DIR=$(pwd) +else + [ ! -d "$1" ] && { echo "Error: $1 is not a directory"; exit 1; } + ROOT_DIR=$(realpath "$1") +fi + +# Verify required compose file exists. +[ ! -f "$ROOT_DIR/compose.yml" ] && { echo "Error: compose.yml file not found"; exit 1; } + +# Build docker image. +echo "Building local docker image ..." +docker compose -f "$ROOT_DIR/compose.yml" -p local-serverless build + +exit 0 diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-down.sh b/packages/serverless-orchestration/local-docker/scripts/docker-down.sh new file mode 100644 index 0000000000..c32ffab087 --- /dev/null +++ b/packages/serverless-orchestration/local-docker/scripts/docker-down.sh @@ -0,0 +1,18 @@ +# Script to stop hub and spoke docker services. + +# Resolve provided root directory. Defaults to current directory if not provided. +if [ -z "$1" ]; then + ROOT_DIR=$(pwd) +else + [ ! -d "$1" ] && { echo "Error: $1 is not a directory"; exit 1; } + ROOT_DIR=$(realpath "$1") +fi + +# Verify required compose file exists. +[ ! -f "$ROOT_DIR/compose.yml" ] && { echo "Error: compose.yml file not found"; exit 1; } + +# Stop hub and spoke services. +echo "Stopping hub and spoke services ..." +docker compose -f "$ROOT_DIR/compose.yml" -p local-serverless down + +exit 0 diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-up.sh b/packages/serverless-orchestration/local-docker/scripts/docker-up.sh new file mode 100644 index 0000000000..06acb8f218 --- /dev/null +++ b/packages/serverless-orchestration/local-docker/scripts/docker-up.sh @@ -0,0 +1,27 @@ +# Script to parse bot-configs and start or update hub and spoke docker services. + +# Resolve provided root directory. Defaults to current directory if not provided. +if [ -z "$1" ]; then + ROOT_DIR=$(pwd) +else + [ ! -d "$1" ] && { echo "Error: $1 is not a directory"; exit 1; } + ROOT_DIR=$(realpath "$1") +fi + +# Verify required files exist. +[ ! -f "$ROOT_DIR/compose.yml" ] && { echo "Error: compose.yml file not found"; exit 1; } +[ ! -f "$ROOT_DIR/hub.env" ] && { echo "Error: hub.env file not found"; exit 1; } +[ ! -f "$ROOT_DIR/spoke.env" ] && { echo "Error: spoke.env file not found"; exit 1; } +[ ! -f "$ROOT_DIR/scripts/update-bot-config.sh" ] && { echo "Error: scripts/update-bot-config.sh file not found"; exit 1; } + +# Convert JSON files under bot-configs to bot-config.env file. +sh "$ROOT_DIR/scripts/update-bot-config.sh" "$ROOT_DIR" + +# Make sure the conversion script did not error. +[ $? != 0 ] && exit 1 + +# Start or update hub and spoke services. +echo "Starting or updating hub and spoke services ..." +docker compose -f "$ROOT_DIR/compose.yml" -p local-serverless up -d + +exit 0 diff --git a/packages/serverless-orchestration/local-docker/scripts/run-bots.sh b/packages/serverless-orchestration/local-docker/scripts/run-bots.sh new file mode 100644 index 0000000000..51084623c4 --- /dev/null +++ b/packages/serverless-orchestration/local-docker/scripts/run-bots.sh @@ -0,0 +1,23 @@ +# Script to trigger bot execution from bucket $1 config file $2 against hub docker service. + +DOCKER_HOST="docker" # Replace with hostname of docker host where hub service is run. +DOCKER_PORT="8080" # Replace with port that is exposed to host by hub docker service. + +generate_post_data() +{ + cat < Date: Thu, 11 May 2023 10:40:26 +0000 Subject: [PATCH 03/20] wip Signed-off-by: Reinis Martinsons --- .dockerignore | 2 +- packages/serverless-orchestration/.gitignore | 2 +- .../local-docker/compose.yml | 8 +++----- .../local-docker/scheduler/Dockerfile | 17 +++++++++++------ .../local-docker/scheduler/entrypoint.sh | 10 ++++++++++ .../{scripts => scheduler}/run-bots.sh | 10 +++++----- .../local-docker/scripts/docker-up.sh | 4 ++-- .../{update-bot-config.sh => update-config.sh} | 9 +++++++++ packages/serverless-orchestration/package.json | 2 +- 9 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 packages/serverless-orchestration/local-docker/scheduler/entrypoint.sh rename packages/serverless-orchestration/local-docker/{scripts => scheduler}/run-bots.sh (52%) rename packages/serverless-orchestration/local-docker/scripts/{update-bot-config.sh => update-config.sh} (69%) diff --git a/.dockerignore b/.dockerignore index fdac50c707..85625cd2b4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -23,4 +23,4 @@ app.yaml .gae_deploy *-env.txt **/*.env -packages/serverless-orchestration/local-docker/bot-configs \ No newline at end of file +packages/serverless-orchestration/local-docker/bot-configs diff --git a/packages/serverless-orchestration/.gitignore b/packages/serverless-orchestration/.gitignore index e95b7b5645..23b7a67778 100644 --- a/packages/serverless-orchestration/.gitignore +++ b/packages/serverless-orchestration/.gitignore @@ -1 +1 @@ -local-docker/bot-configs +local-docker/bot-configs/*/ diff --git a/packages/serverless-orchestration/local-docker/compose.yml b/packages/serverless-orchestration/local-docker/compose.yml index 92a218e907..206c3475a9 100644 --- a/packages/serverless-orchestration/local-docker/compose.yml +++ b/packages/serverless-orchestration/local-docker/compose.yml @@ -15,8 +15,6 @@ services: scheduler: image: scheduler:local build: scheduler - configs: - - crontab -configs: - crontab: - file: scheduler/crontab + env_file: scheduler.env + environment: + - HUB_URL=http://hub:8080 diff --git a/packages/serverless-orchestration/local-docker/scheduler/Dockerfile b/packages/serverless-orchestration/local-docker/scheduler/Dockerfile index 03bc9f2459..af15e203d1 100644 --- a/packages/serverless-orchestration/local-docker/scheduler/Dockerfile +++ b/packages/serverless-orchestration/local-docker/scheduler/Dockerfile @@ -8,12 +8,17 @@ WORKDIR /scheduler RUN apk update && \ apk upgrade --available && sync -# Installing curl +# Installing curl and jq RUN apk add curl +RUN apk add jq -# Copying bot runner script into container -#COPY scripts/run-bots.sh . +# Copying bot runner and entrypoint script into container +COPY run-bots.sh . +COPY entrypoint.sh . -# Creating entry point for crond with crontab config -#ENTRYPOINT ["crond", "-f", "-c", "/scheduler/", "-l", "0", "-L", "/dev/stdout"] -ENTRYPOINT ["crond", "-f"] +# Setting up permissions for the scripts +RUN chmod +x run-bots.sh +RUN chmod +x entrypoint.sh + +# Creating entry point to the script that parses environment and starts crond +ENTRYPOINT ["/scheduler/entrypoint.sh"] \ No newline at end of file diff --git a/packages/serverless-orchestration/local-docker/scheduler/entrypoint.sh b/packages/serverless-orchestration/local-docker/scheduler/entrypoint.sh new file mode 100644 index 0000000000..98cb76e5f0 --- /dev/null +++ b/packages/serverless-orchestration/local-docker/scheduler/entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# Parse the BOT_SCHEDULE environment variable and construct the crontab +echo "$BOT_SCHEDULE" | jq -r '.[] | [.schedule, .bucket, .configFile] | @tsv' | + while IFS=$'\t' read -r schedule bucket configFile + do echo "$schedule /scheduler/run-bots.sh $bucket $configFile $HUB_URL" >> /tmp/crontab + done + +crontab /tmp/crontab +crond -f diff --git a/packages/serverless-orchestration/local-docker/scripts/run-bots.sh b/packages/serverless-orchestration/local-docker/scheduler/run-bots.sh similarity index 52% rename from packages/serverless-orchestration/local-docker/scripts/run-bots.sh rename to packages/serverless-orchestration/local-docker/scheduler/run-bots.sh index 51084623c4..fa5451faf3 100644 --- a/packages/serverless-orchestration/local-docker/scripts/run-bots.sh +++ b/packages/serverless-orchestration/local-docker/scheduler/run-bots.sh @@ -1,7 +1,6 @@ -# Script to trigger bot execution from bucket $1 config file $2 against hub docker service. +#!/bin/sh -DOCKER_HOST="docker" # Replace with hostname of docker host where hub service is run. -DOCKER_PORT="8080" # Replace with port that is exposed to host by hub docker service. +# Script to trigger bot execution from bucket $1 config file $2 against hub service URL $3 generate_post_data() { @@ -15,9 +14,10 @@ EOF BUCKET="$1" FILE="$2" +HUB_URL="$3" DATA=$(generate_post_data) -curl -s -X POST \ +curl -s -S -X POST \ -H "Content-Type: application/json" \ -d "$(generate_post_data)" \ - "http://$DOCKER_HOST:$DOCKER_PORT" + "$HUB_URL" diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-up.sh b/packages/serverless-orchestration/local-docker/scripts/docker-up.sh index 06acb8f218..8b9122eb4b 100644 --- a/packages/serverless-orchestration/local-docker/scripts/docker-up.sh +++ b/packages/serverless-orchestration/local-docker/scripts/docker-up.sh @@ -14,8 +14,8 @@ fi [ ! -f "$ROOT_DIR/spoke.env" ] && { echo "Error: spoke.env file not found"; exit 1; } [ ! -f "$ROOT_DIR/scripts/update-bot-config.sh" ] && { echo "Error: scripts/update-bot-config.sh file not found"; exit 1; } -# Convert JSON files under bot-configs to bot-config.env file. -sh "$ROOT_DIR/scripts/update-bot-config.sh" "$ROOT_DIR" +# Convert JSON files under bot-configs to bot-config.env file and update scheduler.env. +sh "$ROOT_DIR/scripts/update-config.sh" "$ROOT_DIR" # Make sure the conversion script did not error. [ $? != 0 ] && exit 1 diff --git a/packages/serverless-orchestration/local-docker/scripts/update-bot-config.sh b/packages/serverless-orchestration/local-docker/scripts/update-config.sh similarity index 69% rename from packages/serverless-orchestration/local-docker/scripts/update-bot-config.sh rename to packages/serverless-orchestration/local-docker/scripts/update-config.sh index 8c7304be30..6392b1f4a3 100644 --- a/packages/serverless-orchestration/local-docker/scripts/update-bot-config.sh +++ b/packages/serverless-orchestration/local-docker/scripts/update-config.sh @@ -20,4 +20,13 @@ echo "Processing JSON files in $CONFIG_DIR and storing environment in $ENV_FILE rm -f "$ENV_FILE" find "$CONFIG_DIR" -name "*.json" -exec sh "$CONVERT_SCRIPT" {} "$ENV_FILE" \; +# Update scheduler.env if bot-configs/schedule.json exists. Otherwise use empty environment. +SCHEDULE_FILE="$ROOT_DIR/bot-configs/schedule.json" +SCHEDULE_ENV_FILE="$ROOT_DIR/scheduler.env" +if [ -f "$SCHEDULE_FILE" ]; then + echo "Processing $SCHEDULE_FILE ..." + BOT_SCHEDULE=$(cat "$SCHEDULE_FILE" | jq tostring | sed -e 's/\\//g' -e 's/^\"//' -e 's/\"$//') +fi +echo "BOT_SCHEDULE=$BOT_SCHEDULE" > "$SCHEDULE_ENV_FILE" + exit 0 diff --git a/packages/serverless-orchestration/package.json b/packages/serverless-orchestration/package.json index 2a1b0ed005..2b956ff67c 100644 --- a/packages/serverless-orchestration/package.json +++ b/packages/serverless-orchestration/package.json @@ -43,7 +43,7 @@ "scripts": { "test": "HARDHAT_NETWORK=localhost yarn mocha 'test/**/*.js'", "local-build": "sh local-docker/scripts/docker-build.sh local-docker", - "local-config": "sh local-docker/scripts/update-bot-config.sh local-docker", + "local-config": "sh local-docker/scripts/update-config.sh local-docker", "local-up": "sh local-docker/scripts/docker-up.sh local-docker", "local-down": "sh local-docker/scripts/docker-down.sh local-docker" }, From 619134a5cf10e18b95eb0ad46eb93c14777dfe94 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Thu, 11 May 2023 17:53:41 +0000 Subject: [PATCH 04/20] wip Signed-off-by: Reinis Martinsons --- .../local-docker/scripts/docker-up.sh | 2 +- .../local-docker/scripts/update-config.sh | 29 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-up.sh b/packages/serverless-orchestration/local-docker/scripts/docker-up.sh index 8b9122eb4b..a5a46b4dfc 100644 --- a/packages/serverless-orchestration/local-docker/scripts/docker-up.sh +++ b/packages/serverless-orchestration/local-docker/scripts/docker-up.sh @@ -12,7 +12,7 @@ fi [ ! -f "$ROOT_DIR/compose.yml" ] && { echo "Error: compose.yml file not found"; exit 1; } [ ! -f "$ROOT_DIR/hub.env" ] && { echo "Error: hub.env file not found"; exit 1; } [ ! -f "$ROOT_DIR/spoke.env" ] && { echo "Error: spoke.env file not found"; exit 1; } -[ ! -f "$ROOT_DIR/scripts/update-bot-config.sh" ] && { echo "Error: scripts/update-bot-config.sh file not found"; exit 1; } +[ ! -f "$ROOT_DIR/scripts/update-config.sh" ] && { echo "Error: scripts/update-config.sh file not found"; exit 1; } # Convert JSON files under bot-configs to bot-config.env file and update scheduler.env. sh "$ROOT_DIR/scripts/update-config.sh" "$ROOT_DIR" diff --git a/packages/serverless-orchestration/local-docker/scripts/update-config.sh b/packages/serverless-orchestration/local-docker/scripts/update-config.sh index 6392b1f4a3..b890bcbe2c 100644 --- a/packages/serverless-orchestration/local-docker/scripts/update-config.sh +++ b/packages/serverless-orchestration/local-docker/scripts/update-config.sh @@ -1,4 +1,5 @@ # Script to convert JSON bot-configs to environment variables passed to the hub service. +# Also creates environment for the scheduler service. # Resolve provided root directory. Defaults to current directory if not provided. if [ -z "$1" ]; then @@ -12,21 +13,31 @@ fi [ ! -d "$ROOT_DIR/bot-configs" ] && { echo "Error: bot-configs directory not found"; exit 1; } [ ! -f "$ROOT_DIR/scripts/json-to-env.sh" ] && { echo "Error: scripts/json-to-env.sh file not found"; exit 1; } -# Convert JSON files under bot-configs to bot-config.env file. -CONVERT_SCRIPT="$ROOT_DIR/scripts/json-to-env.sh" -CONFIG_DIR="$ROOT_DIR/bot-configs" -ENV_FILE="$ROOT_DIR/bot-config.env" -echo "Processing JSON files in $CONFIG_DIR and storing environment in $ENV_FILE ..." -rm -f "$ENV_FILE" -find "$CONFIG_DIR" -name "*.json" -exec sh "$CONVERT_SCRIPT" {} "$ENV_FILE" \; - # Update scheduler.env if bot-configs/schedule.json exists. Otherwise use empty environment. -SCHEDULE_FILE="$ROOT_DIR/bot-configs/schedule.json" +CONFIG_DIR="$ROOT_DIR/bot-configs" +SCHEDULE_FILE="$CONFIG_DIR/schedule.json" SCHEDULE_ENV_FILE="$ROOT_DIR/scheduler.env" if [ -f "$SCHEDULE_FILE" ]; then + # Verify all array objects in schedule.json have required fields. + cat "$SCHEDULE_FILE" | jq -e '.[] | has("schedule") and has("bucket") and has("configFile")' > /dev/null + [ $? -ne 0 ] && { echo "Error: $SCHEDULE_FILE does not contain required fields"; exit 1; } + + # Verify all bucket/configFile values in schedule.json exist as bot-configs files. + cat "$SCHEDULE_FILE" | jq -r '.[] | [.bucket, .configFile] | @tsv' | + while IFS=$'\t' read -r bucket configFile + do [ ! -f "$CONFIG_DIR/$bucket/$configFile" ] && { echo "Error: $CONFIG_DIR/$bucket/$configFile not found"; exit 1; } + done + echo "Processing $SCHEDULE_FILE ..." BOT_SCHEDULE=$(cat "$SCHEDULE_FILE" | jq tostring | sed -e 's/\\//g' -e 's/^\"//' -e 's/\"$//') fi echo "BOT_SCHEDULE=$BOT_SCHEDULE" > "$SCHEDULE_ENV_FILE" +# Convert JSON files under bot-configs to bot-config.env file. +CONVERT_SCRIPT="$ROOT_DIR/scripts/json-to-env.sh" +CONFIG_ENV_FILE="$ROOT_DIR/bot-config.env" +echo "Processing JSON files in $CONFIG_DIR and storing environment in $CONFIG_ENV_FILE ..." +rm -f "$CONFIG_ENV_FILE" +find "$CONFIG_DIR" -name "*.json" -exec sh "$CONVERT_SCRIPT" {} "$CONFIG_ENV_FILE" \; + exit 0 From a9ef04c42d90ce26f3a29e50edea15ba9e6f331d Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Fri, 12 May 2023 11:24:38 +0000 Subject: [PATCH 05/20] fix: gitignore Signed-off-by: Reinis Martinsons --- packages/serverless-orchestration/.gitignore | 2 +- .../local-docker/bot-configs/schedule.json.template | 0 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 packages/serverless-orchestration/local-docker/bot-configs/schedule.json.template diff --git a/packages/serverless-orchestration/.gitignore b/packages/serverless-orchestration/.gitignore index 23b7a67778..e6926d7b7b 100644 --- a/packages/serverless-orchestration/.gitignore +++ b/packages/serverless-orchestration/.gitignore @@ -1 +1 @@ -local-docker/bot-configs/*/ +local-docker/bot-configs/**/*.json diff --git a/packages/serverless-orchestration/local-docker/bot-configs/schedule.json.template b/packages/serverless-orchestration/local-docker/bot-configs/schedule.json.template new file mode 100644 index 0000000000..e69de29bb2 From 35b420ceae83739d475ebb31009e7405918e0ce1 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Fri, 12 May 2023 11:59:01 +0000 Subject: [PATCH 06/20] feat: add example schedule Signed-off-by: Reinis Martinsons --- .../bot-configs/schedule.json.example | 20 +++++++++++++++++++ .../bot-configs/schedule.json.template | 0 2 files changed, 20 insertions(+) create mode 100644 packages/serverless-orchestration/local-docker/bot-configs/schedule.json.example delete mode 100644 packages/serverless-orchestration/local-docker/bot-configs/schedule.json.template diff --git a/packages/serverless-orchestration/local-docker/bot-configs/schedule.json.example b/packages/serverless-orchestration/local-docker/bot-configs/schedule.json.example new file mode 100644 index 0000000000..565836fe0f --- /dev/null +++ b/packages/serverless-orchestration/local-docker/bot-configs/schedule.json.example @@ -0,0 +1,20 @@ +# Use this example to create schedule.json for scheduling configured bots. This should be structured as an array of +# objects, each object containing the following properties: +# schedule: A cron expression for when the bot should run. See https://crontab.guru/ for help creating cron expressions. +# bucket: The name of the directory under bot-configs where the bot configuration file is stored. +# configFile: The name of the file containing bot configurations to use for the scheduled run. +# Make sure the corresponding bot configuration file exists before updating the config. +# As an example, the following schedule.json will run the bots in serverless-bots/bot-config.json file every 5 minutes +# and the serverless-bots/bot-config-slow.json file every 30 minutes: +[ + { + "schedule": "*/5 * * * *", + "bucket": "serverless-bots", + "configFile": "bot-config.json" + }, + { + "schedule": "*/30 * * * *", + "bucket": "serverless-bots", + "configFile": "bot-config-slow.json" + } +] diff --git a/packages/serverless-orchestration/local-docker/bot-configs/schedule.json.template b/packages/serverless-orchestration/local-docker/bot-configs/schedule.json.template deleted file mode 100644 index e69de29bb2..0000000000 From 7933206cffe174fb228c22620a9289c86e66f912 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Fri, 12 May 2023 19:08:18 +0000 Subject: [PATCH 07/20] fix: rename compose Signed-off-by: Reinis Martinsons --- .../local-docker/{compose.yml => docker-compose.yml} | 2 +- .../local-docker/scripts/docker-build.sh | 4 ++-- .../local-docker/scripts/docker-down.sh | 4 ++-- .../local-docker/scripts/docker-up.sh | 4 ++-- .../local-docker/scripts/json-to-env.sh | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) rename packages/serverless-orchestration/local-docker/{compose.yml => docker-compose.yml} (95%) diff --git a/packages/serverless-orchestration/local-docker/compose.yml b/packages/serverless-orchestration/local-docker/docker-compose.yml similarity index 95% rename from packages/serverless-orchestration/local-docker/compose.yml rename to packages/serverless-orchestration/local-docker/docker-compose.yml index 206c3475a9..1e941f9895 100644 --- a/packages/serverless-orchestration/local-docker/compose.yml +++ b/packages/serverless-orchestration/local-docker/docker-compose.yml @@ -7,7 +7,7 @@ services: - hub.env - bot-config.env ports: - - "8081:8080" + - "8080:8080" spoke: image: umaprotocol/protocol:local build: ../../.. diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-build.sh b/packages/serverless-orchestration/local-docker/scripts/docker-build.sh index 7b8c868f1e..c3d399d327 100644 --- a/packages/serverless-orchestration/local-docker/scripts/docker-build.sh +++ b/packages/serverless-orchestration/local-docker/scripts/docker-build.sh @@ -9,10 +9,10 @@ else fi # Verify required compose file exists. -[ ! -f "$ROOT_DIR/compose.yml" ] && { echo "Error: compose.yml file not found"; exit 1; } +[ ! -f "$ROOT_DIR/docker-docker-compose.yml" ] && { echo "Error: docker-compose.yml file not found"; exit 1; } # Build docker image. echo "Building local docker image ..." -docker compose -f "$ROOT_DIR/compose.yml" -p local-serverless build +docker compose -f "$ROOT_DIR/docker-compose.yml" exit 0 diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-down.sh b/packages/serverless-orchestration/local-docker/scripts/docker-down.sh index c32ffab087..834763f69d 100644 --- a/packages/serverless-orchestration/local-docker/scripts/docker-down.sh +++ b/packages/serverless-orchestration/local-docker/scripts/docker-down.sh @@ -9,10 +9,10 @@ else fi # Verify required compose file exists. -[ ! -f "$ROOT_DIR/compose.yml" ] && { echo "Error: compose.yml file not found"; exit 1; } +[ ! -f "$ROOT_DIR/docker-compose.yml" ] && { echo "Error: docker-compose.yml file not found"; exit 1; } # Stop hub and spoke services. echo "Stopping hub and spoke services ..." -docker compose -f "$ROOT_DIR/compose.yml" -p local-serverless down +docker compose -f "$ROOT_DIR/docker-compose.yml" down exit 0 diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-up.sh b/packages/serverless-orchestration/local-docker/scripts/docker-up.sh index a5a46b4dfc..ae00f921d8 100644 --- a/packages/serverless-orchestration/local-docker/scripts/docker-up.sh +++ b/packages/serverless-orchestration/local-docker/scripts/docker-up.sh @@ -9,7 +9,7 @@ else fi # Verify required files exist. -[ ! -f "$ROOT_DIR/compose.yml" ] && { echo "Error: compose.yml file not found"; exit 1; } +[ ! -f "$ROOT_DIR/docker-compose.yml" ] && { echo "Error: docker-compose.yml file not found"; exit 1; } [ ! -f "$ROOT_DIR/hub.env" ] && { echo "Error: hub.env file not found"; exit 1; } [ ! -f "$ROOT_DIR/spoke.env" ] && { echo "Error: spoke.env file not found"; exit 1; } [ ! -f "$ROOT_DIR/scripts/update-config.sh" ] && { echo "Error: scripts/update-config.sh file not found"; exit 1; } @@ -22,6 +22,6 @@ sh "$ROOT_DIR/scripts/update-config.sh" "$ROOT_DIR" # Start or update hub and spoke services. echo "Starting or updating hub and spoke services ..." -docker compose -f "$ROOT_DIR/compose.yml" -p local-serverless up -d +docker compose -f "$ROOT_DIR/docker-compose.yml" up -d exit 0 diff --git a/packages/serverless-orchestration/local-docker/scripts/json-to-env.sh b/packages/serverless-orchestration/local-docker/scripts/json-to-env.sh index 809b415206..fecbecdfae 100644 --- a/packages/serverless-orchestration/local-docker/scripts/json-to-env.sh +++ b/packages/serverless-orchestration/local-docker/scripts/json-to-env.sh @@ -1,5 +1,5 @@ # Script to stringify json file $1 and append to env file $2. -# This is used by update-bot-config.sh script. +# This is used by update-config.sh script. # Requires jq being installed. echo "Processing $1 ..." From 183fc9fbf6aaad2b1a7427e3c25c7663ad9da7d6 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Sat, 13 May 2023 13:25:06 +0000 Subject: [PATCH 08/20] fix: remove IFS Signed-off-by: Reinis Martinsons --- .../local-docker/scheduler/entrypoint.sh | 2 +- .../local-docker/scripts/update-config.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/serverless-orchestration/local-docker/scheduler/entrypoint.sh b/packages/serverless-orchestration/local-docker/scheduler/entrypoint.sh index 98cb76e5f0..76dfed3b01 100644 --- a/packages/serverless-orchestration/local-docker/scheduler/entrypoint.sh +++ b/packages/serverless-orchestration/local-docker/scheduler/entrypoint.sh @@ -2,7 +2,7 @@ # Parse the BOT_SCHEDULE environment variable and construct the crontab echo "$BOT_SCHEDULE" | jq -r '.[] | [.schedule, .bucket, .configFile] | @tsv' | - while IFS=$'\t' read -r schedule bucket configFile + while read -r schedule bucket configFile do echo "$schedule /scheduler/run-bots.sh $bucket $configFile $HUB_URL" >> /tmp/crontab done diff --git a/packages/serverless-orchestration/local-docker/scripts/update-config.sh b/packages/serverless-orchestration/local-docker/scripts/update-config.sh index b890bcbe2c..a632c58805 100644 --- a/packages/serverless-orchestration/local-docker/scripts/update-config.sh +++ b/packages/serverless-orchestration/local-docker/scripts/update-config.sh @@ -24,7 +24,7 @@ if [ -f "$SCHEDULE_FILE" ]; then # Verify all bucket/configFile values in schedule.json exist as bot-configs files. cat "$SCHEDULE_FILE" | jq -r '.[] | [.bucket, .configFile] | @tsv' | - while IFS=$'\t' read -r bucket configFile + while read -r bucket configFile do [ ! -f "$CONFIG_DIR/$bucket/$configFile" ] && { echo "Error: $CONFIG_DIR/$bucket/$configFile not found"; exit 1; } done From 162475eefa0c20a2bfb230d2118112e2e1af0b37 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Sat, 13 May 2023 16:18:08 +0000 Subject: [PATCH 09/20] fix Signed-off-by: Reinis Martinsons --- .../local-docker/scripts/docker-build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-build.sh b/packages/serverless-orchestration/local-docker/scripts/docker-build.sh index c3d399d327..bb52871d3e 100644 --- a/packages/serverless-orchestration/local-docker/scripts/docker-build.sh +++ b/packages/serverless-orchestration/local-docker/scripts/docker-build.sh @@ -9,10 +9,10 @@ else fi # Verify required compose file exists. -[ ! -f "$ROOT_DIR/docker-docker-compose.yml" ] && { echo "Error: docker-compose.yml file not found"; exit 1; } +[ ! -f "$ROOT_DIR/docker-compose.yml" ] && { echo "Error: docker-compose.yml file not found"; exit 1; } # Build docker image. echo "Building local docker image ..." -docker compose -f "$ROOT_DIR/docker-compose.yml" +docker compose -f "$ROOT_DIR/docker-compose.yml" build exit 0 From 7f54c1f17fec4532d4eecef3789a57f395351058 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Sat, 13 May 2023 17:15:52 +0000 Subject: [PATCH 10/20] fix: dont expose ports Signed-off-by: Reinis Martinsons --- .../serverless-orchestration/local-docker/docker-compose.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/serverless-orchestration/local-docker/docker-compose.yml b/packages/serverless-orchestration/local-docker/docker-compose.yml index 1e941f9895..79a93e757b 100644 --- a/packages/serverless-orchestration/local-docker/docker-compose.yml +++ b/packages/serverless-orchestration/local-docker/docker-compose.yml @@ -6,8 +6,6 @@ services: env_file: - hub.env - bot-config.env - ports: - - "8080:8080" spoke: image: umaprotocol/protocol:local build: ../../.. From 53a58a07aeb4c70a148b347aa9c61ad7f0363539 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Sat, 13 May 2023 17:28:41 +0000 Subject: [PATCH 11/20] fix: update readme Signed-off-by: Reinis Martinsons --- .../local-docker/README.md | 62 ++++++++++++------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/packages/serverless-orchestration/local-docker/README.md b/packages/serverless-orchestration/local-docker/README.md index 075225b6bc..efc1ca9d90 100644 --- a/packages/serverless-orchestration/local-docker/README.md +++ b/packages/serverless-orchestration/local-docker/README.md @@ -3,45 +3,59 @@ This document describes how to run the UMA Serverless Orchestration scripts locally using Docker. This is useful for testing and debugging bots locally before deploying them to the cloud. -The instructions below assume you have [Docker](https://www.docker.com/) installed and its server daemon is running on -the local machine. Also make sure to add your user to `docker` group in order to avoid running commands as root. +The instructions below assume you have [Docker](https://www.docker.com/) and its Compose plugin installed and its server +daemon is running on the local machine. Also make sure to add your user to `docker` group in order to avoid running +commands as root. -Start by enabling swarm mode so that hub and spoke services can be configured in a single [compose file](./uma.yml): +## Build UMA Protocol Docker Image + +In order to build local UMA protocol docker image, run the build script: ```sh -docker swarm init +yarn workspace @uma/serverless-orchestration local-build ``` -## Build UMA Protocol Docker Image +This will build two docker images: -This step is only required if you are testing against a local development branch of the UMA protocol. If you are -testing bot configuration against the published protocol docker image, you can skip this step. +- `umaprotocol/protocol:local` for the UMA protocol +- `scheduler:local` for the cron scheduler that will trigger bots through local hub service -Start the `registry` service: +## Service configuration -```sh -docker service create --name registry --publish published=5000,target=5000 registry:2 -``` +In the `packages/serverless-orchestration/local-docker/` directory create the required `hub.env` and `spoke.env` files +using the provided templates in [hub.env.template](./hub.env.template) and [spoke.env.template](./spoke.env.template) +respectively. -Start the docker build from the root of `protocol` repository: +Place all the tested bot configuration files under the [`./bot-configs/serverless-bots`](./bot-configs/serverless-bots) +directory. Configuration files must be formatted as JSON and have a `.json` extension. -```sh -docker build -t localhost:5000/protocol:dev . -``` +In the [`./bot-configs`](./bot-configs) directory create the required `schedule.json` file using the provided template +in [schedule.json.example](./bot-configs/schedule.json.example). This configuration will be used by the cron scheduler +service to trigger bots through the local hub service. -Once build is complete, push it to the local registry service: +## Start UMA Serverless Orchestration + +To start the UMA Serverless Orchestration services run: ```sh -docker push localhost:5000/protocol:dev +yarn workspace @uma/serverless-orchestration local-up ``` -## Service configuration +This will start the following services: -In the same directory where `uma.yml` compose file is located create the required `hub.env` and `spoke.env` files using -the provided templates in [hub.env.template](./hub.env.template) and [spoke.env.template](./spoke.env.template) -respectively. +- `hub`: local hub service +- `spoke`: local spoke service +- `scheduler`: cron scheduler service -Place all the tested bot configuration files under the [./bot-configs/serverless-bots](./bot-configs/serverless-bots) -directory. Configuration files must be formatted as JSON and have a `.json` extension. +## Stop UMA Serverless Orchestration -## Start UMA Serverless Orchestration +To stop the UMA Serverless Orchestration services run: + +```sh +yarn workspace @uma/serverless-orchestration local-down +``` + +## Limitations + +Currently, the local UMA Serverless Orchestration does not support running bots that require access to GCP Datastore and +caching service. From 13135f3f7358ccb964189b0ea7c741935e2d3316 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Sat, 13 May 2023 21:40:51 +0000 Subject: [PATCH 12/20] fix Signed-off-by: Reinis Martinsons --- packages/serverless-orchestration/local-docker/README.md | 2 +- .../serverless-orchestration/local-docker/hub.env.template | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/serverless-orchestration/local-docker/README.md b/packages/serverless-orchestration/local-docker/README.md index efc1ca9d90..6c25efbceb 100644 --- a/packages/serverless-orchestration/local-docker/README.md +++ b/packages/serverless-orchestration/local-docker/README.md @@ -1,6 +1,6 @@ # Running UMA Serverless Orchestration Locally With Docker -This document describes how to run the UMA Serverless Orchestration scripts locally using Docker. This is useful for +This document describes how to run the UMA Serverless Orchestration service locally using Docker. This is useful for testing and debugging bots locally before deploying them to the cloud. The instructions below assume you have [Docker](https://www.docker.com/) and its Compose plugin installed and its server diff --git a/packages/serverless-orchestration/local-docker/hub.env.template b/packages/serverless-orchestration/local-docker/hub.env.template index 11fb973691..6572f2af04 100644 --- a/packages/serverless-orchestration/local-docker/hub.env.template +++ b/packages/serverless-orchestration/local-docker/hub.env.template @@ -3,8 +3,8 @@ # Entry point for the hub service. COMMAND=node packages/serverless-orchestration/src/ServerlessHub.js -# Default spoke URL. Docker stack automatically adds all services to the same network, thus we can use the service name -# as the hostname. +# Default spoke URL. Docker compose automatically adds all services to the same network, thus we can use the service +# name as the hostname. SPOKE_URL=http://spoke:8080 # Spoke URLs for different spoke services. This is only required if the tested bot configuration includes spokeUrlName From 857156305b7c8fc3cd42f69b99e6741e2172d5da Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Sat, 13 May 2023 21:44:21 +0000 Subject: [PATCH 13/20] fix Signed-off-by: Reinis Martinsons --- packages/serverless-orchestration/local-docker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/serverless-orchestration/local-docker/README.md b/packages/serverless-orchestration/local-docker/README.md index 6c25efbceb..aa81a0768d 100644 --- a/packages/serverless-orchestration/local-docker/README.md +++ b/packages/serverless-orchestration/local-docker/README.md @@ -26,7 +26,7 @@ In the `packages/serverless-orchestration/local-docker/` directory create the re using the provided templates in [hub.env.template](./hub.env.template) and [spoke.env.template](./spoke.env.template) respectively. -Place all the tested bot configuration files under the [`./bot-configs/serverless-bots`](./bot-configs/serverless-bots) +Place all the tested bot configuration files under the `packages/serverless-orchestration/local-docker/bot-configs/serverless-bots` directory. Configuration files must be formatted as JSON and have a `.json` extension. In the [`./bot-configs`](./bot-configs) directory create the required `schedule.json` file using the provided template From 04ca99203b15eec35d0bc92bcdcd95d86f3a58e5 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Sat, 13 May 2023 21:46:03 +0000 Subject: [PATCH 14/20] fix: formatting Signed-off-by: Reinis Martinsons --- packages/serverless-orchestration/local-docker/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/serverless-orchestration/local-docker/README.md b/packages/serverless-orchestration/local-docker/README.md index aa81a0768d..5cf92a60e2 100644 --- a/packages/serverless-orchestration/local-docker/README.md +++ b/packages/serverless-orchestration/local-docker/README.md @@ -23,14 +23,14 @@ This will build two docker images: ## Service configuration In the `packages/serverless-orchestration/local-docker/` directory create the required `hub.env` and `spoke.env` files -using the provided templates in [hub.env.template](./hub.env.template) and [spoke.env.template](./spoke.env.template) +using the provided templates in [`hub.env.template`](./hub.env.template) and [`spoke.env.template`](./spoke.env.template) respectively. Place all the tested bot configuration files under the `packages/serverless-orchestration/local-docker/bot-configs/serverless-bots` directory. Configuration files must be formatted as JSON and have a `.json` extension. In the [`./bot-configs`](./bot-configs) directory create the required `schedule.json` file using the provided template -in [schedule.json.example](./bot-configs/schedule.json.example). This configuration will be used by the cron scheduler +in [`schedule.json.example`](./bot-configs/schedule.json.example). This configuration will be used by the cron scheduler service to trigger bots through the local hub service. ## Start UMA Serverless Orchestration From fdf42d7810e9de64016e5c990815e10ccf9ee887 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Sat, 13 May 2023 21:54:51 +0000 Subject: [PATCH 15/20] fix Signed-off-by: Reinis Martinsons --- .../serverless-orchestration/local-docker/hub.env.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/serverless-orchestration/local-docker/hub.env.template b/packages/serverless-orchestration/local-docker/hub.env.template index 6572f2af04..07d0c9b2c7 100644 --- a/packages/serverless-orchestration/local-docker/hub.env.template +++ b/packages/serverless-orchestration/local-docker/hub.env.template @@ -8,8 +8,8 @@ COMMAND=node packages/serverless-orchestration/src/ServerlessHub.js SPOKE_URL=http://spoke:8080 # Spoke URLs for different spoke services. This is only required if the tested bot configuration includes spokeUrlName -# property. Since the included uma.yml compose file runs only one spoke service we point all named spoke URLs to the -# same spoke service. +# property. Since the docker-compose.yml file runs only one spoke service we point all named spoke URLs to the same +# spoke service. SPOKE_URLS={"large":"http://spoke:8080","small":"http://spoke:8080"} # Provide fallback RPC node URL. From 1aebb7aa64f7ef260f73572af537990f42abeda0 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Sat, 13 May 2023 22:13:49 +0000 Subject: [PATCH 16/20] fix: pass through exit codes Signed-off-by: Reinis Martinsons --- .../local-docker/scripts/docker-build.sh | 2 +- .../local-docker/scripts/docker-down.sh | 2 +- .../serverless-orchestration/local-docker/scripts/docker-up.sh | 2 +- .../local-docker/scripts/update-config.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-build.sh b/packages/serverless-orchestration/local-docker/scripts/docker-build.sh index bb52871d3e..738a93c555 100644 --- a/packages/serverless-orchestration/local-docker/scripts/docker-build.sh +++ b/packages/serverless-orchestration/local-docker/scripts/docker-build.sh @@ -15,4 +15,4 @@ fi echo "Building local docker image ..." docker compose -f "$ROOT_DIR/docker-compose.yml" build -exit 0 +exit $? diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-down.sh b/packages/serverless-orchestration/local-docker/scripts/docker-down.sh index 834763f69d..29897a84e9 100644 --- a/packages/serverless-orchestration/local-docker/scripts/docker-down.sh +++ b/packages/serverless-orchestration/local-docker/scripts/docker-down.sh @@ -15,4 +15,4 @@ fi echo "Stopping hub and spoke services ..." docker compose -f "$ROOT_DIR/docker-compose.yml" down -exit 0 +exit $? diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-up.sh b/packages/serverless-orchestration/local-docker/scripts/docker-up.sh index ae00f921d8..cc12ec215a 100644 --- a/packages/serverless-orchestration/local-docker/scripts/docker-up.sh +++ b/packages/serverless-orchestration/local-docker/scripts/docker-up.sh @@ -24,4 +24,4 @@ sh "$ROOT_DIR/scripts/update-config.sh" "$ROOT_DIR" echo "Starting or updating hub and spoke services ..." docker compose -f "$ROOT_DIR/docker-compose.yml" up -d -exit 0 +exit $? diff --git a/packages/serverless-orchestration/local-docker/scripts/update-config.sh b/packages/serverless-orchestration/local-docker/scripts/update-config.sh index a632c58805..881d29f6af 100644 --- a/packages/serverless-orchestration/local-docker/scripts/update-config.sh +++ b/packages/serverless-orchestration/local-docker/scripts/update-config.sh @@ -40,4 +40,4 @@ echo "Processing JSON files in $CONFIG_DIR and storing environment in $CONFIG_EN rm -f "$CONFIG_ENV_FILE" find "$CONFIG_DIR" -name "*.json" -exec sh "$CONVERT_SCRIPT" {} "$CONFIG_ENV_FILE" \; -exit 0 +exit $? From 26792e645f9713e9d8974858748ab6d48d65706f Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Sat, 13 May 2023 22:15:42 +0000 Subject: [PATCH 17/20] fix: comment Signed-off-by: Reinis Martinsons --- .../serverless-orchestration/local-docker/scripts/docker-up.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/serverless-orchestration/local-docker/scripts/docker-up.sh b/packages/serverless-orchestration/local-docker/scripts/docker-up.sh index cc12ec215a..61ffffad5e 100644 --- a/packages/serverless-orchestration/local-docker/scripts/docker-up.sh +++ b/packages/serverless-orchestration/local-docker/scripts/docker-up.sh @@ -1,4 +1,4 @@ -# Script to parse bot-configs and start or update hub and spoke docker services. +# Script to parse bot-configs and start or update docker services. # Resolve provided root directory. Defaults to current directory if not provided. if [ -z "$1" ]; then From b4e20254fef8d3f702b3a683bd305eaa58995172 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Sat, 13 May 2023 22:20:16 +0000 Subject: [PATCH 18/20] fix: change logger delay Signed-off-by: Reinis Martinsons --- .../serverless-orchestration/local-docker/spoke.env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/serverless-orchestration/local-docker/spoke.env.template b/packages/serverless-orchestration/local-docker/spoke.env.template index 73efb5714e..48be962e04 100644 --- a/packages/serverless-orchestration/local-docker/spoke.env.template +++ b/packages/serverless-orchestration/local-docker/spoke.env.template @@ -10,7 +10,7 @@ BOT_IDENTIFIER=serverless-spoke POLLING_DELAY=0 # Time in seconds to wait for logger to flush. -WAIT_FOR_LOGGER_DELAY=30 +WAIT_FOR_LOGGER_DELAY=5 # Stringified JSON configuration in the form of {"defaultWebHookUrl":""} where should be # replaced with the URL of Slack webhook for the channel to which the spoke should send notifications. From fe4e6103b133a5f30bd595ce7a8702071407d2bf Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Sat, 13 May 2023 22:57:22 +0000 Subject: [PATCH 19/20] fix: IFS Signed-off-by: Reinis Martinsons --- .../local-docker/scheduler/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/serverless-orchestration/local-docker/scheduler/entrypoint.sh b/packages/serverless-orchestration/local-docker/scheduler/entrypoint.sh index 76dfed3b01..98cb76e5f0 100644 --- a/packages/serverless-orchestration/local-docker/scheduler/entrypoint.sh +++ b/packages/serverless-orchestration/local-docker/scheduler/entrypoint.sh @@ -2,7 +2,7 @@ # Parse the BOT_SCHEDULE environment variable and construct the crontab echo "$BOT_SCHEDULE" | jq -r '.[] | [.schedule, .bucket, .configFile] | @tsv' | - while read -r schedule bucket configFile + while IFS=$'\t' read -r schedule bucket configFile do echo "$schedule /scheduler/run-bots.sh $bucket $configFile $HUB_URL" >> /tmp/crontab done From 87b511af503b5b8275d8e982cf1a5ecc8f367eab Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Tue, 16 May 2023 10:50:45 +0000 Subject: [PATCH 20/20] fix: add jq requirement Signed-off-by: Reinis Martinsons --- packages/serverless-orchestration/local-docker/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/serverless-orchestration/local-docker/README.md b/packages/serverless-orchestration/local-docker/README.md index 5cf92a60e2..44752f4cbc 100644 --- a/packages/serverless-orchestration/local-docker/README.md +++ b/packages/serverless-orchestration/local-docker/README.md @@ -7,6 +7,8 @@ The instructions below assume you have [Docker](https://www.docker.com/) and its daemon is running on the local machine. Also make sure to add your user to `docker` group in order to avoid running commands as root. +You also need to have `jq` installed on your machine as it is used for scripts parsing tested bot configuration files. + ## Build UMA Protocol Docker Image In order to build local UMA protocol docker image, run the build script: