-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(misc/loop): Setup the portal loop infra
- Loading branch information
Showing
9 changed files
with
296 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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,26 @@ | ||
# The portal loop :infinity: | ||
|
||
## What is it ? | ||
|
||
It's a Gnoland node that aim to run with always the latest version of gno and never loose transactions history. | ||
|
||
For more information, see issue on github [gnolang/gno#1239](https://github.com/gnolang/gno/issues/1239) | ||
|
||
|
||
## How to use | ||
|
||
Start the loop with: | ||
|
||
``` sh | ||
$ docker compose up -d | ||
``` | ||
|
||
The `snapshotter` container will exec the script [switch.sh](./scripts/switch.sh) every day at 10am (defined in the docker image). | ||
|
||
This script is doing: | ||
|
||
- Pull the new docker image [ghcr.io/gnolang/gno] | ||
- Backup the txs using [gnolang/tx-archive](https://github.com/gnolang/tx-archive) | ||
- Start a new docker container with the backups files | ||
- Changing the proxy (traefik) to redirect to the new portal loop | ||
- Stop the previous loop |
This file contains 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,33 @@ | ||
version: "3" | ||
services: | ||
traefik: | ||
image: "traefik:v2.10" | ||
network_mode: host | ||
container_name: "traefik" | ||
command: | ||
- "--api.insecure=true" | ||
- "--providers.file=true" | ||
- "--providers.file.watch=true" | ||
- "--providers.file.directory=/etc/traefik/configs" | ||
- "--entrypoints.web.address=:80" | ||
ports: | ||
- "80:80" | ||
- "8080:8080" | ||
volumes: | ||
- ./traefik:/etc/traefik/configs | ||
|
||
snapshotter: | ||
build: | ||
dockerfile: ./snapshotter/Dockerfile | ||
command: ["/usr/sbin/crond", "-l", "2", "-f"] | ||
working_dir: /app | ||
network_mode: host | ||
volumes: | ||
- ./scripts:/scripts | ||
- ./backups:/backups | ||
- ./traefik:/etc/traefik/configs | ||
- "/var/run/docker.sock:/var/run/docker.sock:ro" | ||
environment: | ||
HOST_PWD: $PWD | ||
extra_hosts: | ||
- gno.land:127.0.0.1 |
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains 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 @@ | ||
#!/usr/bin/env sh | ||
|
||
MONIKER=${MONIKER:-"gnode"} | ||
P2P_LADDR=${P2P_LADDR:-"tcp://0.0.0.0:26656"} | ||
RPC_LADDR=${RPC_LADDR:-"tcp://0.0.0.0:26657"} | ||
|
||
GENESIS_BACKUP_FILE=${GENESIS_BACKUP_FILE:-""} | ||
|
||
SEEDS=${SEEDS:-""} | ||
PERSISTENT_PEERS=${PERSISTENT_PEERS:-""} | ||
|
||
gnoland start \ | ||
--skip-start=true \ | ||
--skip-failing-genesis-txs \ | ||
--genesis-txs-file "/${GENESIS_BACKUP_FILE}" | ||
|
||
sed -i "s#^moniker = \".*\"#moniker = \"${MONIKER}\"#" ./testdir/config/config.toml | ||
sed -i "s#^laddr = \".*:26656\"#laddr = \"${P2P_LADDR}\"#" ./testdir/config/config.toml | ||
sed -i "s#^laddr = \".*:26657\"#laddr = \"${RPC_LADDR}\"#" ./testdir/config/config.toml | ||
|
||
sed -i "s#^seeds = \".*\"#seeds = \"${SEEDS}\"#" ./testdir/config/config.toml | ||
sed -i "s#^persistent_peers = \".*\"#persistent_peers = \"${PERSISTENT_PEERS}\"#" ./testdir/config/config.toml | ||
|
||
exec gnoland start --skip-failing-genesis-txs |
This file contains 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,75 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -e | ||
|
||
# This script goal is to: | ||
# 1. Snapshot txs for current running node | ||
# 2. Start a new node with this tx in genesis file | ||
# 3. switch traefik node | ||
|
||
|
||
BACKUP_DIR="/backups" | ||
|
||
NOW=$(date +'%Y-%m-%d_%s') | ||
BACKUP_FILE="${BACKUP_DIR}/backup_${NOW}.jsonl" | ||
BACKUP_LEGACY_FILE=$(echo ${BACKUP_FILE} | sed 's/.jsonl$/-legacy.jsonl/') | ||
|
||
HOST_PWD="${HOST_PWD:=$(pwd)}" | ||
|
||
TX_ARCHIVE_CMD=${TX_ARCHIVE_CMD:-"tx-archive"} | ||
|
||
CONTAINER_NAME="gno-${NOW}" | ||
|
||
# TODO: SET THE CURRENT PORTAL LOOP in read only mode | ||
|
||
# Get latest version of gno | ||
docker pull ghcr.io/gnolang/gno | ||
|
||
# If there is no portal loop running, we start one | ||
if docker ps --format json | jq '.Labels' | grep -q "the-portal-loop"; then | ||
${TX_ARCHIVE_CMD} backup \ | ||
--overwrite=true \ | ||
--remote "gno.land:80" \ | ||
--from-block 1 \ | ||
--output-path="${BACKUP_FILE}" | ||
|
||
cat ${BACKUP_FILE} | jq -c -M '.tx' > ${BACKUP_LEGACY_FILE} | ||
fi | ||
|
||
docker volume create ${CONTAINER_NAME} | ||
|
||
docker run -it \ | ||
-d \ | ||
--name "$CONTAINER_NAME" \ | ||
-v ${HOST_PWD}/scripts:/scripts \ | ||
-v ${HOST_PWD}/backups:/backups \ | ||
-v ${CONTAINER_NAME}:/opt/gno/src/testdir \ | ||
-p 26656 \ | ||
-p 26657 \ | ||
-e MONIKER="the-portal-loop" \ | ||
-e GENESIS_BACKUP_FILE="${BACKUP_LEGACY_FILE}" \ | ||
--label "the-portal-loop=${CONTAINER_NAME}" \ | ||
--entrypoint /scripts/start.sh \ | ||
ghcr.io/gnolang/gno | ||
|
||
sleep 5 | ||
|
||
PORTS=$(docker inspect $CONTAINER_NAME | jq '.[0].NetworkSettings.Ports') | ||
|
||
RPC_PORT=$(echo $PORTS | jq -r '."26657/tcp"[0].HostPort') | ||
|
||
echo "New instance is running on: localhost:${RPC_PORT}" | ||
|
||
# wait for RPC to be up | ||
curl -s --retry 10 --retry-delay 5 --retry-all-errors -o /dev/null "localhost:${RPC_PORT}/status" | ||
|
||
|
||
# NOTE: Could be good to wait 5 blocks | ||
|
||
# Update traefik url | ||
sed -i -E "s#localhost:[0-9]+#localhost:${RPC_PORT}#" /etc/traefik/configs/gno.yml | ||
|
||
# Delete previous container | ||
docker rm -f $(docker ps --format json --filter "label=the-portal-loop" | jq -r '.ID' | tail -n +2) | ||
|
||
docker volume prune -f |
This file contains 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,10 @@ | ||
FROM ghcr.io/gnolang/tx-archive as archive-bin | ||
|
||
FROM docker | ||
|
||
RUN apk add bash curl jq | ||
|
||
COPY --from=archive-bin /tx-archive /usr/local/bin/tx-archive | ||
|
||
# Every day at 10am | ||
RUN echo "* 10 * * * sh /scripts/switch.sh" > /var/spool/cron/crontabs/root |
This file contains 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,15 @@ | ||
--- | ||
http: | ||
routers: | ||
gno-portal-loop: | ||
service: gno-portal-loop | ||
# tls: "true" | ||
rule: "Host(`gno.land`)" | ||
entrypoints: "web" | ||
middlewares: [] | ||
|
||
services: | ||
gno-portal-loop: | ||
loadBalancer: | ||
servers: | ||
- url: "http://localhost:26657" |