Skip to content

Commit

Permalink
Add docker build (#129)
Browse files Browse the repository at this point in the history
* Add docker build

* Fix makefile update

* Use Dockerfile.build_local for zion-local

* Add genesis test utils
  • Loading branch information
devfans committed Oct 12, 2023
1 parent 528781a commit f44aa66
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM debian:bullseye-20230703-slim
RUN apt-get update && apt-get install -y git unzip wget curl build-essential
RUN curl -L https://golang.org/dl/go1.20.linux-`dpkg --print-architecture`.tar.gz | tar -C /usr/local -xzf -

WORKDIR /workspace

ARG commit=master

RUN ln -s /usr/local/go/bin/go /usr/bin/go
RUN git clone https://github.com/polynetwork/zion.git && \
cd zion && git checkout ${commit} && make geth
11 changes: 11 additions & 0 deletions Dockerfile.build_local
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.20-bullseye

ARG commit=main

WORKDIR /workspace

COPY go.mod go.sum ./
COPY . ./

RUN go mod download
RUN make geth
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# with Go source code. If you know what GOPATH is then you probably
# don't need to bother with make.

# Zion branch/commit_hash/tag to build with containers
COMMIT ?= master

.PHONY: geth android ios geth-cross evm all test clean
.PHONY: geth-linux geth-linux-386 geth-linux-amd64 geth-linux-mips64 geth-linux-mips64le
.PHONY: geth-linux-arm geth-linux-arm-5 geth-linux-arm-6 geth-linux-arm-7 geth-linux-arm64
Expand All @@ -17,6 +20,26 @@ geth:
@echo "Done building."
@echo "Run \"$(GOBIN)/geth\" to launch geth."

zion-clean:
@echo "Cleaning build artifacts"
rm -rf geth
docker container rm -f go-zion-temp
docker rmi -f go-zion-build

zion: zion-clean
@echo "Building geth binary in container"
docker build --no-cache --build-arg commit=$(COMMIT) -t go-zion-build -f ./Dockerfile.build .
docker container create --name go-zion-temp go-zion-build
docker container cp go-zion-temp:/workspace/zion/build/bin/geth .
sha256sum geth

zion-local: zion-clean
@echo "Building zion binary in container with local source files"
docker build --no-cache --build-arg commit=$(COMMIT) -t go-zion-build -f ./Dockerfile.build_local .
docker container create --name go-zion-temp go-zion-build
docker container cp go-zion-temp:/workspace/build/bin/geth .
sha256sum geth

all:
$(GORUN) build/ci.go install

Expand Down
32 changes: 32 additions & 0 deletions consensus/hotstuff/tool/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
package tool

import (
"encoding/hex"
"encoding/json"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/hotstuff"
"github.com/ethereum/go-ethereum/consensus/hotstuff/validator"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -74,6 +77,35 @@ func TestEncode(t *testing.T) {
dumpNodes(t, testNodeKeys)
}


func TestEncodeSeeds(t *testing.T) {
var addrs []common.Address
for _, str := range []string {
"04c1a1927b9a506ece82ed9db1bfc1da854ddc40e0a4a6a618bf9c5ca671ac893cd3653248c2853c6786ac6d03964717ae1a0a318de18a06a5ef83e8145f9daab7",
"04b8e55b48e89532efb956e6b2732ba5e124fed65b96092fce32a89080411ac0f2eefafae3020e97e248571103b0c1906de9a7ef641dc9037f067f775646cba2a3",
"04f9b194f397426f6540741114fb72cbf4d531fdb1e68a20e6ccc5d4d86e9a93014057e4bb0104e6cb0d3a37efdfe934f77b1c680663ad0e31b99878e2a8246bc2",
"041d64c9eac537ea8536622c4a28ad2fde1869b036241264c0fe5090d495e9db0c355c53c7b03f29845396a067fd9ee6c73722c419eecd77bbe3008c562174bf91",
} {
data, err := hex.DecodeString(str)
if err != nil {
t.Fatal(err)
}
pub, err := crypto.UnmarshalPubkey(data)
if err != nil {
t.Fatal(err)
}
t.Log(PubkeyID(pub).String())
addrs = append(addrs, crypto.PubkeyToAddress(*pub))
}

valset := validator.NewSet(addrs, hotstuff.RoundRobin)
genesis, err := EncodeGenesisExtra(valset.AddressList())
if err != nil {
t.Fatal(err)
}
t.Logf("genesis extra %s", genesis)
}

func TestGenerateAndEncode(t *testing.T) {
nodes := generateNodes(4)
dumpNodes(t, nodes)
Expand Down

0 comments on commit f44aa66

Please sign in to comment.