From f44aa66972c44a7e2f8c4f7946c37aa51cf1948f Mon Sep 17 00:00:00 2001 From: Stefan Liu Date: Thu, 12 Oct 2023 12:40:39 +0800 Subject: [PATCH] Add docker build (#129) * Add docker build * Fix makefile update * Use Dockerfile.build_local for zion-local * Add genesis test utils --- Dockerfile.build | 11 +++++++++ Dockerfile.build_local | 11 +++++++++ Makefile | 23 ++++++++++++++++++ consensus/hotstuff/tool/encoder_test.go | 32 +++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 Dockerfile.build create mode 100644 Dockerfile.build_local diff --git a/Dockerfile.build b/Dockerfile.build new file mode 100644 index 00000000..ccc1242c --- /dev/null +++ b/Dockerfile.build @@ -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 \ No newline at end of file diff --git a/Dockerfile.build_local b/Dockerfile.build_local new file mode 100644 index 00000000..96b7b8da --- /dev/null +++ b/Dockerfile.build_local @@ -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 \ No newline at end of file diff --git a/Makefile b/Makefile index cb5a87da..25e2efab 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/consensus/hotstuff/tool/encoder_test.go b/consensus/hotstuff/tool/encoder_test.go index 27d5b78c..5cc396e4 100644 --- a/consensus/hotstuff/tool/encoder_test.go +++ b/consensus/hotstuff/tool/encoder_test.go @@ -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" ) @@ -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)