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

Add profile option #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.3: QmPCdWsL88nB7fzvhLRhBMo1QVLtt6Vm7ee7N9ZoUsqpPL
1.4.0: QmXnGBw6fDN6EGwUBRnVvuoTFXZFL92f3KfYv2MpRq9kFk
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ var initCmd = cli.Command{
Name: "type",
Usage: "select type of nodes to initialize",
},
cli.StringFlag{
Name: "profile",
Usage: "initialize nodes with the specified profile",
},
},
Action: func(c *cli.Context) error {
if c.Int("count") == 0 {
Expand All @@ -152,6 +156,7 @@ var initCmd = cli.Command{
PortStart: c.Int("port"),
Override: c.String("cfg"),
NodeType: c.String("type"),
Profile: c.String("profile"),
}

err := util.IpfsInit(cfg)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
"license": "",
"name": "iptb",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.3.3"
"version": "1.4.0"
}

2 changes: 1 addition & 1 deletion sharness/t0020-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test_expect_success "iptb stop works" '

for i in {0..2}; do
test_expect_success "daemon '$i' was shut down gracefully" '
cat testbed/'$i'/daemon.stderr | tail -1 | grep "Gracefully shut down daemon"
cat testbed/'$i'/daemon.stderr | grep "Gracefully shut down daemon"
'
done

Expand Down
22 changes: 22 additions & 0 deletions sharness/t0030-profile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

test_description="iptb init --profile"

. lib/test-lib.sh

IPTB_ROOT=.

test_expect_success "iptb init works" '
../bin/iptb init -n 3 --profile=badgerds
'

for i in {0..2}; do
test_expect_success "node '$i' has badger datastore" '
IPATH=$(iptb get path '$i')

test -d "${IPATH}/badgerds"
'
done


test_done
12 changes: 9 additions & 3 deletions util/localnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (
var ErrTimeout = errors.New("timeout")

type LocalNode struct {
Dir string
PeerID string
Dir string
PeerID string
Profile string
}

func (n *LocalNode) Init() error {
Expand All @@ -34,7 +35,12 @@ func (n *LocalNode) Init() error {
return err
}

cmd := exec.Command("ipfs", "init", "-b=1024")
arg := []string{"init", "-b=1024"}
if n.Profile != "" {
arg = append(arg, "--profile="+n.Profile)
}

cmd := exec.Command("ipfs", arg...)
cmd.Env, err = n.envForDaemon()
if err != nil {
return err
Expand Down
10 changes: 8 additions & 2 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type InitCfg struct {
Websocket bool
Override string
NodeType string
Profile string
}

func (c *InitCfg) swarmAddrForPeer(i int) string {
Expand Down Expand Up @@ -195,7 +196,8 @@ func (ns *NodeSpec) Load() (IpfsNode, error) {
switch ns.Type {
case "local":
ln := &LocalNode{
Dir: ns.Dir,
Dir: ns.Dir,
Profile: ns.Extra["profile"].(string),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relying on this being set makes me a bit worried. Will this always be the case? We may want to default to "".

}

if _, err := os.Stat(filepath.Join(ln.Dir, "config")); err == nil {
Expand Down Expand Up @@ -269,13 +271,17 @@ func initSpecs(cfg *InitCfg) ([]*NodeSpec, error) {
Type: "docker",
Dir: dir,
Extra: map[string]interface{}{
"image": img,
"image": img,
"profile": cfg.Profile,
},
}
default:
ns = &NodeSpec{
Type: "local",
Dir: dir,
Extra: map[string]interface{}{
"profile": cfg.Profile,
},
}
}
specs = append(specs, ns)
Expand Down