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

feat: add local dev setup script #1237

Merged
merged 9 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions misc/dev/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.PHONY: all local

all: local

local:
echo "Giving permissions to run script"
chmod u+x ./dev.sh
echo "Running local development setup"
@./dev.sh $$RESTORE_DIR $$BACKUP_DIR
77 changes: 77 additions & 0 deletions misc/dev/dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for later: add a --watch option to automatically reload based on FS changes.

# Constants and Configurations
TX_ARCHIVE_BINARY="github.com/gnolang/tx-archive/cmd@latest"
DELAY=5

# The restore source directory
restore_dir=$1

# The backup output directory
backup_dir=$2

# Set up the kill signal callback
teardown() {
echo "Stopping background processes..."
kill 0
}

# Set up the required tx-archive tool
install_tools() {
echo "Installing tx-archive binary"
if go install $TX_ARCHIVE_BINARY; then
echo "Installation successful"
else
echo "Failed to install the binary"
exit 1
fi
}

# Helper for checking the local exit code
check_exit_code() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Error: Process failed with exit code $exit_code"
teardown
fi
}

# Install the required tools
install_tools

# Pull in the latest changes from VC
cd ../..
git checkout master
git pull

# Clean out the blockchain data
cd gno.land && make clean fclean build install

# Start the gnoland node (fresh chain), and in parallel
# - start the restore service for transactions
# - start the backup service for transactions
(
echo "Starting Gno node..."
gnoland start
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for later: add the --in-memory if it exists, or create a tempdir?

check_exit_code
) &
(
# Sleep the restore until the node is fully loaded up
sleep $DELAY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a fast method to check readiness would be convenient. Today, @gfanton informed me about an event checker created by @thehowl in a pull request. It would be great to have a CLI option to call this.

echo "Starting restore..."
cmd restore -legacy -watch -input-path "$restore_dir"
check_exit_code
) &
(
# Sleep the restore until the node is fully loaded up
sleep $DELAY
echo "Starting backup..."
cmd backup -legacy -watch -overwrite -output-path "$backup_dir"
check_exit_code
) &

# Trap all kill signals
trap 'teardown' INT

# Wait for all background processes to finish
wait
Loading