Skip to content

Commit e6b050f

Browse files
committed
[FAB-4413] Enable peer to report version info
The peer currently support a verion command and flag but does not actually print version info when starting. This change improves the version info and makes it consistent with the info now provided by other binaries. Change-Id: Ie030653fc1212401cf63b77a8212167f3919e26c Signed-off-by: Gari Singh <[email protected]>
1 parent 77fa0ad commit e6b050f

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

peer/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var mainCmd = &cobra.Command{
6262
},
6363
Run: func(cmd *cobra.Command, args []string) {
6464
if versionFlag {
65-
version.Print()
65+
fmt.Print(version.GetInfo())
6666
} else {
6767
cmd.HelpFunc()(cmd, args)
6868
}

peer/node/start.go

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/hyperledger/fabric/msp/mgmt"
3333
"github.com/hyperledger/fabric/peer/common"
3434
peergossip "github.com/hyperledger/fabric/peer/gossip"
35+
"github.com/hyperledger/fabric/peer/version"
3536
pb "github.com/hyperledger/fabric/protos/peer"
3637
"github.com/spf13/cobra"
3738
"github.com/spf13/viper"
@@ -78,6 +79,7 @@ func initSysCCs() {
7879
}
7980

8081
func serve(args []string) error {
82+
logger.Infof("Starting %s", version.GetInfo())
8183
ledgermgmt.Initialize()
8284
// Parameter overrides must be processed before any parameters are
8385
// cached. Failures to cache cause the server to terminate immediately.

peer/version/version.go

+24-16
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package version
188

199
import (
2010
"fmt"
11+
"runtime"
2112

2213
"github.com/hyperledger/fabric/common/metadata"
2314
"github.com/spf13/cobra"
2415
)
2516

17+
// Program name
18+
const ProgramName = "peer"
19+
2620
// Cmd returns the Cobra Command for Version
2721
func Cmd() *cobra.Command {
2822
return cobraCommand
@@ -33,11 +27,25 @@ var cobraCommand = &cobra.Command{
3327
Short: "Print fabric peer version.",
3428
Long: `Print current version of the fabric peer server.`,
3529
Run: func(cmd *cobra.Command, args []string) {
36-
Print()
30+
fmt.Print(GetInfo())
3731
},
3832
}
3933

40-
// Print outputs the current executable version to stdout
41-
func Print() {
42-
fmt.Printf("Fabric peer server version %s\n", metadata.Version)
34+
// GetInfo returns version information for the peer
35+
func GetInfo() string {
36+
if metadata.Version == "" {
37+
metadata.Version = "development build"
38+
}
39+
40+
ccinfo := fmt.Sprintf(" Base Image Version: %s\n"+
41+
" Base Docker Namespace: %s\n"+
42+
" Base Docker Label: %s\n"+
43+
" Docker Namepace: %s\n",
44+
metadata.BaseVersion, metadata.BaseDockerNamespace,
45+
metadata.BaseDockerLabel, metadata.DockerNamespace)
46+
47+
return fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s\n"+
48+
" Chaincode:\n %s\n",
49+
ProgramName, metadata.Version, runtime.Version(),
50+
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), ccinfo)
4351
}

0 commit comments

Comments
 (0)