Skip to content

Commit

Permalink
pos-lachesis docker
Browse files Browse the repository at this point in the history
  • Loading branch information
a.guzev committed Apr 16, 2019
1 parent 442f07d commit 6889b32
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 3 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
21 changes: 21 additions & 0 deletions src/poslachesis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# PoS-Lachesis node

Package assembles functionality of [network node](../posnode/) and [consensus](../posposet/) into solid Lachesis-node.


### Executables

[`cmd/`](./cmd/) - contains cli (only for fakenet now):

- run single node: `go run main.go`;
- for args see `go run main.go --help`;
- build: `go build .`;


### Docker

[`docker/`](./docker/) - contains docker scripts to try lachesis fakenet:

- build node docker image "pos-lachesis": `make`;
- run network of N nodes: `n=N ./start.sh`;
- drop network: `./stop.sh`;
18 changes: 18 additions & 0 deletions src/poslachesis/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.12 as build

WORKDIR /go/src/github.com/Fantom-foundation/go-lachesis
COPY . .

RUN go get github.com/Masterminds/glide

RUN glide install && CGO_ENABLED=0 go build -ldflags "-s -w" -o /tmp/lachesis ./src/poslachesis/cmd



FROM scratch as prod

COPY --from=build /tmp/lachesis /

EXPOSE 55555 55556

ENTRYPOINT ["/lachesis"]
13 changes: 13 additions & 0 deletions src/poslachesis/docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: build start stop

all: build


build:
cd ../../.. && docker build -f src/poslachesis/docker/Dockerfile -t "pos-lachesis" .

start:
./start.sh

stop:
./stop.sh
15 changes: 15 additions & 0 deletions src/poslachesis/docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

declare -ri n="${n:-3}"

docker network create lachesis

limit_cpu=$(echo "scale=2; 1/$n" | bc)
limit_io=$(echo "500/$n" | bc)
limits="--cpus=${limit_cpu} --blkio-weight=${limit_io}"

for i in $(seq $n)
do
j=$(($i % $n + 1)) # ring
docker run -d --rm --name=pos-lachesis-node-$i ${limits} --net=lachesis "pos-lachesis" --fakegen=$i/$n --db=/tmp --peer=pos-lachesis-node-$j
done
8 changes: 8 additions & 0 deletions src/poslachesis/docker/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

docker ps -q --filter "network=lachesis" | while read id
do
docker stop $id
done

docker network rm lachesis
5 changes: 2 additions & 3 deletions src/posnode/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ func (n *Node) StartEventEmission() {
return
}
n.emitter.done = make(chan struct{})
done := n.emitter.done

go func() {
go func(done chan struct{}) {
ticker := time.NewTicker(n.conf.EmitInterval)
for {
select {
Expand All @@ -36,7 +35,7 @@ func (n *Node) StartEventEmission() {
return
}
}
}()
}(n.emitter.done)
}

// StopEventEmission stops event emission.
Expand Down

0 comments on commit 6889b32

Please sign in to comment.