Skip to content

Commit

Permalink
Migrating away from update.sh and run.sh
Browse files Browse the repository at this point in the history
Let us embrace docker compose.
Fixes filecoin-saturn#109, filecoin-saturn#125
  • Loading branch information
AnomalRoil committed Jan 11, 2023
1 parent 209e0ad commit df19399
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 60 deletions.
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: "3.8"
services:
saturn-node:
image: ghcr.io/filecoin-saturn/l1-node:${SATURN_NETWORK:-test}
container_name: saturn_node
restart: always
environment:
SATURN_NETWORK: "${SATURN_NETWORK:-test}"
FIL_WALLET_ADDRESS: "${FIL_WALLET_ADDRESS:?please make sure to set your FIL_WALLET_ADDRESS environment variable}"
NODE_OPERATOR_EMAIL: "${NODE_OPERATOR_EMAIL:?please make sure to set your NODE_OPERATOR_EMAIL environment variable}"
SPEEDTEST_SERVER_CONFIG: "${SPEEDTEST_SERVER_CONFIG}"
ulimits:
nofile:
soft: 65536
hard: 65536
ports:
- 80:80
- 443:443
network_mode: host
stop_signal: SIGTERM
stop_grace_period: 30m
labels:
com.centurylinklabs.watchtower.enable: true
com.centurylinklabs.watchtower.lifecycle.pre-update-timeout: 30
com.centurylinklabs.watchtower.lifecycle.post-update-timeout: 30
volumes:
- ${SATURN_HOME:-$HOME}/shared:/usr/src/app/shared

watchtower:
image: containrrr/watchtower
environment:
WATCHTOWER_POLL_INTERVAL: 10800
WATCHTOWER_LABEL_ENABLE: true
volumes:
- /var/run/docker.sock:/var/run/docker.sock

9 changes: 3 additions & 6 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

set -ex

: "${SATURN_NETWORK:=test}"
: "${SATURN_HOME:=$HOME}"

echo "Running Saturn $SATURN_NETWORK network L1 Node on $SATURN_HOME"
sudo docker rm -f saturn-node || true
sudo docker run --name saturn-node -it -d \
--restart=unless-stopped \
-v "$SATURN_HOME/shared:/usr/src/app/shared" \
-e "FIL_WALLET_ADDRESS=$FIL_WALLET_ADDRESS" \
-e "NODE_OPERATOR_EMAIL=$NODE_OPERATOR_EMAIL" \
-e "SPEEDTEST_SERVER_CONFIG=$SPEEDTEST_SERVER_CONFIG" \
-e "FIL_WALLET_ADDRESS=" \
-e "NODE_OPERATOR_EMAIL=" \
-e "SPEEDTEST_SERVER_CONFIG=" \
--network host \
--ulimit nofile=1000000 \
ghcr.io/filecoin-saturn/l1-node:$SATURN_NETWORK
94 changes: 40 additions & 54 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,53 @@ if pidof -o %PPID -x "update.sh" > /dev/null; then
exit
fi

update_target=$SATURN_HOME/update.sh

echo -n "$(date -u) Checking for auto-update script ($update_target) updates... "

if wget -O "$update_target.tmp" -T 10 -t 3 "https://raw.githubusercontent.com/filecoin-saturn/L1-node/main/update.sh" && [[ -s "$update_target.tmp" ]] && [ "$(stat -c %s "$update_target.tmp")" -ne "$(stat -c %s "$update_target")" ]
then
mv -f "$update_target.tmp" "$update_target"
chmod +x "$update_target"
echo "updated $update_target script successfully!"
exit
else
echo "$update_target script up to date"
rm -f "$update_target.tmp"
fi

run_target=$SATURN_HOME/run.sh

echo -n "$(date -u) Checking for run script ($run_target) updates... "

if wget -O "$run_target.tmp" -T 10 -t 3 "https://raw.githubusercontent.com/filecoin-saturn/L1-node/main/run.sh" && [[ -s "$run_target.tmp" ]] && [ "$(stat -c %s "$run_target.tmp")" -ne "$(stat -c %s "$run_target")" ]
then
mv -f "$run_target.tmp" "$run_target"
chmod +x "$run_target"
echo "updated $run_target script successfully!"
exit
else
echo "$run_target script up to date"
rm -f "$run_target.tmp"
fi

echo -n "$(date -u) Checking for Saturn $SATURN_NETWORK network L1 node updates... "

out=$(sudo docker pull ghcr.io/filecoin-saturn/l1-node:$SATURN_NETWORK)

if [[ $out != *"up to date"* ]]; then
compose_file=$SATURN_HOME/docker-compose.yml

echo -n "$(date -u) The auto-update script was deprecated to migrate to a docker compose setup."
echo -n "$(date -u) The run script was deprecated too."

if [ -f "$compose_file" ]; then
echo "We have migrated to a docker compose setup to reduce risks caused by these update and run scripts. You can delete these scripts and use the Docker Compose workflow now."
else
wget -O "$compose_file.tmp" -T 10 -t 3 "https://raw.githubusercontent.com/filecoin-saturn/L1-node/main/docker-compose.yml"
if [[ -s "$compose_file.tmp" ]];
then
mv -f "$compose_file.tmp" "$compose_file"
echo "Downloaded the docker compose file successfully!"
else
echo "Failed to download the docker compose file automagically. Please open a Github issue or migrate manually to the docker compose setup"
rm -f "$compose_file.tmp"
exit
fi

echo "Testing compatibility with our Docker Compose workflow"
sudo docker compose version
if [ $? -ne 0 ];
then
echo 'docker compose might not be supported by your setup, or you are still using an old docker-compose version';
exit
fi
echo "You have docker compose, proceeding."
echo -n "$(date -u) Pulling Saturn $SATURN_NETWORK network L1 node updates."
sudo docker compose -f $compose_file pull
echo "$(date -u) New Saturn $SATURN_NETWORK network L1 node version found!"

random_sleep="$(( RANDOM % 3600 ))"
random_sleep="$(( RANDOM % 2000 ))"
echo "$(date -u) Waiting for $random_sleep seconds..."
sleep "$random_sleep"

echo -n "$(date -u) Draining $SATURN_NETWORK network L1 node... "
sudo docker kill --signal=SIGTERM saturn-node >> /dev/null
sleep 900
echo "restarting...."
echo "restarting with docker compose now..."

sudo docker pull ghcr.io/filecoin-saturn/l1-node:$SATURN_NETWORK || true
sudo docker compose -f $compose_file pull
sudo docker stop saturn-node || true
sudo docker rm -f saturn-node || true
sudo docker run --name saturn-node -it -d \
--restart=unless-stopped \
-v "$SATURN_HOME/shared:/usr/src/app/shared" \
-e "FIL_WALLET_ADDRESS=$FIL_WALLET_ADDRESS" \
-e "NODE_OPERATOR_EMAIL=$NODE_OPERATOR_EMAIL" \
-e "SPEEDTEST_SERVER_CONFIG=$SPEEDTEST_SERVER_CONFIG" \
--network host \
--ulimit nofile=1000000 \
ghcr.io/filecoin-saturn/l1-node:$SATURN_NETWORK
sudo docker image prune -f

echo "Updated to latest version successfully!"
else
echo "Saturn $SATURN_NETWORK network L1 node up to date"
sudo docker compose -f $compose_file up -d
if [ $? -ne 0 ];
then
echo 'Error while launching the docker compose setup';
exit
fi
echo "Updated to the latest version successfully! You can now delete the run.sh and update.sh scripts."
fi

0 comments on commit df19399

Please sign in to comment.