Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Add scripts to clean, build, run and test the app
Browse files Browse the repository at this point in the history
  • Loading branch information
kgapos committed Oct 27, 2023
1 parent 5b79765 commit 3afeb36
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ jobs:
run: docker run -d -p 11012:11012 -e NODE_URL=https://mainnet.vechain.org --name node-healthcheck node-healthcheck:latest
- name: Smoke test
run: |
IS_HEALTHY=$(curl -s http://localhost:11012/healthcheck | jq ".isHealthy")
RESPONSE=$(curl -s http://localhost:11012/healthcheck)
IS_HEALTHY=$(echo $RESPONSE | jq ".isHealthy")
if [ "$IS_HEALTHY" != "true" ]; then
echo "Smoke test failed"
exit 1
Expand Down
9 changes: 9 additions & 0 deletions scripts/all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

scripts_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
"$scripts_path/clean.sh"
"$scripts_path/build.sh"
"$scripts_path/run.sh"
sleep 1
"$scripts_path/test.sh"
4 changes: 4 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e

docker build -t node-healthcheck:dev ..
5 changes: 5 additions & 0 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e

docker rm node-healthcheck -f 2> /dev/null
docker rmi node-healthcheck:dev -f 2> /dev/null
6 changes: 3 additions & 3 deletions release.sh → scripts/release.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -ex
set -e

if [ -z "$1" ]; then
echo "Please provide the tag for the new build."
exit 1
echo "Please provide the tag for the new build."
exit 1
fi
tag=$1

Expand Down
8 changes: 8 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e

docker run -d \
--name node-healthcheck \
-p 11012:11012 \
-e NODE_URL="https://sync-testnet.vechain.org" \
node-healthcheck:dev
30 changes: 30 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -e

retry_command() {
local max_attempts=5
local delay=3
local attempt=0

until [ $attempt -ge $max_attempts ]; do
"$@"
local exit_code=$?
if [ $exit_code -eq 0 ]; then
return 0
fi

attempt=$((attempt + 1))
echo "Command failed (Attempt $attempt/$max_attempts). Retrying in $delay seconds..." >&2
sleep "$delay"
done

echo "Command failed $max_attempts times. Giving up." >&2
}

response=$(retry_command curl -s http://localhost:11012/healthcheck)
is_healthy=$(echo $response | jq ".isHealthy")
if [ "$is_healthy" == "true" ]; then
echo "Smoke test successful."
else
echo "Smoke test failed."
fi

0 comments on commit 3afeb36

Please sign in to comment.