Skip to content

Commit

Permalink
[FAB-17431] Decouple javaenv from Fabric version
Browse files Browse the repository at this point in the history
By default Fabric was configured to use the following javaenv image for java chaincode:
runtime: $(DOCKER_NS)/fabric-javaenv:$(ARCH)-$(PROJECT_VERSION)

Since javaenv versioning may deviate from Fabric versioning,
it is important to decouple the versions. This commit updates
the javaenv reference to use the latest two digit version:
runtime: $(DOCKER_NS)/fabric-javaenv:$(TWO_DIGIT_VERSION)

For example, Fabric v1.4.5 would utilize fabric-javaenv:1.4.

This is a backport of the two digit change in master, applied to javaenv.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
  • Loading branch information
denyeart committed Feb 25, 2020
1 parent ac6305e commit 29c58ac
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/chaincode/chaincodetest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ chaincode:
# tools added for java shim layer packaging.
# This image is packed with shim layer libraries that are necessary
# for Java chaincode runtime.
runtime: $(DOCKER_NS)/fabric-javaenv:$(ARCH)-$(PROJECT_VERSION)
runtime: $(DOCKER_NS)/fabric-javaenv:$(TWO_DIGIT_VERSION)

# timeout in millisecs for starting up a container and waiting for Register
# to come through. 1sec should be plenty for chaincode unit tests
Expand Down
10 changes: 10 additions & 0 deletions core/container/util/dockerutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,23 @@ func ParseDockerfileTemplate(template string) string {
r := strings.NewReplacer(
"$(ARCH)", runtime.GOARCH,
"$(PROJECT_VERSION)", metadata.Version,
"$(TWO_DIGIT_VERSION)", twoDigitVersion(metadata.Version),
"$(BASE_VERSION)", metadata.BaseVersion,
"$(DOCKER_NS)", metadata.DockerNamespace,
"$(BASE_DOCKER_NS)", metadata.BaseDockerNamespace)

return r.Replace(template)
}

// twoDigitVersion truncates a 3 digit version (e.g. 2.0.0) to a 2 digit version (e.g. 2.0),
// If version does not include dots (e.g. latest), just return the passed version
func twoDigitVersion(version string) string {
if strings.LastIndex(version, ".") < 0 {
return version
}
return version[0:strings.LastIndex(version, ".")]
}

func GetDockerfileFromConfig(path string) string {
return ParseDockerfileTemplate(viper.GetString(path))
}
20 changes: 19 additions & 1 deletion core/container/util/dockerutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,34 @@ func TestUtil_DockerfileTemplateParser(t *testing.T) {
}

func TestUtil_GetDockerfileFromConfig(t *testing.T) {
expected := "FROM " + metadata.DockerNamespace + ":" + runtime.GOARCH + "-" + metadata.Version
path := "dt"
expected := "FROM " + metadata.DockerNamespace + ":" + runtime.GOARCH + "-" + metadata.Version
viper.Set(path, "FROM $(DOCKER_NS):$(ARCH)-$(PROJECT_VERSION)")
actual := GetDockerfileFromConfig(path)
assert.Equal(t, expected, actual, "Error parsing Dockerfile Template. Expected \"%s\", got \"%s\"",
expected, actual)

expected = "FROM " + metadata.DockerNamespace + ":" + runtime.GOARCH + "-" + twoDigitVersion(metadata.Version)
viper.Set(path, "FROM $(DOCKER_NS):$(ARCH)-$(TWO_DIGIT_VERSION)")
actual = GetDockerfileFromConfig(path)
assert.Equal(t, expected, actual, "Error parsing Dockerfile Template. Expected \"%s\", got \"%s\"",
expected, actual)
}

func TestUtil_GetDockertClient(t *testing.T) {
viper.Set("vm.endpoint", "unix:///var/run/docker.sock")
_, err := NewDockerClient()
assert.NoError(t, err, "Error getting docker client")
}

func TestTwoDigitVersion(t *testing.T) {
version := "2.0.0"
expected := "2.0"
actual := twoDigitVersion(version)
assert.Equal(t, expected, actual, `Error parsing two digit version. Expected "%s", got "%s"`, expected, actual)

version = "latest"
expected = "latest"
actual = twoDigitVersion(version)
assert.Equal(t, expected, actual, `Error parsing two digit version. Expected "%s", got "%s"`, expected, actual)
}
2 changes: 1 addition & 1 deletion examples/cluster/config/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ chaincode:
# tools added for java shim layer packaging.
# This image is packed with shim layer libraries that are necessary
# for Java chaincode runtime.
runtime: $(DOCKER_NS)/fabric-javaenv:$(ARCH)-$(PROJECT_VERSION)
runtime: $(DOCKER_NS)/fabric-javaenv:$(TWO_DIGIT_VERSION)

# timeout in millisecs for starting up a container and waiting for Register
# to come through. 1sec should be plenty for chaincode unit tests
Expand Down
2 changes: 1 addition & 1 deletion integration/nwo/core_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ chaincode:
car:
runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)
java:
runtime: $(DOCKER_NS)/fabric-javaenv:$(ARCH)-$(PROJECT_VERSION)
runtime: $(DOCKER_NS)/fabric-javaenv:$(TWO_DIGIT_VERSION)
node:
runtime: $(BASE_DOCKER_NS)/fabric-baseimage:$(ARCH)-$(BASE_VERSION)
startuptimeout: 300s
Expand Down
2 changes: 1 addition & 1 deletion sampleconfig/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ chaincode:
# tools added for java shim layer packaging.
# This image is packed with shim layer libraries that are necessary
# for Java chaincode runtime.
runtime: $(DOCKER_NS)/fabric-javaenv:$(ARCH)-$(PROJECT_VERSION)
runtime: $(DOCKER_NS)/fabric-javaenv:$(TWO_DIGIT_VERSION)

node:
# need node.js engine at runtime, currently available in baseimage
Expand Down

0 comments on commit 29c58ac

Please sign in to comment.