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

chore(misc/loop): Setup the portal loop infra #1400

Merged
merged 116 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
716d261
chore(misc/loop): Setup the portal loop infra
albttx Nov 28, 2023
ee5b463
chore: portal-loop add gnoweb
albttx Dec 5, 2023
9640c16
chore: add Makefile and improve readme
albttx Dec 5, 2023
1fb7124
chore: auto read-only mode for portal loop
albttx Dec 5, 2023
11a6d58
chore: improve readme
albttx Dec 6, 2023
04416db
fix: read-only mode
albttx Dec 6, 2023
3b8f3d3
chore: wait 5 blocks
albttx Dec 6, 2023
3379dc4
Merge branch 'master' of github.com:gnolang/gno into ops/portal-loop
albttx Dec 6, 2023
d644fff
chore: rpc on localhost
albttx Dec 6, 2023
9c90185
chore: fix docker volume prune
albttx Dec 6, 2023
041e196
fix: inverse read-only sed
albttx Dec 7, 2023
c664c54
fix: traefik entrypoint on localhost
albttx Dec 7, 2023
83a932a
chore: don't start a new portal portal loop if no update
albttx Dec 7, 2023
c1c0ca7
Update misc/loop/README.md
albttx Dec 7, 2023
cc1fc9d
fix: docker.stop
albttx Dec 7, 2023
1f13bbc
chore: default whitelist empty
albttx Dec 7, 2023
ea05eb4
chore: edit url for gnoteam and gno.local
albttx Dec 12, 2023
f7e77f4
chore: add https
albttx Dec 12, 2023
7c85b82
chore: portal loop url
albttx Dec 12, 2023
dfcc56b
chore: redirect http to https
albttx Dec 12, 2023
9740982
chore: update
albttx Dec 13, 2023
1db5e94
chore: fix portal loop, update urls
albttx Dec 15, 2023
7f01a37
chore: set gnoweb help flag
albttx Dec 15, 2023
0fc6e2b
fix(gnoweb): FaucetURL correct endpoint
albttx Dec 16, 2023
e6b0cd1
wip
albttx Dec 16, 2023
b4dd017
no git backups
albttx Dec 22, 2023
cd9e9fd
chore: portal loop in go
albttx Dec 22, 2023
067cae4
Merge branch 'master' of github.com:gnolang/gno into ops/portal-loop
albttx Dec 22, 2023
23d3aee
chore: portal loop in go
albttx Dec 22, 2023
68191ac
chore: gitignore backups
albttx Dec 22, 2023
e302c3b
chore: wait 5 blocks
albttx Dec 22, 2023
468b7b5
chore: remove flag views-dir
albttx Dec 22, 2023
83459e2
chore: don't start portal if no new docker image
albttx Dec 22, 2023
2abd82b
fix: api break
albttx Jan 15, 2024
4456dfe
chore: add watchtower to update gnoweb
albttx Jan 15, 2024
47e7712
chore: gitignore letsencrypt
albttx Jan 16, 2024
7851113
fix: @moul suggestions
albttx Jan 16, 2024
0232643
Merge branch 'master' of github.com:gnolang/gno into ops/portal-loop
albttx Jan 16, 2024
92c3240
chore: update portalloopd as a cli
albttx Jan 16, 2024
ea306e3
chore: append official genesis txs
albttx Jan 17, 2024
1936f7e
chore: watchtower ignore build
albttx Jan 17, 2024
ad3f52d
chore: update url to gno.land
albttx Jan 17, 2024
a9afce5
chore: watctower only watch enable images
albttx Jan 19, 2024
f99920b
chore: add logs
albttx Jan 19, 2024
429b4db
chore: update portal loop check every 2m
albttx Jan 19, 2024
acb291b
chore: setup chain-id to portal-loop
albttx Jan 19, 2024
9886c06
wip
albttx Jan 23, 2024
cccb87a
Merge branch 'master' of github.com:gnolang/gno into ops/portal-loop
albttx Jan 23, 2024
e4ff190
chore: fix start.sh regex
albttx Jan 24, 2024
469638c
fix(gno.land/pkg/gnoclient): Signer takes chainID
albttx Jan 24, 2024
9d74a89
chore: cmd/{portalloopd,autocounterd}
albttx Jan 24, 2024
13b2c1e
remove binary
albttx Jan 24, 2024
da4389f
chore: cmd/autocounterd
albttx Jan 24, 2024
6027cc3
chore: fix dockerfile
albttx Jan 24, 2024
fff3c91
chore(ci): add portal loop workflow
albttx Jan 25, 2024
e9a5d4a
fix(ci): add matrix
albttx Jan 25, 2024
34ba807
chore: meta id uniq
albttx Jan 25, 2024
0a40091
chore: build in misc/loop
albttx Jan 25, 2024
9f7bb82
chore: use context
albttx Jan 25, 2024
1ec3944
chore: update
albttx Jan 25, 2024
88426e2
chore: update gnolang/gno
albttx Jan 25, 2024
ad2edfe
chore(ci): update build image
albttx Jan 26, 2024
a1b55a0
chore: debug log ls
albttx Jan 26, 2024
b66e7f4
chore: unignore portalloopd from git
albttx Jan 26, 2024
88155a3
chore: add gh permission
albttx Jan 26, 2024
aa95c60
chore: remove debug log
albttx Jan 26, 2024
3ba250f
chore: fix printf error
albttx Jan 26, 2024
86c72a8
chore: error log
albttx Jan 26, 2024
2c2b198
chore: fix error msg
albttx Jan 26, 2024
414cf6d
chore: remove network_mode: host
albttx Jan 26, 2024
1c101a8
chore: update rpcURL
albttx Jan 26, 2024
7c0da27
chore: update ci
albttx Jan 26, 2024
025877f
chore: increment interval as a flag
albttx Jan 29, 2024
35139f4
chore: fix name
albttx Jan 29, 2024
63ec207
chore: update image path
albttx Jan 29, 2024
fb0da48
Merge branch 'master' of github.com:gnolang/gno into ops/portal-loop
albttx Jan 30, 2024
50f87d5
chore: remove useless
albttx Feb 1, 2024
5df0051
chore: portal loop
albttx Feb 1, 2024
53b3c21
chore: update docker compose
albttx Feb 1, 2024
b2a5037
fix: typo
albttx Feb 16, 2024
bfc0596
fix: docker compose expose port 81
albttx Feb 16, 2024
08d2e07
chore: remove autocounterd
albttx Feb 16, 2024
4aaa427
fix: help-remote url
albttx Feb 16, 2024
0f83d7d
chore: change private port
albttx Feb 19, 2024
921dbf8
chore: remove start-faucet script
albttx Feb 20, 2024
790c0cc
chore: refactoring
albttx Feb 20, 2024
a055462
chore: go mod tidy
albttx Feb 20, 2024
5866031
Merge branch 'master' of github.com:gnolang/gno into ops/portal-loop
albttx Feb 20, 2024
d18b1e3
chore: fix portalloop ci
albttx Feb 23, 2024
ebf4012
chore: use 26657 as port
albttx Feb 23, 2024
45adae6
Merge branch 'master' of github.com:gnolang/gno into ops/portal-loop
albttx Mar 5, 2024
2161fc4
fix: typo
albttx Mar 5, 2024
1f55c08
fix: load txs with jsonl
albttx Mar 5, 2024
4ecdbc1
chore(ci): remove workflow paths
albttx Mar 5, 2024
6e85a94
chore: update makefile
albttx Mar 5, 2024
7261e40
chore: add workflow dispatch
albttx Mar 5, 2024
f3aa0b0
chore(ci): reset
albttx Mar 5, 2024
d2c925b
chore(misc/loop): gnoweb production add analytics
albttx Mar 5, 2024
31ffac8
Merge branch 'master' into ops/portal-loop
albttx Mar 7, 2024
4d8081f
chore(make): disable cgo, reorganise makefiles (#1715)
thehowl Mar 7, 2024
50218d7
feat: allow disabling consensus WAL (#1723)
deelawn Mar 8, 2024
b4ccfe1
feat(txtar): handle quote for gnokey (#1745)
gfanton Mar 11, 2024
764364a
chore(gnoweb): update link to the docs (#1753)
leohhhn Mar 11, 2024
4c9d10c
feat: add `gnoland config` command suite (#1605)
zivkovicmilos Mar 12, 2024
4a911f5
chore(gnoweb/docs): better website connectivity (#1763)
leohhhn Mar 13, 2024
3b4759b
refactor(tm2): remove pkg/maths in favour of min/max (#1746)
thehowl Mar 13, 2024
db648fe
feat(gnodev): add more configuration flags for server usage (#1622)
gfanton Mar 13, 2024
9c3e97d
feat(p/ufmt): add `ufmt.Errorf` (#1767)
notJoon Mar 13, 2024
d1399ec
feat: swap legacy faucet implementation (#1614)
zivkovicmilos Mar 14, 2024
43c2498
chore(p/math_eval, gnovm): simplify `errors.New` + `Sprintf` with `Er…
notJoon Mar 14, 2024
fb44c1e
docs: Update creating-grc20.md (#1771)
kazai777 Mar 14, 2024
4208e61
docs: update `write-simple-dapp.md` (#1770)
kazai777 Mar 14, 2024
d13bd1d
fix(docs): update blog link (#1774)
leohhhn Mar 14, 2024
c562831
chore: add gnofaucet
albttx Mar 15, 2024
6014b15
Merge branch 'master' of github.com:gnolang/gno into ops/portal-loop
albttx Mar 18, 2024
a76fc87
Merge branch 'master' into ops/portal-loop
moul Mar 18, 2024
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
48 changes: 48 additions & 0 deletions .github/workflows/portal-loop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: portal-loop

on:
push:
paths:
- misc/loop
- .github/workflows/portal-loop.yml
branches:
- "master"
- "ops/portal-loop"
tags:
- "v*"

permissions:
contents: read
packages: write

jobs:
portal-loop:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker metadata portalloopd
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}/portalloopd
tags: |
type=raw,value=latest
type=semver,pattern=v{{version}}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: ./misc/loop
target: portalloopd
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 3 additions & 0 deletions misc/loop/.gitignore
thehowl marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/portalloopd
/backups
/traefik/letsencrypt
19 changes: 19 additions & 0 deletions misc/loop/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:alpine AS builder

COPY . /go/src/github.com/gnolang/gno/misc/loop

WORKDIR /go/src/github.com/gnolang/gno/misc/loop

RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go build -o /build/portalloopd ./cmd

# Final image for portalloopd
FROM docker AS portalloopd

RUN apk add bash curl jq

COPY --from=builder /build/portalloopd /usr/bin/portalloopd

ENTRYPOINT [ "/usr/bin/portalloopd" ]
CMD [ "serve" ]
52 changes: 15 additions & 37 deletions misc/loop/Makefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,22 @@
# The startup delay (waits until the node is "ready")
DELAY ?= 10 # seconds
# The temporary backup file for transactions
BACKUP_FILE ?= $(abspath ./txs_backup.log)
# The entire txs history across all iterations
HISTORY_OUTPUT := $(abspath ./txs_history.log)
all: docker.start

# The gnoland binary
gnoland_bin := go run github.com/gnolang/gno/gno.land/cmd/gnoland
# The tx archive binary
tx_bin := go run github.com/gnolang/tx-archive/cmd
docker.start: # Start the portal loop
docker compose up -d

# The relative gno.land directory
gnoland_dir := $(abspath ../../gno.land)
docker.stop: # Stop the portal loop
docker compose down
docker rm -f $(docker ps -aq --filter "label=the-portal-loop")
albttx marked this conversation as resolved.
Show resolved Hide resolved

all: loop
docker.build: # (re)Build snapshotter image
docker compose build

start.gnoland:
cd $(gnoland_dir) && $(gnoland_bin) start -skip-failing-genesis-txs -genesis-txs-file $(HISTORY_OUTPUT)
clean.gnoland:
make -C $(gnoland_dir) fclean
.PHONY: start.gnoland clean.gnoland
docker.pull: # Pull new images to update versions
docker compose pull

# Starts the backup service
# and backs up transactions into a file
# that is wiped on every loop
tx.backup:
sleep $(DELAY)
$(tx_bin) backup -legacy -watch -overwrite -output-path "$(BACKUP_FILE)"
.PHONY: tx.backup
portalloopd.bash: # Get a bash command inside of the portalloopd container
docker compose exec portalloopd bash

# Saves the history from previous iterations into
# a temporary transactions log
save.history:
@test -e $(BACKUP_FILE) || (echo "No existing backup file not found: '$(BACKUP_FILE)'"; exit 1)
cat $(BACKUP_FILE) >> $(HISTORY_OUTPUT)
.PHONY: save.history
switch: portalloopd.switch

loop: clean.gnoland
# backup history, if needed
$(MAKE) save.history || true
# run our dev loop
./run_loop.sh
.PHONY: loop
portalloopd.switch: # Force switch the portal loop with latest image
docker compose exec portalloopd switch
42 changes: 42 additions & 0 deletions misc/loop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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

# or using the Makefile

$ make
albttx marked this conversation as resolved.
Show resolved Hide resolved
```

The [`portalloopd`](./cmd/portalloopd) binary is starting inside of the docker container `portalloopd`

This script is doing:

- Setup the current portal-loop in read only mode
- Pull the latest version of [ghcr.io/gnolang/gno]()
- Backup the txs using [gnolang/tx-archive](https://github.com/gnolang/tx-archive)
albttx marked this conversation as resolved.
Show resolved Hide resolved
- Start a new docker container with the backups files
- Changing the proxy (traefik) to redirect to the new portal loop
- Unlock read only mode
- Stop the previous loop

### Makefile helper

You can find a [Makefile](./Makefile) to help you interact with the portal loop

- Force switch of the portal loop with a new version

```bash
make portalloopd.switch
```
Empty file added misc/loop/backups/.keep
Empty file.
85 changes: 85 additions & 0 deletions misc/loop/cmd/cmd_backup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package main

import (
"context"
"flag"
"os"

"github.com/docker/docker/client"
"github.com/gnolang/gno/tm2/pkg/commands"
)

type backupCfg struct {
rpcAddr string
traefikGnoFile string
backupDir string
hostPWD string
}

func (c *backupCfg) RegisterFlags(fs *flag.FlagSet) {
if os.Getenv("HOST_PWD") == "" {
os.Setenv("HOST_PWD", os.Getenv("PWD"))
}

if os.Getenv("BACKUP_DIR") == "" {
os.Setenv("BACKUP_DIR", "./backups")
}

if os.Getenv("RPC_URL") == "" {
os.Setenv("RPC_URL", "http://rpc.portal.gno.local:26657")
}

if os.Getenv("PROM_ADDR") == "" {
os.Setenv("PROM_ADDR", ":9090")
}

if os.Getenv("TRAEFIK_GNO_FILE") == "" {
os.Setenv("TRAEFIK_GNO_FILE", "./traefik/gno.yml")
}

fs.StringVar(&c.rpcAddr, "rpc", os.Getenv("RPC_URL"), "tendermint rpc url")
fs.StringVar(&c.traefikGnoFile, "traefik-gno-file", os.Getenv("TRAEFIK_GNO_FILE"), "traefik gno file")
fs.StringVar(&c.backupDir, "backup-dir", os.Getenv("BACKUP_DIR"), "backup directory")
fs.StringVar(&c.hostPWD, "pwd", os.Getenv("HOST_PWD"), "host pwd (for docker usage)")
}

func newBackupCmd(io commands.IO) *commands.Command {
cfg := &backupCfg{}

return commands.NewCommand(
commands.Metadata{
Name: "backup",
ShortUsage: "backup [flags]",
},
cfg,
func(ctx context.Context, _ []string) error {
return execBackup(ctx, cfg)
},
)
}

func execBackup(ctx context.Context, cfg *backupCfg) error {
dockerClient, err := client.NewEnvClient()
if err != nil {
return err
}

portalLoop := &snapshotter{}

portalLoop, err = NewSnapshotter(dockerClient, config{
backupDir: cfg.backupDir,
rpcAddr: cfg.rpcAddr,
hostPWD: cfg.hostPWD,
traefikGnoFile: cfg.traefikGnoFile,
})
if err != nil {
return err
}

err = StartPortalLoop(ctx, portalLoop, false)
if err != nil {
return err
}

return portalLoop.backupTXs(ctx, portalLoop.url)
}
116 changes: 116 additions & 0 deletions misc/loop/cmd/cmd_serve.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package main

import (
"context"
"flag"
"net/http"
"os"
"time"

"github.com/docker/docker/client"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
)

type serveCfg struct {
rpcAddr string
traefikGnoFile string
backupDir string
hostPWD string
}

type serveService struct {
cfg serveCfg

// TODO(albttx): put getter on it with RMutex
portalLoop *snapshotter

portalLoopURL string
}

func (c *serveCfg) RegisterFlags(fs *flag.FlagSet) {
if os.Getenv("HOST_PWD") == "" {
os.Setenv("HOST_PWD", os.Getenv("PWD"))
}

if os.Getenv("BACKUP_DIR") == "" {
os.Setenv("BACKUP_DIR", "./backups")
}

if os.Getenv("RPC_URL") == "" {
os.Setenv("RPC_URL", "http://rpc.portal.gno.local:26657")
}

if os.Getenv("PROM_ADDR") == "" {
os.Setenv("PROM_ADDR", ":9090")
}

if os.Getenv("TRAEFIK_GNO_FILE") == "" {
os.Setenv("TRAEFIK_GNO_FILE", "./traefik/gno.yml")
}

fs.StringVar(&c.rpcAddr, "rpc", os.Getenv("RPC_URL"), "tendermint rpc url")
fs.StringVar(&c.traefikGnoFile, "traefik-gno-file", os.Getenv("TRAEFIK_GNO_FILE"), "traefik gno file")
fs.StringVar(&c.backupDir, "backup-dir", os.Getenv("BACKUP_DIR"), "backup directory")
fs.StringVar(&c.hostPWD, "pwd", os.Getenv("HOST_PWD"), "host pwd (for docker usage)")
thehowl marked this conversation as resolved.
Show resolved Hide resolved
}

func newServeCmd(io commands.IO) *commands.Command {
cfg := &serveCfg{}

return commands.NewCommand(
commands.Metadata{
Name: "serve",
ShortUsage: "serve [flags]",
},
cfg,
func(ctx context.Context, args []string) error {
return execServe(ctx, cfg, args)
},
)
}

func execServe(ctx context.Context, cfg *serveCfg, args []string) error {
dockerClient, err := client.NewEnvClient()
if err != nil {
return err
}

portalLoop := &snapshotter{}

// Serve monitoring
go func() {
s := &monitoringService{
portalLoop: portalLoop,
}

for portalLoop.url == "" {
time.Sleep(time.Second * 1)
}

go s.recordMetrics()

http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(os.Getenv("PROM_ADDR"), nil)
}()

// the loop
for {
portalLoop, err = NewSnapshotter(dockerClient, config{
backupDir: cfg.backupDir,
rpcAddr: cfg.rpcAddr,
hostPWD: cfg.hostPWD,
traefikGnoFile: cfg.traefikGnoFile,
})
if err != nil {
return err
}

err = StartPortalLoop(ctx, portalLoop, false)
if err != nil {
logrus.WithError(err).Error()
}
time.Sleep(time.Second * 120)
}
}
Loading
Loading