Skip to content

Commit

Permalink
FAB-9641 add CommitSHA metadata
Browse files Browse the repository at this point in the history
Added metadata.CommitSHA
Made metadata.Version a const that would be
modified with each MMP release and allow for
binaries to be built that could be released directly
following successful pipeline according to the
stable image strategy.

This also has the side-effect of addressing the issue
raised in FAB-8559 that the fabric-ccenv image might not
be found in CI testing under certain circumstances.

rolling back last two commits... this one works.

Change-Id: Id2f4a172f181c395a2a1b8864c51d1431c3c3230
Signed-off-by: Christopher Ferris <chrisfer@us.ibm.com>
  • Loading branch information
christo4ferris committed Jun 14, 2018
1 parent b1025bf commit db3d76f
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 58 deletions.
22 changes: 9 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ PROJECT_NAME = $(PROJECT_NAME)/fabric
else
PROJECT_NAME = hyperledger/fabric
endif
IS_RELEASE = false
EXPERIMENTAL ?= true

BUILD_DIR ?= .build
Expand All @@ -65,20 +64,17 @@ ifeq ($(EXPERIMENTAL),true)
GO_TAGS += experimental
endif

ifneq ($(IS_RELEASE),true)
EXTRA_VERSION ?= snapshot-$(shell git rev-parse --short HEAD)
PROJECT_VERSION=$(BASE_VERSION)-$(EXTRA_VERSION)
else
PROJECT_VERSION=$(BASE_VERSION)
endif
EXTRA_VERSION ?= $(shell git rev-parse --short HEAD)
PROJECT_VERSION=$(BASE_VERSION)-snapshot-$(EXTRA_VERSION)

PKGNAME = github.com/$(PROJECT_NAME)
CGO_FLAGS = CGO_CFLAGS=" "
ARCH=$(shell go env GOARCH)
MARCH=$(shell go env GOOS)-$(shell go env GOARCH)

# defined in common/metadata/metadata.go
METADATA_VAR = Version=$(PROJECT_VERSION)
METADATA_VAR = Version=$(BASE_VERSION)
METADATA_VAR += CommitSHA=$(EXTRA_VERSION)
METADATA_VAR += BaseVersion=$(BASEIMAGE_RELEASE)
METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)
METADATA_VAR += DockerNamespace=$(DOCKER_NS)
Expand Down Expand Up @@ -162,16 +158,16 @@ orderer: $(BUILD_DIR)/bin/orderer
orderer-docker: $(BUILD_DIR)/image/orderer/$(DUMMY)

.PHONY: configtxgen
configtxgen: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.Version=$(PROJECT_VERSION)
configtxgen: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.CommitSHA=$(EXTRA_VERSION)
configtxgen: $(BUILD_DIR)/bin/configtxgen

configtxlator: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.Version=$(PROJECT_VERSION)
configtxlator: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.CommitSHA=$(EXTRA_VERSION)
configtxlator: $(BUILD_DIR)/bin/configtxlator

cryptogen: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.Version=$(PROJECT_VERSION)
cryptogen: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.CommitSHA=$(EXTRA_VERSION)
cryptogen: $(BUILD_DIR)/bin/cryptogen

idemixgen: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.Version=$(PROJECT_VERSION)
idemixgen: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.CommitSHA=$(EXTRA_VERSION)
idemixgen: $(BUILD_DIR)/bin/idemixgen

tools-docker: $(BUILD_DIR)/image/tools/$(DUMMY)
Expand Down Expand Up @@ -330,7 +326,7 @@ release: $(patsubst %,release/%, $(MARCH))
# builds release packages for all target platforms
release-all: $(patsubst %,release/%, $(RELEASE_PLATFORMS))

release/%: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.Version=$(PROJECT_VERSION)
release/%: GO_LDFLAGS=-X $(pkgmap.$(@F))/metadata.CommitSHA=$(EXTRA_VERSION)

release/windows-amd64: GOOS=windows
release/windows-amd64: $(patsubst %,release/windows-amd64/bin/%, $(RELEASE_PKGS)) release/windows-amd64/install
Expand Down
1 change: 1 addition & 0 deletions common/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package metadata

// Variables defined by the Makefile and passed in with ldflags
var Version string = "latest"
var CommitSHA string = "development build"
var BaseVersion string = "0.4.8"
var BaseDockerLabel string = "org.hyperledger.fabric"
var DockerNamespace string = "hyperledger"
Expand Down
12 changes: 7 additions & 5 deletions common/tools/configtxgen/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ import (
)

// Package version
var Version string
const Version = "1.2.0"

var CommitSHA string

// Program name
const ProgramName = "configtxgen"

func GetVersionInfo() string {
if Version == "" {
Version = "development build"
if CommitSHA == "" {
CommitSHA = "development build"
}

return fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
ProgramName, Version, runtime.Version(),
return fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n OS/Arch: %s",
ProgramName, Version, CommitSHA, runtime.Version(),
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
}
14 changes: 7 additions & 7 deletions common/tools/configtxgen/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ import (
)

func TestGetVersionInfo(t *testing.T) {
testVersions := []string{"", "TestVersion"}
testSHAs := []string{"", "abcdefg"}

for _, version := range testVersions {
metadata.Version = version
if version == "" {
version = "development build"
for _, sha := range testSHAs {
metadata.CommitSHA = sha
if sha == "" {
sha = "development build"
}

expected := fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
metadata.ProgramName, version, runtime.Version(),
expected := fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n OS/Arch: %s",
metadata.ProgramName, metadata.Version, sha, runtime.Version(),
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
assert.Equal(t, expected, metadata.GetVersionInfo())
}
Expand Down
12 changes: 7 additions & 5 deletions common/tools/configtxlator/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ import (
// package-scoped variables

// Package version
var Version string
const Version = "1.2.0"

var CommitSHA string

// package-scoped constants

// Program name
const ProgramName = "configtxlator"

func GetVersionInfo() string {
if Version == "" {
Version = "development build"
if CommitSHA == "" {
CommitSHA = "development build"
}

return fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
ProgramName, Version, runtime.Version(),
return fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n OS/Arch: %s",
ProgramName, Version, CommitSHA, runtime.Version(),
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
}
8 changes: 4 additions & 4 deletions common/tools/configtxlator/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
)

func TestGetVersionInfo(t *testing.T) {
testVersion := "TestVersion"
metadata.Version = testVersion
testSHA := "abcdefg"
metadata.CommitSHA = testSHA

expected := fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
metadata.ProgramName, testVersion, runtime.Version(),
expected := fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n OS/Arch: %s",
metadata.ProgramName, metadata.Version, testSHA, runtime.Version(),
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
assert.Equal(t, expected, metadata.GetVersionInfo())
}
12 changes: 7 additions & 5 deletions common/tools/cryptogen/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ import (
// package-scoped variables

// Package version
var Version string
const Version = "1.2.0"

var CommitSHA string

// package-scoped constants

// Program name
const ProgramName = "cryptogen"

func GetVersionInfo() string {
if Version == "" {
Version = "development build"
if CommitSHA == "" {
CommitSHA = "development build"
}

return fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
ProgramName, Version, runtime.Version(),
return fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n OS/Arch: %s",
ProgramName, Version, CommitSHA, runtime.Version(),
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
}
8 changes: 4 additions & 4 deletions common/tools/cryptogen/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
)

func TestGetVersionInfo(t *testing.T) {
testVersion := "TestVersion"
metadata.Version = testVersion
testSHA := "abcdefg"
metadata.CommitSHA = testSHA

expected := fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
metadata.ProgramName, testVersion, runtime.Version(),
expected := fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n OS/Arch: %s",
metadata.ProgramName, metadata.Version, testSHA, runtime.Version(),
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
assert.Equal(t, expected, metadata.GetVersionInfo())
}
12 changes: 7 additions & 5 deletions common/tools/idemixgen/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ import (
)

// Package version
var Version string
const Version = "1.2.0"

var CommitSHA string

// Program name
const ProgramName = "idemixgen"

func GetVersionInfo() string {
if Version == "" {
Version = "1.2.0-dev"
if CommitSHA == "" {
CommitSHA = "development build"
}

return fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
ProgramName, Version, runtime.Version(),
return fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n OS/Arch: %s",
ProgramName, Version, CommitSHA, runtime.Version(),
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
}
8 changes: 4 additions & 4 deletions common/tools/idemixgen/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
)

func TestGetVersionInfo(t *testing.T) {
testVersion := "TestVersion"
metadata.Version = testVersion
testSHA := "abcdefg"
metadata.CommitSHA = testSHA

expected := fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s",
metadata.ProgramName, testVersion, runtime.Version(),
expected := fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n OS/Arch: %s",
metadata.ProgramName, metadata.Version, testSHA, runtime.Version(),
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
assert.Equal(t, expected, metadata.GetVersionInfo())
}
6 changes: 4 additions & 2 deletions orderer/common/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ func GetVersionInfo() string {
Version = "development build"
}

return fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s\n"+
" Experimental features: %s\n", ProgramName, Version, runtime.Version(),
return fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n"+
" Go version: %s\n OS/Arch: %s\n"+
" Experimental features: %s\n", ProgramName, Version, common.CommitSHA,
runtime.Version(),
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), common.Experimental)
}
3 changes: 2 additions & 1 deletion orderer/common/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ func TestGetVersionInfo(t *testing.T) {
common.Version = "testVersion"
}

expected := fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s\n"+
expected := fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n OS/Arch: %s\n"+
" Experimental features: %s\n", metadata.ProgramName, common.Version,
common.CommitSHA,
runtime.Version(), fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
common.Experimental)
assert.Equal(t, expected, metadata.GetVersionInfo())
Expand Down
5 changes: 3 additions & 2 deletions peer/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ func GetInfo() string {
metadata.BaseVersion, metadata.BaseDockerNamespace,
metadata.BaseDockerLabel, metadata.DockerNamespace)

return fmt.Sprintf("%s:\n Version: %s\n Go version: %s\n OS/Arch: %s\n"+
return fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n"+
" OS/Arch: %s\n"+
" Experimental features: %s\n Chaincode:\n %s\n",
ProgramName, metadata.Version, runtime.Version(),
ProgramName, metadata.Version, metadata.CommitSHA, runtime.Version(),
fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
metadata.Experimental, ccinfo)
}
2 changes: 1 addition & 1 deletion sampleconfig/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ chaincode:
name:

# Generic builder environment, suitable for most chaincode types
builder: $(DOCKER_NS)/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)
builder: $(DOCKER_NS)/fabric-ccenv:latest

# Enables/disables force pulling of the base docker images (listed below)
# during user chaincode instantiation.
Expand Down

0 comments on commit db3d76f

Please sign in to comment.