-
Notifications
You must be signed in to change notification settings - Fork 8
chore: example for a snapshot node #89
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
env | ||
gnoland-data/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Snapshots node | ||
|
||
## How it's works | ||
|
||
1. Setup the environment variables and setup the variables for the [minio-client](https://min.io) with your S3 credentials | ||
|
||
``` sh | ||
cp env.example env | ||
``` | ||
|
||
2. Start the node | ||
|
||
By default, a snapshots will occur every 4 hours, and will upload it to S3 | ||
|
||
``` sh | ||
docker compose up -d | ||
``` | ||
|
||
## How to force a snapshot now | ||
|
||
``` sh | ||
docker compose exec snapshotter sh /scripts/snapshots.sh | ||
``` | ||
|
||
## TO-DOs | ||
|
||
[ ] Prune the node before uploading the snapshots |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: "gnoland-snapshot-node" | ||
|
||
services: | ||
gnoland: | ||
image: "ghcr.io/gnolang/gno/gnoland:chain-test4.3" | ||
entrypoint: ["/scripts/entrypoint.gnoland.sh"] | ||
ports: | ||
- 127.0.0.1:26657:26657 | ||
volumes: | ||
- ./scripts:/scripts | ||
- ./gnoland-data:/gnoroot/gnoland-data | ||
|
||
snapshotter: | ||
image: "docker:27.2.0-cli-alpine3.20" | ||
entrypoint: ["sh", "/scripts/entrypoint.snapshotter.sh"] | ||
env_file: "env" | ||
environment: | ||
CHAIN_ID: "test4" | ||
volumes: | ||
- "/var/run/docker.sock:/var/run/docker.sock:ro" | ||
- "./scripts:/scripts" | ||
- "./docker-compose.yml:/docker-compose.yml" | ||
- "./env:/env" | ||
- "./gnoland-data:/gnoroot/gnoland-data:ro" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
MC_ENDPOINT="" | ||
MC_ACCESS_KEY="" | ||
MC_SECRET_KEY="" | ||
MC_BUCKET="" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env sh | ||
|
||
LOG_LEVEL=${LOG_LEVEL:-"info"} | ||
|
||
MONIKER=${MONIKER:-"gnode"} | ||
P2P_LADDR=${P2P_LADDR:-"tcp://0.0.0.0:26656"} | ||
RPC_LADDR=${RPC_LADDR:-"tcp://0.0.0.0:26657"} | ||
|
||
CHAIN_ID=${CHAIN_ID:-"dev"} | ||
albttx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
gnoland config init | ||
|
||
gnoland config set rpc.laddr "${RPC_LADDR}" | ||
gnoland config set p2p.laddr "${P2P_LADDR}" | ||
|
||
exec gnoland start --lazy --genesis="./gnoland-data/genesis.json" --log-level=${LOG_LEVEL} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env sh | ||
|
||
apk add --no-cache curl jq lz4 minio-client | ||
|
||
export DAEMON_HOME="/gnoroot/gnoland-data" | ||
|
||
[ -z "$MC_ENDPOINT" ] && echo "MC_ENDPOINT is not set, skip snapshot" && exit 1 | ||
[ -z "$MC_ACCESS_KEY" ] && echo "MC_ACCESS_KEY is not set, skip snapshot" && exit 1 | ||
[ -z "$MC_SECRET_KEY" ] && echo "MC_SECRET_KEY is not set, skip snapshot" && exit 1 | ||
|
||
mcli alias set s3 ${MC_ENDPOINT} ${MC_ACCESS_KEY} ${MC_SECRET_KEY} | ||
|
||
# exec snapshots script every 4 hours | ||
echo "0 */4 * * * sh /scripts/snapshots.sh" > /etc/crontabs/root | ||
crontab /etc/crontabs/root | ||
|
||
exec crond -f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env sh | ||
|
||
DAEMON_HOME="/gnoroot/gnoland-data" | ||
|
||
HEIGHT=$(curl -s gnoland:26657/status | jq -r '.result.sync_info.latest_block_height') | ||
echo "[INFO] Snapshotting at height: ${HEIGHT}" | ||
|
||
echo "[INFO] Stopping gnoland..." | ||
docker compose stop gnoland | ||
|
||
FILE="gnoland-${HEIGHT}-${CHAIN_ID}.tar.lz4" | ||
|
||
tar cvf - -C ${DAEMON_HOME} wal db | lz4 > $FILE | ||
|
||
mcli cp --attr x-amz-acl=public-read --tags="type=snapshot" ${FILE} "s3/${MC_BUCKET}/${CHAIN_ID}/${FILE}"; echo | ||
|
||
rm -vf ${FILE} | ||
|
||
echo "[INFO] Starting gnoland ..." | ||
docker compose start gnoland |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.