From e1cbb43565a7d45baef6e17f9af6ce74dffe1741 Mon Sep 17 00:00:00 2001 From: kexkey Date: Tue, 25 Aug 2020 18:22:10 -0400 Subject: [PATCH] Batcher cypherapp --- batcher/data/config.json | 18 +++++++++++++++++ batcher/docker-compose.yaml | 25 +++++++++++++++++++++++ batcher/isCoreApp | 0 batcher/test.sh | 40 +++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 batcher/data/config.json create mode 100644 batcher/docker-compose.yaml create mode 100644 batcher/isCoreApp create mode 100644 batcher/test.sh diff --git a/batcher/data/config.json b/batcher/data/config.json new file mode 100644 index 0000000..e9f1394 --- /dev/null +++ b/batcher/data/config.json @@ -0,0 +1,18 @@ +{ + "LOG": "DEBUG", + "BASE_DIR": "/batcher", + "DATA_DIR": "data", + "DB_NAME": "batcher.sqlite", + "URL_SERVER": "http://batcher", + "URL_PORT": 8000, + "URL_CTX_WEBHOOKS": "webhooks", + "SESSION_TIMEOUT": 600, + "CN_URL": "https://gatekeeper:2009/v0", + "CN_API_ID": "003", + "CN_API_KEY": "39b83c35972aeb81a242bfe189dc0a22da5ac6cbb64072b492f2d46519a97618", + "DEFAULT_BATCHER_ID": 1, + "BATCH_TIMEOUT_MINUTES": 60, + "CHECK_THRESHOLD_MINUTES": 10, + "BATCH_THRESHOLD_AMOUNT": 0.5, + "BATCH_CONF_TARGET": 6 +} diff --git a/batcher/docker-compose.yaml b/batcher/docker-compose.yaml new file mode 100644 index 0000000..5b6d943 --- /dev/null +++ b/batcher/docker-compose.yaml @@ -0,0 +1,25 @@ +version: "3" + +services: + batcher: + environment: + - "TRACING=1" + - "CYPHERNODE_URL=https://gatekeeper:${GATEKEEPER_PORT}" + image: cyphernode/batcher:v0.1.0 + entrypoint: ["npm", "run", "start:dev"] + volumes: + - "$APP_SCRIPT_PATH/data:/batcher/data" + - "$GATEKEEPER_DATAPATH/certs/cert.pem:/batcher/cert.pem:ro" + networks: + - cyphernodeappsnet + restart: always + labels: + - "traefik.docker.network=cyphernodeappsnet" + - "traefik.frontend.rule=PathPrefixStrip:/batcher" + - "traefik.frontend.passHostHeader=true" + - "traefik.enable=true" + - "traefik.port=8000" + - "traefik.frontend.auth.basic.users=" +networks: + cyphernodeappsnet: + external: true diff --git a/batcher/isCoreApp b/batcher/isCoreApp new file mode 100644 index 0000000..e69de29 diff --git a/batcher/test.sh b/batcher/test.sh new file mode 100644 index 0000000..e001df3 --- /dev/null +++ b/batcher/test.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +timeout_feature() { + local interval=10 + local totaltime=60 + local testwhat=${1} + local returncode + local endtime=$(($(date +%s) + ${totaltime})) + + while : + do + eval ${testwhat} + returncode=$? + + # If no error or 2 minutes passed, we get out of this loop + ([ "${returncode}" -eq "0" ] || [ $(date +%s) -gt ${endtime} ]) && break + + printf "\e[1;31mMaybe it's too early, I'll retry every ${interval} seconds for $((${totaltime} / 60)) minutes ($((${endtime} - $(date +%s))) seconds left).\e[1;0m\r\n" + + sleep ${interval} + done + + return ${returncode} +} + +do_test() { + local rc + rc=$(curl -k -s -o /dev/null -w "%{http_code}" https://127.0.0.1:${TRAEFIK_HTTPS_PORT}/batcher) + [ "${rc}" -ne "401" ] && return 400 + return 0 +} + +export TRAEFIK_HTTPS_PORT + +timeout_feature do_test +returncode=$? + +# return 0: tests cool +# return 1: tests failed +return $returncode