Skip to content

Commit

Permalink
Merge "[FAB-2446] label fabric docker images"
Browse files Browse the repository at this point in the history
  • Loading branch information
mastersingh24 authored and Gerrit Code Review committed Feb 25, 2017
2 parents adb66f7 + b38b5a8 commit ea7015e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ BASEIMAGE_RELEASE=$(shell cat ./.baseimage-release)
# defined in common/metadata/metadata.go
METADATA_VAR = Version=$(PROJECT_VERSION)
METADATA_VAR += BaseVersion=$(BASEIMAGE_RELEASE)
METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)

GO_LDFLAGS = $(patsubst %,-X $(PKGNAME)/common/metadata.%,$(METADATA_VAR))

Expand Down Expand Up @@ -221,6 +222,8 @@ build/image/%/Dockerfile: images/%/Dockerfile.in
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $@
@echo LABEL $(BASE_DOCKER_LABEL).version=$(PROJECT_VERSION) \\>>$@
@echo " " $(BASE_DOCKER_LABEL).base.version=$(BASEIMAGE_RELEASE)>>$@

build/image/%/$(DUMMY): Makefile build/image/%/payload build/image/%/Dockerfile
$(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}})
Expand Down
1 change: 1 addition & 0 deletions common/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ package metadata
// Variables defined by the Makefile and passed in with ldflags
var Version string
var BaseVersion string
var BaseDockerLabel string
5 changes: 2 additions & 3 deletions core/chaincode/chaincode_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ func (chaincodeSupport *ChaincodeSupport) getArgsAndEnv(cccid *ccprovider.CCCont
case pb.ChaincodeSpec_GOLANG, pb.ChaincodeSpec_CAR:
//chaincode executable will be same as the name of the chaincode
args = []string{"chaincode", fmt.Sprintf("-peer.address=%s", chaincodeSupport.peerAddress)}
chaincodeLogger.Debugf("Executable is %s", args[0])
case pb.ChaincodeSpec_JAVA:
//TODO add security args
args = strings.Split(
Expand All @@ -366,11 +365,11 @@ func (chaincodeSupport *ChaincodeSupport) getArgsAndEnv(cccid *ccprovider.CCCont
args = append(args, chaincodeSupport.peerTLSSvrHostOrd)
}
}
chaincodeLogger.Debugf("Executable is %s", args[0])
chaincodeLogger.Debugf("Args %v", args)
default:
return nil, nil, fmt.Errorf("Unknown chaincodeType: %s", cLang)
}
chaincodeLogger.Debugf("Executable is %s", args[0])
chaincodeLogger.Debugf("Args %v", args)
return args, envs, nil
}

Expand Down
11 changes: 11 additions & 0 deletions core/chaincode/platforms/platforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"io/ioutil"

"github.com/hyperledger/fabric/common/metadata"
"github.com/hyperledger/fabric/core/chaincode/platforms/car"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
"github.com/hyperledger/fabric/core/chaincode/platforms/java"
Expand Down Expand Up @@ -103,6 +104,15 @@ func generateDockerfile(platform Platform, cds *pb.ChaincodeDeploymentSpec, tls

buf = append(buf, base)

// ----------------------------------------------------------------------------------------------------
// Add some handy labels
// ----------------------------------------------------------------------------------------------------
buf = append(buf, fmt.Sprintf("LABEL %s.chaincode.id.name=\"%s\" \\", metadata.BaseDockerLabel, cds.ChaincodeSpec.ChaincodeId.Name))
buf = append(buf, fmt.Sprintf(" %s.chaincode.id.version=\"%s\" \\", metadata.BaseDockerLabel, cds.ChaincodeSpec.ChaincodeId.Version))
buf = append(buf, fmt.Sprintf(" %s.chaincode.type=\"%s\" \\", metadata.BaseDockerLabel, cds.ChaincodeSpec.Type.String()))
buf = append(buf, fmt.Sprintf(" %s.version=\"%s\" \\", metadata.BaseDockerLabel, metadata.Version))
buf = append(buf, fmt.Sprintf(" %s.base.version=\"%s\"", metadata.BaseDockerLabel, metadata.BaseVersion))

// ----------------------------------------------------------------------------------------------------
// Then augment it with any general options
// ----------------------------------------------------------------------------------------------------
Expand All @@ -117,6 +127,7 @@ func generateDockerfile(platform Platform, cds *pb.ChaincodeDeploymentSpec, tls
// Finalize it
// ----------------------------------------------------------------------------------------------------
contents := strings.Join(buf, "\n")
logger.Debugf("\n%s", contents)

return []byte(contents), nil
}
Expand Down
2 changes: 2 additions & 0 deletions docker-env.mk
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ DBUILD = docker build $(DOCKER_BUILD_FLAGS)
DOCKER_TAG=$(ARCH)-$(PROJECT_VERSION)
BASE_DOCKER_TAG=$(ARCH)-$(BASEIMAGE_RELEASE)

BASE_DOCKER_LABEL=org.hyperledger.fabric

DOCKER_GO_LDFLAGS += $(GO_LDFLAGS)
DOCKER_GO_LDFLAGS += -linkmode external -extldflags '-static -lpthread'

Expand Down

0 comments on commit ea7015e

Please sign in to comment.