Skip to content

Commit

Permalink
feat(core): add 'berty daemon --init-only' option + configure the moc…
Browse files Browse the repository at this point in the history
…k network driver
  • Loading branch information
moul committed Jul 30, 2018
1 parent 816057f commit 4ae4be0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Expand Up @@ -50,6 +50,10 @@ jobs:
name: Build application Docker image
command: |
docker build --cache-from=berty -t berty .
- run:
name: Run application within Docker
command: |
docker run --rm berty daemon --init-only
- run:
name: Save Docker image layer cache
command: |
Expand Down Expand Up @@ -88,6 +92,11 @@ jobs:
command: |
cd core
make test | tee /tmp/test-results/go-test-report.out
- run:
name: integration core
command: |
cd core
make integration
- run:
name: junit-report
command: |
Expand Down
8 changes: 8 additions & 0 deletions core/Makefile
Expand Up @@ -46,6 +46,14 @@ testwatch:
test: generate
$(TEST_CMD)

.PHONY: integration
integration: install
rm -f /tmp/berty.integration.db
@# initialize a new daemon on a fresh db
$(BIN) daemon --init-only --sql-path=/tmp/berty.integration.db
@# initialize a new daemon based on an existing db
$(BIN) daemon --init-only --sql-path=/tmp/berty.integration.db

.PHONY: lint
lint: generate
gometalinter.v2 --config=../.gometalinter.json $(TEST_PATHS)
Expand Down
18 changes: 14 additions & 4 deletions core/cmd/berty/daemon.go
Expand Up @@ -15,6 +15,7 @@ import (
"google.golang.org/grpc/reflection"

"github.com/berty/berty/core/entity"
"github.com/berty/berty/core/network/drivermock"
"github.com/berty/berty/core/node"
"github.com/berty/berty/core/sql"
"github.com/berty/berty/core/sql/sqlcipher"
Expand All @@ -26,6 +27,7 @@ type daemonOptions struct {
sqlPath string
sqlKey string
dropDatabase bool
initOnly bool
}

func newDaemonCommand() *cobra.Command {
Expand All @@ -42,6 +44,7 @@ func newDaemonCommand() *cobra.Command {
flags.StringVarP(&opts.sqlPath, "sql-path", "", "/tmp/berty.db", "sqlcipher database path")
flags.StringVarP(&opts.sqlKey, "sql-key", "", "s3cur3", "sqlcipher database encryption key")
flags.BoolVar(&opts.dropDatabase, "drop-database", false, "drop database to force a reinitialization")
flags.BoolVar(&opts.initOnly, "init-only", false, "stop after node initialization (useful for integration tests")
return cmd
}

Expand Down Expand Up @@ -79,26 +82,33 @@ func daemon(opts *daemonOptions) error {
node.WithP2PGrpcServer(gs),
node.WithNodeGrpcServer(gs),
node.WithSQL(db),
node.WithDevice(&entity.Device{Name: "bart"}), // FIXME: get device dynamically
node.WithDevice(&entity.Device{Name: "bart"}), // FIXME: get device dynamically
node.WithNetworkDriver(drivermock.NewEnqueuer()), // FIXME: use a p2p driver instead
)
if err != nil {
return errors.Wrap(err, "failed to initialize node")
}

if opts.initOnly {
return nil
}

// start grpc server(s)
go func() {
errChan <- gs.Serve(listener)
}()
if !opts.hideBanner {
fmt.Println(banner)
}
zap.L().Info("grpc server started", zap.String("bind", opts.bind))

// start node
go func() {
errChan <- n.Start()
}()

// show banner
if !opts.hideBanner {
fmt.Println(banner)
}

// signal handling
signalChan := make(chan os.Signal, 1)
signal.Notify(
Expand Down

0 comments on commit 4ae4be0

Please sign in to comment.