Merge pull request #353 from filecoin-project/feat/node-deploy

Quick miner deploy util
This commit is contained in:
Łukasz Magiera 2019-10-15 15:09:53 +02:00 committed by GitHub
commit 98b4533247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 138 additions and 9 deletions

3
.gitignore vendored
View File

@ -2,8 +2,11 @@
/lotus-storage-miner
/pond
/townhall
/fountain
/lotuspond/front/node_modules
/lotuspond/front/build
/cmd/lotus-townhall/townhall/node_modules
/cmd/lotus-townhall/townhall/build
**/*.h
**/*.a
**/*.pc

View File

@ -98,6 +98,12 @@ townhall:
go run github.com/GeertJohan/go.rice/rice append --exec townhall -i ./cmd/lotus-townhall
.PHONY: townhall
fountain:
rm -f fountain
go build -o fountain ./cmd/lotus-fountain
go run github.com/GeertJohan/go.rice/rice append --exec fountain -i ./cmd/lotus-fountain
.PHONY: fountain
clean:
rm -rf $(CLEAN)
-$(MAKE) -C $(BLS_PATH) clean

View File

@ -2,11 +2,13 @@ package cli
import (
"fmt"
"time"
cid "github.com/ipfs/go-cid"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/chain"
cid "github.com/ipfs/go-cid"
)
var syncCmd = &cli.Command{
@ -14,6 +16,7 @@ var syncCmd = &cli.Command{
Usage: "Inspect or interact with the chain syncer",
Subcommands: []*cli.Command{
syncStatusCmd,
syncWaitCmd,
},
}
@ -49,3 +52,36 @@ var syncStatusCmd = &cli.Command{
return nil
},
}
var syncWaitCmd = &cli.Command{
Name: "wait",
Usage: "Wait for sync to be complete",
Action: func(cctx *cli.Context) error {
napi, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)
for {
ss, err := napi.SyncState(ctx)
if err != nil {
return err
}
var target []cid.Cid
if ss.Target != nil {
target = ss.Target.Cids()
}
fmt.Printf("\r\x1b[2KTarget: %s\tState: %s\tHeight: %d", target, chain.SyncStageString(ss.Stage), ss.Height)
if ss.Stage == api.StageSyncComplete {
fmt.Println("\nDone")
return nil
}
time.Sleep(1 * time.Second)
}
},
}

View File

@ -6,6 +6,7 @@ import (
"net/http"
"os"
rice "github.com/GeertJohan/go.rice"
logging "github.com/ipfs/go-log"
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
@ -89,8 +90,9 @@ var runCmd = &cli.Command{
from: from,
}
http.HandleFunc("/", h.index)
http.Handle("/", http.FileServer(rice.MustFindBox("site").HTTPBox()))
http.HandleFunc("/send", h.send)
http.HandleFunc("/sendcoll", h.sendColl)
fmt.Printf("Open http://%s\n", cctx.String("front"))
@ -110,13 +112,6 @@ type handler struct {
from address.Address
}
func (h *handler) index(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "<!DOCTYPE html>\n<html><head><title>Lotus Fountain</title><style>body {font-family: 'monospace';}</style></head><body>")
fmt.Fprintf(w, "<form action='/send' method='get'>Enter destination address: ")
fmt.Fprintf(w, "<input type='text' name='address'><br><button type='submit'>Send</button>")
fmt.Fprintf(w, "</form></body></html>")
}
func (h *handler) send(w http.ResponseWriter, r *http.Request) {
to, err := address.NewFromString(r.FormValue("address"))
if err != nil {
@ -141,3 +136,33 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(smsg.Cid().String()))
}
func (h *handler) sendColl(w http.ResponseWriter, r *http.Request) {
to, err := address.NewFromString(r.FormValue("address"))
if err != nil {
w.WriteHeader(400)
w.Write([]byte(err.Error()))
return
}
coll, err := h.api.StatePledgeCollateral(h.ctx, nil)
if err != nil {
return
}
smsg, err := h.api.MpoolPushMessage(h.ctx, &types.Message{
Value: coll,
From: h.from,
To: to,
GasPrice: types.NewInt(0),
GasLimit: types.NewInt(1000),
})
if err != nil {
w.WriteHeader(400)
w.Write([]byte(err.Error()))
return
}
w.Write([]byte(smsg.Cid().String()))
}

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Lotus Fountain</title>
<style>
body {
font-family: 'monospace';
background: #1f1f1f;
color: #f0f0f0;
}
</style>
</head>
<body>
<form action='/send' method='get'>
<span>Enter destination address:</span>
<input type='text' name='address' style="width: 300px">
<button type='submit'>Send</button>
</form>
</body>
</html>

16
scripts/deploy-miner.sh Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
HOST=$1
ssh "$HOST" 'lotus wallet new bls > addr'
ssh "$HOST" 'curl http://147.75.80.29:777/sendcoll?address=$(cat addr)' &
ssh "$HOST" 'curl http://147.75.80.29:777/sendcoll?address=$(cat addr)' &
ssh "$HOST" 'curl http://147.75.80.29:777/send?address=$(cat addr)' &
wait
echo "SYNC WAIT"
sleep 30
ssh "$HOST" 'lotus sync wait'
ssh "$HOST" 'lotus-storage-miner init --owner=$(cat addr)'
ssh "$HOST" 'systemctl start lotus-storage-miner' &

23
scripts/deploy-node.sh Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
HOST=$1
# upload binaries
# TODO: destroy
ssh "$HOST" 'systemctl stop lotus-storage-miner'
ssh "$HOST" 'systemctl stop lotus-daemon'
ssh "$HOST" 'mkdir -p .lotus .lotusstorage' &
scp "./lotus" "$HOST:/usr/local/bin" &
scp "./lotus-storage-miner" "$HOST:/usr/local/bin" &
scp -C scripts/daemon.service "${HOST}:/etc/systemd/system/lotus-daemon.service" &
scp -C scripts/sminer.service "${HOST}:/etc/systemd/system/lotus-storage-miner.service" &
wait
ssh "$HOST" 'systemctl daemon-reload'
ssh "$HOST" 'systemctl start lotus-daemon' &
wait
# setup miner actor