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

fix(misc/loop): use gnolang images, use gnoland config, more misc #1804

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions misc/loop/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
portalloopd
backups
traefik/letsencrypt
13 changes: 13 additions & 0 deletions misc/loop/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### DEVELOPMENT & PRODUCTION ###

# faucet mnemonic
FAUCET_MNEMONIC=
# Value for --captcha-secret in gnofaucet command
CAPTCHA_SECRET_KEY=

### PRODUCTION ONLY ###

# autocounterd mnmenonic
COUNTER_MNEMONIC=
# API token for watchtower
WATCHTOWER_HTTP_API_TOKEN=mytoken
1 change: 1 addition & 0 deletions misc/loop/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/portalloopd
/backups
/traefik/letsencrypt
/.env
31 changes: 9 additions & 22 deletions misc/loop/cmd/cmd_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,20 @@ type backupCfg struct {
traefikGnoFile string
backupDir string
hostPWD string
promAddr 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")
wd, err := os.Getwd()
if err != nil {
panic(err)
}

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)")
fs.StringVar(&c.rpcAddr, "rpc-url", "http://rpc.portal.gno.local:26657", "tendermint rpc url")
fs.StringVar(&c.traefikGnoFile, "traefik-gno-file", "./traefik/gno.yml", "traefik gno file")
fs.StringVar(&c.backupDir, "backup-dir", "./backups", "backup directory")
fs.StringVar(&c.hostPWD, "host-pwd", wd, "host pwd (for docker usage)")
fs.StringVar(&c.promAddr, "prom-addr", ":9090", "listening address for prometheus exporter")
}

func newBackupCmd(io commands.IO) *commands.Command {
Expand Down
37 changes: 12 additions & 25 deletions misc/loop/cmd/cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type serveCfg struct {
traefikGnoFile string
backupDir string
hostPWD string
promAddr string
}

type serveService struct {
Expand All @@ -30,33 +31,19 @@ type serveService struct {
}

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")
wd, err := os.Getwd()
if err != nil {
panic(err)
}

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)")
fs.StringVar(&c.rpcAddr, "rpc-url", "http://rpc.portal.gno.local:26657", "tendermint rpc url")
fs.StringVar(&c.traefikGnoFile, "traefik-gno-file", "./traefik/gno.yml", "traefik gno file")
fs.StringVar(&c.backupDir, "backup-dir", "./backups", "backup directory")
fs.StringVar(&c.hostPWD, "host-pwd", wd, "host pwd (for docker usage)")
fs.StringVar(&c.promAddr, "prom-addr", ":9090", "listening address for prometheus exporter")
}

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

return commands.NewCommand(
Expand All @@ -71,7 +58,7 @@ func newServeCmd(io commands.IO) *commands.Command {
)
}

func execServe(ctx context.Context, cfg *serveCfg, args []string) error {
func execServe(ctx context.Context, cfg *serveCfg, _ []string) error {
dockerClient, err := client.NewEnvClient()
if err != nil {
return err
Expand All @@ -92,7 +79,7 @@ func execServe(ctx context.Context, cfg *serveCfg, args []string) error {
go s.recordMetrics()

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

// the loop
Expand Down
33 changes: 10 additions & 23 deletions misc/loop/cmd/cmd_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,23 @@ type switchCfg struct {
traefikGnoFile string
backupDir string
hostPWD string
promAddr string
}

func (c *switchCfg) 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")
wd, err := os.Getwd()
if err != nil {
panic(err)
}

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)")
fs.StringVar(&c.rpcAddr, "rpc-url", "http://rpc.portal.gno.local:26657", "tendermint rpc url")
fs.StringVar(&c.traefikGnoFile, "traefik-gno-file", "./traefik/gno.yml", "traefik gno file")
fs.StringVar(&c.backupDir, "backup-dir", "./backups", "backup directory")
fs.StringVar(&c.hostPWD, "host-pwd", wd, "host pwd (for docker usage)")
fs.StringVar(&c.promAddr, "prom-addr", ":9090", "listening address for prometheus exporter")
}

func newSwitchCmd(io commands.IO) *commands.Command {
func newSwitchCmd(_ commands.IO) *commands.Command {
cfg := &switchCfg{}

return commands.NewCommand(
Expand Down
4 changes: 4 additions & 0 deletions misc/loop/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/peterbourgon/ff/v3"
)

type service struct {
Expand All @@ -22,6 +23,9 @@ func main() {
Name: "portalloopd",
ShortUsage: "<subcommand> [flags] [<arg>...]",
LongHelp: "Portalloop commands interactions",
Options: []ff.Option{
ff.WithEnvVars(),
},
},
commands.NewEmptyConfig(),
commands.HelpExec,
Expand Down
File renamed without changes.
11 changes: 2 additions & 9 deletions misc/loop/docker-compose.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ services:
gnoweb:
image: ghcr.io/gnolang/gno/gnoweb-slim
restart: unless-stopped
env_file: ".env"
entrypoint:
- gnoweb
- --bind=0.0.0.0:8888
Expand Down Expand Up @@ -79,10 +78,6 @@ services:
- "--num-accounts=1"
- "--remote=http://traefik:26657"
- "--captcha-secret=${CAPTCHA_SECRET_KEY}"
env_file: ".env"
# environment:
# from .env
# - RECAPTCHA_SECRET_KEY
labels:
com.centurylinklabs.watchtower.enable: "true"
traefik.enable: "true"
Expand All @@ -95,8 +90,7 @@ services:
traefik.http.middlewares.gnofaucet-ratelimit.ratelimit.period: "1m"

portalloopd:
# image: ghcr.io/gnolang/gno/portalloopd
image: ghcr.io/albttx/gno/portalloopd
image: ghcr.io/gnolang/gno/portalloopd
restart: unless-stopped
volumes:
- ./scripts:/scripts
Expand All @@ -119,9 +113,8 @@ services:
- "com.centurylinklabs.watchtower.enable=true"

autocounterd:
image: ghcr.io/albttx/gno/autocounterd
image: ghcr.io/gnolang/gno/autocounterd
restart: unless-stopped
env_file: ".env"
command:
- "start"
- "--mnemonic=${COUNTER_MNEMONIC}"
Expand Down
6 changes: 2 additions & 4 deletions misc/loop/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ services:
- "--listen-address=0.0.0.0:5050"
- "--chain-id=portal-loop"
# - "--is-behind-proxy=true"
- "--mnemonic=${MNEMONIC}"
- "--mnemonic=${FAUCET_MNEMONIC}"
# - "--num-accounts=1"
- "--remote=http://traefik:26657"
environment:
# from .env
- RECAPTCHA_SECRET_KEY
- "--captcha-secret=${CAPTCHA_SECRET_KEY}"

portalloopd:
build:
Expand Down
20 changes: 10 additions & 10 deletions misc/loop/scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env sh
# This script is used by portalloopd to actually launch the gno.land node.
# It sets up the gno.land node's config with the given environment variables,
# and starts the node.

MONIKER=${MONIKER:-"gnode"}
P2P_LADDR=${P2P_LADDR:-"tcp://0.0.0.0:26656"}
Expand All @@ -14,16 +17,13 @@ PERSISTENT_PEERS=${PERSISTENT_PEERS:-""}
echo "" >> /opt/gno/src/gno.land/genesis/genesis_txs.jsonl
cat ${GENESIS_BACKUP_FILE} >> /opt/gno/src/gno.land/genesis/genesis_txs.jsonl

gnoland start \
--chainid="${CHAIN_ID}" \
--skip-start=true \
--skip-failing-genesis-txs
gnoland config init -config-path="./testdir/config/config.toml"

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
gnoland config set -config-path="./testdir/config/config.toml" moniker "${MONIKER}"
gnoland config set -config-path="./testdir/config/config.toml" p2p.laddr "${P2P_LADDR}"
gnoland config set -config-path="./testdir/config/config.toml" rpc.laddr "${RPC_LADDR}"

sed -i "s#seeds = \".*\"#seeds = \"${SEEDS}\"#" ./testdir/config/config.toml
sed -i "s#persistent_peers = \".*\"#persistent_peers = \"${PERSISTENT_PEERS}\"#" ./testdir/config/config.toml
gnoland config set -config-path="./testdir/config/config.toml" p2p.seeds "${SEEDS}"
gnoland config set -config-path="./testdir/config/config.toml" p2p.persistent_peers "${PERSISTENT_PEERS}"

exec gnoland start --skip-failing-genesis-txs
exec gnoland start --skip-failing-genesis-txs --chainid="${CHAIN_ID}"
Loading