Skip to content

Commit

Permalink
Add scripts for client and relay working environments on docker (#844)
Browse files Browse the repository at this point in the history
* add scripts for client and relay tests

* re structure docker files used for testing

* add small explanation on README
  • Loading branch information
emmanuelm41 committed Dec 6, 2021
1 parent 1dd837f commit e663c6f
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ drand-client
drand-relay-gossip
drand-relay-http
drand-relay-s3
docker/data*
test/docker/tmp
test/docker/data*
**/nohup.out
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ build_all: drand drand-client drand-relay-http drand-relay-gossip drand-relay-s3
build_docker:
docker build --build-arg major=$(MAJOR) --build-arg minor=$(MINOR) --build-arg patch=$(PATCH) --build-arg gitCommit=`git rev-parse HEAD` -t drandorg/go-drand:latest .

build_docker_dev:
docker build -f test/docker/Dockerfile --build-arg major=$(MAJOR) --build-arg minor=$(MINOR) --build-arg patch=$(PATCH) --build-arg gitCommit=`git rev-parse HEAD` -t drandorg/go-drand-dev:latest .
############################################ Deps ############################################

install_deps_linux:
Expand Down
38 changes: 38 additions & 0 deletions test/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM golang:1.17.1-buster AS builder

ARG major=0
ARG minor=0
ARG patch=0
ARG gitCommit

ENV GOPATH /go
ENV SRC_PATH $GOPATH/src/github.com/drand/drand/
ENV GOPROXY https://proxy.golang.org

# Get the TLS CA certificates, they're not provided by busybox.
RUN apt-get update && apt-get install -y ca-certificates

COPY go.* $SRC_PATH
WORKDIR $SRC_PATH
RUN go mod download

COPY . $SRC_PATH
RUN make client
RUN make relay-http

FROM busybox:1-glibc

ENV GOPATH /go
ENV SRC_PATH /go/src/github.com/drand/drand
ENV DRAND_HOME /data/drand

COPY --from=builder $SRC_PATH/drand-client /usr/local/bin/drand-client
COPY --from=builder $SRC_PATH/drand-relay-http /usr/local/bin/drand-relay-http

VOLUME $DRAND_HOME
ENTRYPOINT [""]

# Defaults for drand go here
CMD [""]


9 changes: 9 additions & 0 deletions test/docker/READM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Instructions

---

In order to run the docker compose file, you will need to build drand and drand-dev images. You will find two commands on Makefile for that.

The commands are:
- ```make build_docker```
- ```make build_docker_dev```
27 changes: 27 additions & 0 deletions docker/docker-compose.yml → test/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,30 @@ services:
DRAND_PUBLIC_ADDRESS: "drand_4:8480"
DRAND_SHARE_SECRET: "thisisthesecretweshouldsettorundkgprocessonthenodes"

drand_client:
container_name: drand_client
image: docker.io/drandorg/go-drand-dev:latest
volumes:
- ./data_0:/data/drand_0
- ./data_1:/data/drand_1
- ./data_2:/data/drand_2
- ./data_3:/data/drand_3
- ./data_4:/data/drand_4
command: tail -f /dev/null

drand_relay:
container_name: drand_relay
image: docker.io/drandorg/go-drand-dev:latest
volumes:
- ./data_0:/data/drand_0
- ./data_1:/data/drand_1
- ./data_2:/data/drand_2
- ./data_3:/data/drand_3
- ./data_4:/data/drand_4
command: tail -f /dev/null
ports:
- "0.0.0.0:9080:9080"
- "0.0.0.0:9180:9180"
- "0.0.0.0:9280:9280"
- "0.0.0.0:9380:9380"

File renamed without changes.
File renamed without changes.
108 changes: 108 additions & 0 deletions test/docker/utils/testClient.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
################ Insecure mode ################
###############################################

# Insecure is used because we are not using TLS to initiate the communication and we are not providing chain hash nor group file

# Get last random value over http
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_0:8081 --insecure'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_1:8181 --insecure'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_2:8281 --insecure'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_3:8381 --insecure'

# Get last random value over grpc
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_0:8080 --insecure'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_1:8180 --insecure'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_2:8280 --insecure'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_3:8380 --insecure'


# Get random values as they become available over grpc
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_0:8080 --insecure --watch'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_1:8180 --insecure --watch'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_2:8280 --insecure --watch'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_3:8380 --insecure --watch'

# Get random values generated on round 1050 over grpc
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_0:8080 --insecure --round 1050'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_1:8180 --insecure --round 1050'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_2:8280 --insecure --round 1050'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_3:8380 --insecure --round 1050'

# Get random values generated on round 1050 over http
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_0:8081 --insecure --round 1050'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_1:8181 --insecure --round 1050'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_2:8281 --insecure --round 1050'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_3:8381 --insecure --round 1050'

############### With chain hash ###############
###############################################

# Insecure is kept there because we are not using TLS to initiate the communication

# Get last random value over http
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_0:8081 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_1:8181 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_2:8281 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_2:8281 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'

# Get last random value over grpc
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_0:8080 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_1:8180 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_2:8280 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_3:8380 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'


# Get random values as they become available over grpc
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_0:8080 --insecure --watch --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_1:8180 --insecure --watch --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_2:8280 --insecure --watch --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_3:8380 --insecure --watch --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'

# Get random values generated on round 1050 over grpc
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_0:8080 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_1:8180 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_2:8280 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_3:8380 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'

# Get random values generated on round 1050 over http
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_0:8081 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_1:8181 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_2:8281 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_2:8281 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493'

############### With chain hash #################
################ and config file ################

# Insecure is kept there because we are not using TLS to initiate the communication

# Get last random value over http
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_0:8081 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_0/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_1:8181 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_1/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_2:8281 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_2/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_2:8281 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_3/.drand/multibeacon/default/groups/drand_group.toml'

# Get last random value over grpc
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_0:8080 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_0/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_1:8180 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_1/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_2:8280 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_2/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_3:8380 --insecure --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_3/.drand/multibeacon/default/groups/drand_group.toml'


# Get random values as they become available over grpc
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_0:8080 --insecure --watch --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_0/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_1:8180 --insecure --watch --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_1/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_2:8280 --insecure --watch --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_2/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_3:8380 --insecure --watch --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_3/.drand/multibeacon/default/groups/drand_group.toml'

# Get random values generated on round 1050 over grpc
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_0:8080 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_0/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_1:8180 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_1/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_2:8280 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_2/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --grpc-connect drand_3:8380 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_3/.drand/multibeacon/default/groups/drand_group.toml'

# Get random values generated on round 1050 over http
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_0:8081 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_0/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_1:8181 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_1/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_2:8281 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_2/.drand/multibeacon/default/groups/drand_group.toml'
docker exec drand_client /bin/sh -c 'drand-client --url http://drand_3:8381 --insecure --round 1050 --chain-hash 945ae851f30772add04b090fd6ba3d741969e38eee2f26fc77533e0d20a90493 --group-conf ./data/drand_3/.drand/multibeacon/default/groups/drand_group.toml'

42 changes: 42 additions & 0 deletions test/docker/utils/testRelay.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## Start drand-relay-http inside running drand containers (Dockerfile)
mkdir -p tmp/relay/node_0
cd ./tmp/relay/node_0
nohup docker exec drand_relay /bin/sh -c 'drand-relay-http --url http://drand_0:8081 --insecure --bind 0.0.0.0:9080' &
cd ../../../

mkdir -p tmp/relay/node_1
cd ./tmp/relay/node_1
nohup docker exec drand_relay /bin/sh -c 'drand-relay-http --url http://drand_1:8181 --insecure --bind 0.0.0.0:9180' &
cd ../../../

mkdir -p tmp/relay/node_2
cd ./tmp/relay/node_2
nohup docker exec drand_relay /bin/sh -c 'drand-relay-http --url http://drand_2:8281 --insecure --bind 0.0.0.0:9280' &
cd ../../../

mkdir -p tmp/relay/node_3
cd ./tmp/relay/node_3
nohup docker exec drand_relay /bin/sh -c 'drand-relay-http --url http://drand_3:8381 --insecure --bind 0.0.0.0:9380' &
cd ../../../

sleep 5s

# Fetch round 1050
curl http://127.0.0.1:9080/public/1050
curl http://127.0.0.1:9180/public/1050
curl http://127.0.0.1:9280/public/1050

# Fetch latest round
curl http://127.0.0.1:9080/public/latest
curl http://127.0.0.1:9180/public/latest
curl http://127.0.0.1:9280/public/latest

# Fetch chain info
curl http://127.0.0.1:9080/info
curl http://127.0.0.1:9180/info
curl http://127.0.0.1:9280/info

# Check how relay is working (difference between last seen and expected round)
curl http://127.0.0.1:9080/health
curl http://127.0.0.1:9180/health
curl http://127.0.0.1:9280/health

0 comments on commit e663c6f

Please sign in to comment.