Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto update support for containers #93

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions scripts/checkForUpdates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash


DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
VERSION_FILE="https://raw.githubusercontent.com/fuseio/fuse-network/master/Version"

function updateContainers {
"$DIR/quickstart.sh"
}

function getContainerImageNames {
docker ps -a --format '{{.Image}}'
}

function grabAndParseVersionFile {
wget -O "$DIR/versionFile" $VERSION_FILE
source "$DIR/versionFile"

# Print versions
echo "Oracle version = $DOCKER_IMAGE_ORACLE_VERSION"
echo "Parity version = $DOCKER_IMAGE_FUSE_PARITY_VERSION"
echo "Fuse app version = $DOCKER_IMAGE_FUSE_APP_VERSION"
echo "Netstats version = $DOCKER_IMAGE_NET_STATS_VERSION"
}

function versionComp {
local nodeName=$1
local expectedVersion=$2
if [[ $nodeName == *"$expectedVersion"* ]]; then
return 0
else
return 1
fi
}

function checkContainers {
grabAndParseVersionFile
conatiners=$(getContainerImageNames)
update=0

for IMAGE_NAME_WITH_TAG in ${conatiners[@]}; do
Andrew-Pohl marked this conversation as resolved.
Show resolved Hide resolved
if [[ $IMAGE_NAME_WITH_TAG == *"netstat"* ]]; then
#netstats container
versionComp "$IMAGE_NAME_WITH_TAG" "$DOCKER_IMAGE_NET_STATS_VERSION"
update=$?
elif [[ $IMAGE_NAME_WITH_TAG == *"validator-app"* ]]; then
#fuseapp container
versionComp "$IMAGE_NAME_WITH_TAG" "$DOCKER_IMAGE_FUSE_APP_VERSION"
update=$?
elif [[ $IMAGE_NAME_WITH_TAG == *"node"* ]]; then
#parity container
versionComp "$IMAGE_NAME_WITH_TAG" "$DOCKER_IMAGE_FUSE_PARITY_VERSION"
update=$?
elif [[ $IMAGE_NAME_WITH_TAG == *"native-to-erc20-oracle"* ]]; then
#bridge container
versionComp "$IMAGE_NAME_WITH_TAG" "$DOCKER_IMAGE_ORACLE_VERSION"
update=$?
fi

if [[ $update == 1 ]]; then
break
fi
done

if [[ $update == 1 ]]; then
updateContainers
fi
}

checkContainers
2 changes: 2 additions & 0 deletions scripts/examples/.env.bootnode.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ BOOTNODES=enode://e21e2053005e40653d055fc01a07768357749d27d630702c203b1a3c00bdf2

# in case `sudo` is needed
PERMISSION_PREFIX=

ENABLE_AUTO_UPDATE=1
4 changes: 3 additions & 1 deletion scripts/examples/.env.bridgeValidator.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ FOREIGN_START_BLOCK=9911301
MAX_PROCESSING_TIME=60000

# create a defi pulse account to access ethgas station api https://data.defipulse.com/
FOREIGN_GAS_PRICE_ORACLE_URL=
FOREIGN_GAS_PRICE_ORACLE_URL=

ENABLE_AUTO_UPDATE=1
4 changes: 3 additions & 1 deletion scripts/examples/.env.explorer.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ ROLE=explorer
NODE_KEY=<your_node_key>

# in case `sudo` is needed
PERMISSION_PREFIX=
PERMISSION_PREFIX=

ENABLE_AUTO_UPDATE=0
2 changes: 2 additions & 0 deletions scripts/examples/.env.node.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ PERMISSION_PREFIX=
# NUMBER_OF_HTTP_CONNECTIONS_THREADS should be the amount of maximum concurrent connection you require (recommended <= 4 * cpu cores)
NUMBER_OF_RPC_THREADS=1
NUMBER_OF_HTTP_CONNECTIONS_THREADS=4

ENABLE_AUTO_UPDATE=1
4 changes: 3 additions & 1 deletion scripts/examples/.env.validator.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ PERMISSION_PREFIX=
# netstats validator name
VAL_NAME=

MAX_PROCESSING_TIME=60000
MAX_PROCESSING_TIME=60000

ENABLE_AUTO_UPDATE=1
44 changes: 38 additions & 6 deletions scripts/quickstart.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/bash


set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

OLDIFS=$IFS

QUICKSTART_VERSION="1.0.0"
Expand All @@ -14,7 +17,9 @@ DOCKER_IMAGE_FUSE_APP_VERSION="1.0.0"
DOCKER_IMAGE_FUSE_PARITY_VERSION="1.0.0"
DOCKER_IMAGE_NET_STATS_VERSION="1.0.0"

ENV_FILE=".env"
AUTOUPDATE_FILE="https://raw.githubusercontent.com/fuseio/fuse-network/master/scripts/checkForUpdates.sh"

ENV_FILE="$DIR/.env"
DOCKER_IMAGE_PARITY="fusenet/node"
DOCKER_CONTAINER_PARITY="fusenet"
DOCKER_IMAGE_APP="fusenet/validator-app"
Expand All @@ -25,7 +30,7 @@ DOCKER_COMPOSE_ORACLE="https://raw.githubusercontent.com/fuseio/fuse-bridge/mast
DOCKER_IMAGE_ORACLE="fusenet/native-to-erc20-oracle"
DOCKER_CONTAINER_ORACLE="fuseoracle"
DOCKER_LOG_OPTS="--log-opt max-size=10m --log-opt max-file=25 --log-opt compress=true"
BASE_DIR=$(pwd)/fusenet
BASE_DIR="$DIR/fusenet"
DATABASE_DIR=$BASE_DIR/database
CONFIG_DIR=$BASE_DIR/config
PASSWORD_FILE=$CONFIG_DIR/pass.pwd
Expand Down Expand Up @@ -63,6 +68,29 @@ declare -a VALID_ROLE_LIST=(
bridge-validator
)

function stopCronTask {
FILE="/etc/cron.d/autoUpdateFuse"

if [ -f "$FILE" ]; then
$PERMISSION_PREFIX rm "$FILE"
fi
}

function addCronTask {
FILE="/etc/cron.d/autoUpdateFuse"

#grab the auto update script
wget -O "$DIR/autoUpdate.sh" $AUTOUPDATE_FILE

Hour=$(($RANDOM % 23))
Mins=$(($RANDOM % 59))

CRONSTRING="$Mins $Hour * * * $USER $DIR/autoUpdate.sh > $DIR/autoUpdateOut.log 2>&1"

echo "$CRONSTRING" >> "$FILE"
echo "Running auto update everyday at $Hour:$Mins"
}

function displayErrorAndExit {
local arg1=$1
if [[ $arg1 != "" ]];
Expand Down Expand Up @@ -210,7 +238,7 @@ function checkEthGasAPI {

function checkDiskSpace {
if [ $PLATFORM == "LINUX" ]; then
mountedDrive=$(df --output=target quickstart.sh | tail -n1)
mountedDrive=$(df --output=target "$DIR/quickstart.sh" | tail -n1)
totalDriveSpaceBytes=$(df -k --output=size "$mountedDrive" | tail -n1)
totalDriveSpaceMB=$(( totalDriveSpaceBytes / 1024 ))
if [ "$totalDriveSpaceMB" -lt "$REQUIRED_DRIVE_SPACE_MB" ]; then
Expand Down Expand Up @@ -347,8 +375,8 @@ function setup {

if [ "$OVERRIDE_VERSION_FILE" == false ] ; then
echo -e "\nGrab docker Versions"
wget -O versionFile $VERSION_FILE
export $(grep -v '^#' versionFile | xargs)
wget -O "$DIR/versionFile" $VERSION_FILE
export $(grep -v '^#' "$DIR/versionFile" | xargs)
else
echo -e "\n Using hardcoded version Info"
fi
Expand Down Expand Up @@ -378,7 +406,7 @@ function setup {
$PERMISSION_PREFIX docker pull $DOCKER_IMAGE_ORACLE

echo -e "\nDownload oracle docker-compose.yml"
wget -O docker-compose.yml $DOCKER_COMPOSE_ORACLE
wget -O "$DIR/docker-compose.yml" $DOCKER_COMPOSE_ORACLE

echo -e "\nUpdating block numbers in env file"
getAndUpdateBlockNumbers
Expand Down Expand Up @@ -724,10 +752,14 @@ function displayWarning {


# Go :)
stopCronTask
setPlatform
sanityChecks
parseArguments
setup
run
if [[ "$ENABLE_AUTO_UPDATE" == 1 ]]; then
addCronTask
fi
displayWarning
IFS=$OLDIFS