Skip to content

Commit 6889b32

Browse files
author
a.guzev
committed
pos-lachesis docker
1 parent 442f07d commit 6889b32

File tree

7 files changed

+78
-3
lines changed

7 files changed

+78
-3
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

src/poslachesis/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# PoS-Lachesis node
2+
3+
Package assembles functionality of [network node](../posnode/) and [consensus](../posposet/) into solid Lachesis-node.
4+
5+
6+
### Executables
7+
8+
[`cmd/`](./cmd/) - contains cli (only for fakenet now):
9+
10+
- run single node: `go run main.go`;
11+
- for args see `go run main.go --help`;
12+
- build: `go build .`;
13+
14+
15+
### Docker
16+
17+
[`docker/`](./docker/) - contains docker scripts to try lachesis fakenet:
18+
19+
- build node docker image "pos-lachesis": `make`;
20+
- run network of N nodes: `n=N ./start.sh`;
21+
- drop network: `./stop.sh`;

src/poslachesis/docker/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM golang:1.12 as build
2+
3+
WORKDIR /go/src/github.com/Fantom-foundation/go-lachesis
4+
COPY . .
5+
6+
RUN go get github.com/Masterminds/glide
7+
8+
RUN glide install && CGO_ENABLED=0 go build -ldflags "-s -w" -o /tmp/lachesis ./src/poslachesis/cmd
9+
10+
11+
12+
FROM scratch as prod
13+
14+
COPY --from=build /tmp/lachesis /
15+
16+
EXPOSE 55555 55556
17+
18+
ENTRYPOINT ["/lachesis"]

src/poslachesis/docker/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.PHONY: build start stop
2+
3+
all: build
4+
5+
6+
build:
7+
cd ../../.. && docker build -f src/poslachesis/docker/Dockerfile -t "pos-lachesis" .
8+
9+
start:
10+
./start.sh
11+
12+
stop:
13+
./stop.sh

src/poslachesis/docker/start.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
declare -ri n="${n:-3}"
4+
5+
docker network create lachesis
6+
7+
limit_cpu=$(echo "scale=2; 1/$n" | bc)
8+
limit_io=$(echo "500/$n" | bc)
9+
limits="--cpus=${limit_cpu} --blkio-weight=${limit_io}"
10+
11+
for i in $(seq $n)
12+
do
13+
j=$(($i % $n + 1)) # ring
14+
docker run -d --rm --name=pos-lachesis-node-$i ${limits} --net=lachesis "pos-lachesis" --fakegen=$i/$n --db=/tmp --peer=pos-lachesis-node-$j
15+
done

src/poslachesis/docker/stop.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
docker ps -q --filter "network=lachesis" | while read id
4+
do
5+
docker stop $id
6+
done
7+
8+
docker network rm lachesis

src/posnode/emitter.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ func (n *Node) StartEventEmission() {
2424
return
2525
}
2626
n.emitter.done = make(chan struct{})
27-
done := n.emitter.done
2827

29-
go func() {
28+
go func(done chan struct{}) {
3029
ticker := time.NewTicker(n.conf.EmitInterval)
3130
for {
3231
select {
@@ -36,7 +35,7 @@ func (n *Node) StartEventEmission() {
3635
return
3736
}
3837
}
39-
}()
38+
}(n.emitter.done)
4039
}
4140

4241
// StopEventEmission stops event emission.

0 commit comments

Comments
 (0)