Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Verify latest docker
Browse files Browse the repository at this point in the history
Adds a test that checks if the latest docker can actually create a stable
new byzcoin.
  • Loading branch information
ineiti committed Sep 2, 2020
1 parent 7caf1a4 commit 9208211
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ jobs:
- name: Fetch latest code
run: make update

- name: Verify mixed environment still runs
run: |
sudo echo "127.0.0.1 node1 node2 node3 node4" | sudo tee -a /etc/hosts
make verify_latest
- name: Replay
run: |
( cd upstream/cothority; go build -o ../../bcadmin ./byzcoin/bcadmin )
Expand All @@ -39,5 +44,6 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Push new docker image
run: make docker-push-new
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/upstream/
/bcadmin
/cached.db
.godocker
.idea
nodes
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ DOW := $(shell date +%a)
# Monday's date
ifeq '$(DOW)' 'Mon'
DATE_COMPILE := $(shell date +%Y%m%d)
DATE_PREVIOUS := $(shell date --date "last Monday" +%Y%m%d || \
date -v Mon -v -7d %Y%m%d)
else
# mac date doesn't know about --date argument...
DATE_COMPILE := $(shell date --date "last Monday" +%Y%m%d || \
date -v Mon +%Y%m%d)
DATE_PREVIOUS := $(shell date --date "Monday a fortnight ago" +%Y%m%d || \
date -v Mon -v -7d +%Y%m%d)
endif

DOCKER_TAG = $(DATE_COMPILE)
Expand Down Expand Up @@ -110,3 +114,9 @@ docker-push-all: docker
docker tag $(DOCKER_NAME):$(DOCKER_TAG) $(DOCKER_NAME):$$d; \
docker push $(DOCKER_NAME):$$d; \
done

verify_latest: LATEST=$(DOCKER_NAME):$(DOCKER_TAG)
verify_latest: PREVIOUS=$(DOCKER_NAME):$(DATE_PREVIOUS)
verify_latest: docker
docker pull $(PREVIOUS)
./update_test.sh $(PREVIOUS) $(LATEST)
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,13 @@ As every node is linked to a different 'daily' docker image, the 7 nodes

## Verification

The travis-job at c4dt/byzcoin verifies that the new code correctly replays
all known transactions on the chain.
This plus the normal unit-tests from the code are the only verification done
before a new docker is created and published.
The following verifications are done before a new image is generated:
* a small unit-test for the binary
* the new code correctly replays all known transactions on the chain
* a cothority with 4 nodes can correctly migrate from the previous to the
current nodes

All those tests are done in the `update.yaml` github action.

## Manual updates

Expand Down
133 changes: 133 additions & 0 deletions update_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/bin/bash

set -e

PREVIOUS=$1
LATEST=$2
NODES=$(seq -f "node%g" 4)
DATA=nodes
BLOCK_PREVIOUS=5s

main(){
cleanup
docker_config_run
mint_coins 3
docker_replace
switch_leader
mint_coins 5
}

cleanup() {
for n in $NODES; do
docker rm -f $n || true
done

mkdir -p $DATA
if [ ! -f $DATA/bcadmin ]; then
echo "Creating bcadmin binary"
(cd pkg/cothority && go build ./byzcoin/bcadmin && mv bcadmin ../../$DATA)
fi

cd $DATA || exit 1
rm -rf node*
}

docker_start() {
local image=$1
local name=$2
local port=$3
local ports="$port-$((port + 1))"
docker run -v $(pwd)/$name:/byzcoin -p $ports:$ports -d \
--name $name -h $name -e DEBUG_TIME=true -e DEBUG_COLOR=true \
--network nodes $image \
./byzcoin run /byzcoin
docker logs -f $name >>logs 2>&1 &
}

docker_config_run(){
docker network create nodes || true
PORT=2000
for n in $NODES; do
echo "Configuring $n"
docker run -v $(pwd)/$n:/byzcoin $PREVIOUS \
./byzcoin config --data-dir /byzcoin \
--address-node "tls://$n:$((PORT))" \
--address-ws "http://$n:$((PORT + 1))" --desc $n >/dev/null

echo "Starting $n"
docker_start $PREVIOUS $n $PORT

PORT=$((PORT + 10))
done

rm -f roster.toml
for p in node*/public.toml; do
cat <<EOF >>roster.toml
[[servers]]
$(cat $p | sed 's/^/ /' | sed 's/Services/servers.Services/')
EOF
done

echo "Creating new chain"
rm -f *.cfg
./bcadmin -c . create -i $BLOCK_PREVIOUS roster.toml

echo "Latest block"
./bcadmin debug list http://localhost:2001
}

docker_replace(){
PORT=2000
for n in $NODES; do
echo "Replacing $n"
docker rm -f $n
docker_start $LATEST $n $PORT

echo "Minting some coins"
./bcadmin mint bc-* key-* \
559cd91debcb38952632b509ee5e00624deac7275c7a986ebbe35bc2a6e3dfad 100 &

PORT=$((PORT + 10))
done

./bcadmin debug list -v http://localhost:2001
}

mint_coins(){
for mint in $(seq $1); do
echo "Minting some coins $mint"
./bcadmin mint bc-* key-* \
559cd91debcb38952632b509ee5e00624deac7275c7a986ebbe35bc2a6e3dfad 100
done
echo "Latest block"
./bcadmin debug list http://localhost:2001
}

switch_leader(){
PORT=2000
for n in $NODES; do
PORT_NEXT=$(( (((PORT-2000)+10) % 40) + 2001))
echo "Switching leader $n - next port: $PORT_NEXT"
docker rm -f $n

LEADER=$n
while [ $LEADER = $n ]; do
echo "Minting some coins for leader $LEADER"
./bcadmin mint bc-* key-* \
559cd91debcb38952632b509ee5e00624deac7275c7a986ebbe35bc2a6e3dfad 100 &
sleep 2

LEADER=$( ./bcadmin debug list -v http://localhost:$PORT_NEXT |
grep "Roster: " | sed -e "s;.*\[tls://\([^:]*\):.*;\1;" )
echo "New leader is: $LEADER"
done

docker_start $LATEST $n $PORT
sleep 2

PORT=$((PORT + 10))
done
}

main

0 comments on commit 9208211

Please sign in to comment.