Skip to content

Commit b38b5a8

Browse files
author
Luis Sanchez
committed
[FAB-2446] label fabric docker images
Enables filtering images and containers to find only chaincode containers using the --filter option. Added to fabric images: - org.hyperledger.fabric.version - org.hyperledger.fabric.base.version Added to chain code images: - org.hyperledger.fabric.chaincode.id.name - org.hyperledger.fabric.chaincode.id.version - org.hyperledger.fabric.chaincode.type Example: docker images \ --filter label=org.hyperledger.fabric.version Change-Id: I4023ee9632cb4dfd56b92f12ea76c21ef6402f21 Signed-off-by: Luis Sanchez <[email protected]>
1 parent 536a3fd commit b38b5a8

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ BASEIMAGE_RELEASE=$(shell cat ./.baseimage-release)
5353
# defined in common/metadata/metadata.go
5454
METADATA_VAR = Version=$(PROJECT_VERSION)
5555
METADATA_VAR += BaseVersion=$(BASEIMAGE_RELEASE)
56+
METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)
5657

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

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

225228
build/image/%/$(DUMMY): Makefile build/image/%/payload build/image/%/Dockerfile
226229
$(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}})

common/metadata/metadata.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ package metadata
1919
// Variables defined by the Makefile and passed in with ldflags
2020
var Version string
2121
var BaseVersion string
22+
var BaseDockerLabel string

core/chaincode/chaincode_support.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ func (chaincodeSupport *ChaincodeSupport) getArgsAndEnv(cccid *ccprovider.CCCont
352352
case pb.ChaincodeSpec_GOLANG, pb.ChaincodeSpec_CAR:
353353
//chaincode executable will be same as the name of the chaincode
354354
args = []string{"chaincode", fmt.Sprintf("-peer.address=%s", chaincodeSupport.peerAddress)}
355-
chaincodeLogger.Debugf("Executable is %s", args[0])
356355
case pb.ChaincodeSpec_JAVA:
357356
//TODO add security args
358357
args = strings.Split(
@@ -366,11 +365,11 @@ func (chaincodeSupport *ChaincodeSupport) getArgsAndEnv(cccid *ccprovider.CCCont
366365
args = append(args, chaincodeSupport.peerTLSSvrHostOrd)
367366
}
368367
}
369-
chaincodeLogger.Debugf("Executable is %s", args[0])
370-
chaincodeLogger.Debugf("Args %v", args)
371368
default:
372369
return nil, nil, fmt.Errorf("Unknown chaincodeType: %s", cLang)
373370
}
371+
chaincodeLogger.Debugf("Executable is %s", args[0])
372+
chaincodeLogger.Debugf("Args %v", args)
374373
return args, envs, nil
375374
}
376375

core/chaincode/platforms/platforms.go

+11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"io/ioutil"
2929

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

104105
buf = append(buf, base)
105106

107+
// ----------------------------------------------------------------------------------------------------
108+
// Add some handy labels
109+
// ----------------------------------------------------------------------------------------------------
110+
buf = append(buf, fmt.Sprintf("LABEL %s.chaincode.id.name=\"%s\" \\", metadata.BaseDockerLabel, cds.ChaincodeSpec.ChaincodeId.Name))
111+
buf = append(buf, fmt.Sprintf(" %s.chaincode.id.version=\"%s\" \\", metadata.BaseDockerLabel, cds.ChaincodeSpec.ChaincodeId.Version))
112+
buf = append(buf, fmt.Sprintf(" %s.chaincode.type=\"%s\" \\", metadata.BaseDockerLabel, cds.ChaincodeSpec.Type.String()))
113+
buf = append(buf, fmt.Sprintf(" %s.version=\"%s\" \\", metadata.BaseDockerLabel, metadata.Version))
114+
buf = append(buf, fmt.Sprintf(" %s.base.version=\"%s\"", metadata.BaseDockerLabel, metadata.BaseVersion))
115+
106116
// ----------------------------------------------------------------------------------------------------
107117
// Then augment it with any general options
108118
// ----------------------------------------------------------------------------------------------------
@@ -117,6 +127,7 @@ func generateDockerfile(platform Platform, cds *pb.ChaincodeDeploymentSpec, tls
117127
// Finalize it
118128
// ----------------------------------------------------------------------------------------------------
119129
contents := strings.Join(buf, "\n")
130+
logger.Debugf("\n%s", contents)
120131

121132
return []byte(contents), nil
122133
}

docker-env.mk

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ DBUILD = docker build $(DOCKER_BUILD_FLAGS)
5656
DOCKER_TAG=$(ARCH)-$(PROJECT_VERSION)
5757
BASE_DOCKER_TAG=$(ARCH)-$(BASEIMAGE_RELEASE)
5858

59+
BASE_DOCKER_LABEL=org.hyperledger.fabric
60+
5961
DOCKER_GO_LDFLAGS += $(GO_LDFLAGS)
6062
DOCKER_GO_LDFLAGS += -linkmode external -extldflags '-static -lpthread'
6163

0 commit comments

Comments
 (0)