Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node versioning #824

Merged
merged 26 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
42df740
v1.2.0
willscott Oct 5, 2020
44b55ad
Merge branch 'master' into release/v1.2
willscott Oct 21, 2020
3bc0526
Merge branch 'master' into release/v1.2
willscott Nov 11, 2020
91f2aeb
Merge branch 'master' into release/v1.2
willscott Nov 11, 2020
df6cee3
Merge remote-tracking branch 'origin/master' into release/v1.2
willscott Dec 14, 2020
1d6486e
Merge branch 'master' of github.com:drand/drand into release/v1.2
willscott Dec 14, 2020
277e1e9
Merge branch 'master' into release/v1.2
willscott Apr 14, 2021
a5ee729
Merge branch 'master' into release/v1.2
willscott Apr 15, 2021
6fe1929
Merge branch 'drand:master' into master
emmanuelm41 Sep 28, 2021
da7cfe6
Merge branch 'drand:master' into master
emmanuelm41 Sep 28, 2021
ceb1b75
Merge branch 'drand:master' into master
emmanuelm41 Sep 30, 2021
95ee48e
Merge branch 'drand:master' into master
emmanuelm41 Oct 1, 2021
a5980d4
update go version to 1.17
emmanuelm41 Oct 5, 2021
018aba5
update go and protobuf version
emmanuelm41 Oct 5, 2021
e391685
Merge pull request #30 from Zondax/go-version-update
emmanuelm41 Oct 6, 2021
51628a2
Merge branch 'drand:master' into master
emmanuelm41 Oct 6, 2021
586f4f8
apply node versioning on all messages flowing on drand
emmanuelm41 Sep 30, 2021
f277aaf
re generate pb.go files
emmanuelm41 Oct 1, 2021
02a8e14
apply some fixes required by golint
emmanuelm41 Oct 1, 2021
652e34c
fix makefile as it was broken
emmanuelm41 Oct 1, 2021
870e87f
fix typo on major name
emmanuelm41 Oct 5, 2021
47e12c6
apply sync.Once on app version parsing
emmanuelm41 Oct 5, 2021
daa52fa
apply version values on build docker cmd
emmanuelm41 Oct 5, 2021
e579eb1
use tag to set node version values
emmanuelm41 Oct 5, 2021
1e37d78
change new field name from Context to Metadata
emmanuelm41 Oct 5, 2021
f6d743c
pin specific hash for github actions on CI
emmanuelm41 Oct 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-go@v2
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # pin@v2
- uses: actions/setup-go@331ce1d993939866bb63c32c6cbbfd48fa76fc57 # pin@v2
with:
go-version: '^1.17'
- uses: actions/cache@v2
- uses: actions/cache@c64c572235d810460d0d6876e9c705ad5002b353 # pin@v2
id: cache
with:
path: ~/go/pkg/mod
Expand All @@ -25,9 +25,9 @@ jobs:
${{ runner.os }}-go-
- name: Build and push Docker image
run: |
docker build --build-arg version=`git describe --tags` --build-arg gitCommit=`git rev-parse HEAD` -t drandorg/go-drand:latest .
docker build --build-arg major=0 --build-arg minor=0 --build-arg patch=0 --build-arg gitCommit=`git rev-parse HEAD` -t drandorg/go-drand:latest .
echo $DOCKER_PWD | docker login -u $DOCKER_LOGIN --password-stdin
docker push drandorg/go-drand:latest
env:
DOCKER_PWD: ${{ secrets.DOCKER_PWD }}
DOCKER_LOGIN: ${{ secrets.DOCKER_LOGIN }}
DOCKER_LOGIN: ${{ secrets.DOCKER_LOGIN }}
19 changes: 14 additions & 5 deletions .github/workflows/publish_tagged.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,31 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-go@v2
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # pin@v2
- uses: actions/setup-go@331ce1d993939866bb63c32c6cbbfd48fa76fc57 # pin@v2
with:
go-version: '^1.17'
- uses: actions/cache@v2
- uses: actions/cache@c64c572235d810460d0d6876e9c705ad5002b353 # pin@v2
id: cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get latest release version number
id: get_version
uses: battila7/get-version-action@d97fbc34ceb64d1f5d95f4dfd6dce33521ccccf5 # pin@v2
- name: Parse semver string
id: semver_parser
uses: booxmedialtd/ws-action-parse-semver@3576f3a20a39f8752fe0d8195f5ed384090285dc # pin@v1
with:
input_string: ${{ steps.get_version.outputs.version }}
version_extractor_regex: 'v(.*)$'
- name: Build and push tagged Docker image
run: |
docker build --build-arg version=`git describe --tags` --build-arg gitCommit=`git rev-parse HEAD` -t drandorg/go-drand:`git describe --tags` .
docker build --build-arg major=${{ steps.semver_parser.outputs.major }} --build-arg minor=${{ steps.semver_parser.outputs.minor }} --build-arg patch=${{ steps.semver_parser.outputs.patch }} --build-arg gitCommit=`git rev-parse HEAD` -t drandorg/go-drand:`git describe --tags` .
echo $DOCKER_PWD | docker login -u $DOCKER_LOGIN --password-stdin
docker push drandorg/go-drand:`git describe --tags`
env:
DOCKER_PWD: ${{ secrets.DOCKER_PWD }}
DOCKER_LOGIN: ${{ secrets.DOCKER_LOGIN }}
DOCKER_LOGIN: ${{ secrets.DOCKER_LOGIN }}
41 changes: 27 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,45 @@ jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # pin@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2

- name: Set up Go
uses: actions/setup-go@331ce1d993939866bb63c32c6cbbfd48fa76fc57 # pin@v2
with:
go-version: '1.17'
-
name: Install Protoc
uses: arduino/setup-protoc@v1.1.2

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # pin@v1.1.2
with:
version: '3.14.0'
-
name: Install Protoc-gen-go

- name: Install Protoc-gen-go
run: |
GO111MODULE=off go get github.com/golang/protobuf/protoc-gen-go@v1.5.2
GO111MODULE=off go get google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0
go mod tidy
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2

- name: Get latest release version number
id: get_version
uses: battila7/get-version-action@d97fbc34ceb64d1f5d95f4dfd6dce33521ccccf5 # pin@v2

- name: Parse semver string
id: semver_parser
uses: booxmedialtd/ws-action-parse-semver@3576f3a20a39f8752fe0d8195f5ed384090285dc # pin@v1
with:
input_string: ${{ steps.get_version.outputs.version }}
version_extractor_regex: 'v(.*)$'

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@5a54d7e660bda43b405e8463261b3d25631ffe86 # pin@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAJOR: ${{ steps.semver_parser.outputs.major }}
MINOR: ${{ steps.semver_parser.outputs.minor }}
PATCH: ${{ steps.semver_parser.outputs.patch }}
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM golang:1.14.2-buster AS builder
MAINTAINER Hector Sanjuan <hector@protocol.ai>

ARG version=unknown
ARG major=0
ARG minor=0
ARG patch=0
ARG gitCommit

ENV GOPATH /go
Expand Down Expand Up @@ -32,7 +34,9 @@ RUN \
go install \
-mod=readonly \
-ldflags \
"-X github.com/drand/drand/cmd/drand-cli.version=${version} \
"-X github.com/drand/drand/common.MAJOR=${major} \
-X github.com/drand/drand/common.MINOR=${minor} \
-X github.com/drand/drand/common.PATCH=${patch} \
-X github.com/drand/drand/cmd/drand-cli.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` \
-X github.com/drand/drand/cmd/drand-cli.gitCommit=${gitCommit}"

Expand Down
33 changes: 26 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
.PHONY: test test-unit test-integration demo deploy-local linter install build client drand relay-http relay-gossip relay-s3

# Version values
ifeq ($(MAJOR),)
MAJOR := 0
endif

ifeq ($(PATCH),)
PATCH := 0
endif

ifeq ($(MINOR),)
MINOR := 0
endif

VER_PACKAGE=github.com/drand/drand/common
CLI_PACKAGE=github.com/drand/drand/cmd/drand-cli

GIT_REVISION := $(shell git rev-parse HEAD)
BUILD_DATE := $(shell date -u +%d/%m/%Y@%H:%M:%S)

drand: build

#################### Lint and fmt process ##################
Expand Down Expand Up @@ -63,35 +82,35 @@ build_proto:

# create the "drand" binary and install it in $GOBIN
install:
go install -ldflags "-X github.com/drand/drand/cmd/drand-cli.version=`git describe --tags` -X github.com/drand/drand/cmd/drand-cli.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` -X github.com/drand/drand/cmd/drand-cli.gitCommit=`git rev-parse HEAD`"
go install -ldflags "-X $(VER_PACKAGE).MAJOR=$(MAJOR) -X $(VER_PACKAGE).MINOR=$(MINOR) -X $(VER_PACKAGE).PATCH=$(PATCH) -X $(CLI_PACKAGE).buildDate=$(BUILD_DATE) -X $(CLI_PACKAGE).gitCommit=$(GIT_REVISION)"

# create the "drand" binary in the current folder
build:
go build -o drand -mod=readonly -ldflags "-X github.com/drand/drand/cmd/drand-cli.version=`git describe --tags` -X github.com/drand/drand/cmd/drand-cli.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` -X github.com/drand/drand/cmd/drand-cli.gitCommit=`git rev-parse HEAD`"
go build -o drand -mod=readonly -ldflags "-X $(VER_PACKAGE).MAJOR=$(MAJOR) -X $(VER_PACKAGE).MINOR=$(MINOR) -X $(VER_PACKAGE).PATCH=$(PATCH) -X $(CLI_PACKAGE).buildDate=$(BUILD_DATE) -X $(CLI_PACKAGE).gitCommit=$(GIT_REVISION)"

# create the "drand-client" binary in the current folder
client:
go build -o drand-client -mod=readonly -ldflags "-X main.version=`git describe --tags` -X main.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` -X main.gitCommit=`git rev-parse HEAD`" ./cmd/client
go build -o drand-client -mod=readonly -ldflags "-X $(VER_PACKAGE).MAJOR=$(MAJOR) -X $(VER_PACKAGE).MINOR=$(MINOR) -X $(VER_PACKAGE).PATCH=$(PATCH) -X main.buildDate=$(BUILD_DATE) -X main.gitCommit=$(GIT_REVISION)" ./cmd/client
drand-client: client

# create the "drand-relay-http" binary in the current folder
relay-http:
go build -o drand-relay-http -mod=readonly -ldflags "-X main.version=`git describe --tags` -X main.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` -X main.gitCommit=`git rev-parse HEAD`" ./cmd/relay
go build -o drand-relay-http -mod=readonly -ldflags "-X $(VER_PACKAGE).MAJOR=$(MAJOR) -X $(VER_PACKAGE).MINOR=$(MINOR) -X $(VER_PACKAGE).PATCH=$(PATCH) -X main.buildDate=$(BUILD_DATE) -X main.gitCommit=$(GIT_REVISION)" ./cmd/relay
drand-relay-http: relay-http

# create the "drand-relay-gossip" binary in the current folder
relay-gossip:
go build -o drand-relay-gossip -mod=readonly -ldflags "-X main.version=`git describe --tags` -X main.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` -X main.gitCommit=`git rev-parse HEAD`" ./cmd/relay-gossip
go build -o drand-relay-gossip -mod=readonly -ldflags "-X $(VER_PACKAGE).MAJOR=$(MAJOR) -X $(VER_PACKAGE).MINOR=$(MINOR) -X $(VER_PACKAGE).PATCH=$(PATCH) -X main.buildDate=$(BUILD_DATE) -X main.gitCommit=$(GIT_REVISION)" ./cmd/relay-gossip
drand-relay-gossip: relay-gossip

# create the "drand-relay-s3" binary in the current folder
relay-s3:
go build -o drand-relay-s3 -mod=readonly -ldflags "-X main.version=`git describe --tags` -X main.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` -X main.gitCommit=`git rev-parse HEAD`" ./cmd/relay-s3
go build -o drand-relay-s3 -mod=readonly -ldflags "-X $(VER_PACKAGE).MAJOR=$(MAJOR) -X $(VER_PACKAGE).MINOR=$(MINOR) -X $(VER_PACKAGE).PATCH=$(PATCH) -X main.buildDate=$(BUILD_DATE) -X main.gitCommit=$(GIT_REVISION)" ./cmd/relay-s3
drand-relay-s3: relay-s3

build_all: drand drand-client drand-relay-http drand-relay-gossip drand-relay-s3
build_docker:
docker build --build-arg version=`git describe --tags` --build-arg gitCommit=`git rev-parse HEAD` -t drandorg/go-drand:latest .
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 .

############################################ Deps ############################################

Expand Down
24 changes: 15 additions & 9 deletions chain/beacon/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (

"github.com/drand/drand/chain"
"github.com/drand/drand/log"
"github.com/drand/drand/protobuf/common"
proto "github.com/drand/drand/protobuf/drand"
"github.com/drand/drand/utils"
clock "github.com/jonboulle/clockwork"

"github.com/drand/drand/key"
Expand Down Expand Up @@ -51,11 +53,12 @@ type Handler struct {
serving bool
stopped bool
l log.Logger
version utils.Version
}

// NewHandler returns a fresh handler ready to serve and create randomness
// beacon
func NewHandler(c net.ProtocolClient, s chain.Store, conf *Config, l log.Logger) (*Handler, error) {
func NewHandler(c net.ProtocolClient, s chain.Store, conf *Config, l log.Logger, version utils.Version) (*Handler, error) {
emmanuelm41 marked this conversation as resolved.
Show resolved Hide resolved
if conf.Share == nil || conf.Group == nil {
return nil, errors.New("beacon: invalid configuration")
}
Expand All @@ -75,14 +78,15 @@ func NewHandler(c net.ProtocolClient, s chain.Store, conf *Config, l log.Logger)
ticker := newTicker(conf.Clock, conf.Group.Period, conf.Group.GenesisTime)
store := newChainStore(logger, conf, c, crypto, s, ticker)
handler := &Handler{
conf: conf,
client: c,
crypto: crypto,
chain: store,
ticker: ticker,
addr: addr,
close: make(chan bool),
l: logger,
conf: conf,
client: c,
crypto: crypto,
chain: store,
ticker: ticker,
addr: addr,
close: make(chan bool),
l: logger,
version: version,
}
return handler, nil
}
Expand Down Expand Up @@ -354,10 +358,12 @@ func (h *Handler) broadcastNextPartial(current roundInfo, upon *chain.Beacon) {
return
}
h.l.Debug("broadcast_partial", round, "from_prev_sig", shortSigStr(previousSig), "msg_sign", shortSigStr(msg))
metadata := common.NewMetadata(h.version.ToProto())
packet := &proto.PartialBeaconPacket{
Round: round,
PreviousSig: previousSig,
PartialSig: currSig,
Metadata: metadata,
}
h.chain.NewValidPartial(h.addr, packet)
for _, id := range h.crypto.GetGroup().Nodes {
Expand Down
5 changes: 4 additions & 1 deletion chain/beacon/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/drand/drand/protobuf/drand"
"github.com/drand/drand/test"
testnet "github.com/drand/drand/test/net"
"github.com/drand/drand/utils"
"github.com/drand/kyber"
"github.com/drand/kyber/share"
"github.com/drand/kyber/util/random"
Expand Down Expand Up @@ -195,7 +196,9 @@ func (b *BeaconTest) CreateNode(t *testing.T, i int) {
Clock: node.clock,
}

node.handler, err = NewHandler(net.NewGrpcClient(), store, conf, log.NewLogger(nil, log.LogDebug))
logger := log.NewLogger(nil, log.LogDebug)
version := utils.Version{Major: 0, Minor: 0, Patch: 0}
node.handler, err = NewHandler(net.NewGrpcClient(), store, conf, logger, version)
checkErr(err)
if node.callback != nil {
node.handler.AddCallback(priv.Public.Address(), node.callback)
Expand Down
11 changes: 6 additions & 5 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import (

"github.com/drand/drand/client"
"github.com/drand/drand/cmd/client/lib"
"github.com/drand/drand/common"
"github.com/drand/drand/log"
"github.com/urfave/cli/v2"
)

// Automatically set through -ldflags
// Example: go install -ldflags "-X main.version=`git describe --tags`
// -X main.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` -X main.gitCommit=`git rev-parse HEAD`"
// Example: go install -ldflags "-X main.buildDate=`date -u +%d/%m/%Y@%H:%M:%S` -X main.gitCommit=`git rev-parse HEAD`"
var (
version = "master"
gitCommit = "none"
buildDate = "unknown"
)
Expand Down Expand Up @@ -65,9 +64,11 @@ var clientMetricsIDFlag = &cli.StringFlag{
}

func main() {
version := common.GetAppVersion()

app := cli.NewApp()
app.Name = "drand-client"
app.Version = version
app.Version = version.String()
app.Usage = "CDN Drand client for loading randomness from an HTTP endpoint"
app.Flags = lib.ClientFlags
app.Flags = append(app.Flags,
Expand All @@ -76,7 +77,7 @@ func main() {
clientMetricsPushIntervalFlag, verboseFlag)
app.Action = Client
cli.VersionPrinter = func(c *cli.Context) {
fmt.Printf("drand client %v (date %v, commit %v)\n", version, buildDate, gitCommit)
fmt.Printf("drand client %s (date %v, commit %v)\n", version, buildDate, gitCommit)
}

err := app.Run(os.Args)
Expand Down
Loading