Skip to content

Commit

Permalink
Update Go to v1.16.7 and alpine to 3.14 (release-2.2)
Browse files Browse the repository at this point in the history
Go module support is assumed starting in Go v1.16.
Therefore, for chaincodes without go modules (such as in the integration tests),
need to explicitly set GO111MODULE to off otherwise chaincode will not compile.
See Go v1.16 release notes for more details: https://golang.org/doc/go1.16#go-command

As part of troubleshooting the Go upgrade, also added debug for the chaincode
compile command.

Also update alpine to 3.14.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
  • Loading branch information
denyeart authored and ale-linux committed Aug 31, 2021
1 parent 851f838 commit 1eedcff
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# - unit-test - runs the go-test based unit tests
# - verify - runs unit tests for only the changed package tree

ALPINE_VER ?= 3.12
ALPINE_VER ?= 3.14
BASE_VERSION = 2.2.3

# 3rd party image version
Expand Down Expand Up @@ -76,7 +76,7 @@ METADATA_VAR += CommitSHA=$(EXTRA_VERSION)
METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)
METADATA_VAR += DockerNamespace=$(DOCKER_NS)

GO_VER = 1.15.7
GO_VER = 1.16.7
GO_TAGS ?=

RELEASE_EXES = orderer $(TOOLS_EXES)
Expand Down
2 changes: 1 addition & 1 deletion ci/azure-pipelines-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pr: none
variables:
GOPATH: $(Agent.BuildDirectory)/go
PATH: $(Agent.BuildDirectory)/go/bin:/usr/local/go/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
GOVER: 1.15.7
GOVER: 1.16.7

jobs:
- job: UnitTests
Expand Down
2 changes: 1 addition & 1 deletion ci/azure-pipelines-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ variables:
- name: GOPATH
value: $(Agent.BuildDirectory)/go
- name: GOVER
value: 1.15.7
value: 1.16.7

stages:
- stage: BuildBinaries
Expand Down
2 changes: 1 addition & 1 deletion ci/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pr:
variables:
GOPATH: $(Agent.BuildDirectory)/go
PATH: $(Agent.BuildDirectory)/go/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
GOVER: 1.15.7
GOVER: 1.16.7

stages:
- stage: VerifyBuild
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/platforms/golang/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ elif [ -f "/chaincode/input/src/%[2]s/go.mod" ]; then
cd /chaincode/input/src/%[2]s
GO111MODULE=on go build -v -mod=readonly %[1]s -o /chaincode/output/chaincode .
else
GOPATH=/chaincode/input:$GOPATH go build -v %[1]s -o /chaincode/output/chaincode %[2]s
GO111MODULE=off GOPATH=/chaincode/input:$GOPATH go build -v %[1]s -o /chaincode/output/chaincode %[2]s
fi
echo Done!
`
Expand Down
4 changes: 2 additions & 2 deletions core/chaincode/platforms/golang/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ elif [ -f "/chaincode/input/src/the-path/go.mod" ]; then
cd /chaincode/input/src/the-path
GO111MODULE=on go build -v -mod=readonly -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode .
else
GOPATH=/chaincode/input:$GOPATH go build -v -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode the-path
GO111MODULE=off GOPATH=/chaincode/input:$GOPATH go build -v -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode the-path
fi
echo Done!
`,
Expand Down Expand Up @@ -420,7 +420,7 @@ elif [ -f "/chaincode/input/src/the-path/go.mod" ]; then
cd /chaincode/input/src/the-path
GO111MODULE=on go build -v -mod=readonly -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode .
else
GOPATH=/chaincode/input:$GOPATH go build -v -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode the-path
GO111MODULE=off GOPATH=/chaincode/input:$GOPATH go build -v -ldflags "-linkmode external -extldflags '-static'" -o /chaincode/output/chaincode the-path
fi
echo Done!
`,
Expand Down
7 changes: 6 additions & 1 deletion core/chaincode/platforms/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ type DockerBuildOptions struct {
OutputStream io.Writer
}

func (dbo DockerBuildOptions) String() string {
return fmt.Sprintf("Image=%s Env=%s Cmd=%s)", dbo.Image, dbo.Env, dbo.Cmd)
}

//-------------------------------------------------------------------------------------------
// DockerBuild
//-------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -60,7 +64,7 @@ func DockerBuild(opts DockerBuildOptions, client *docker.Client) error {
}
}

logger.Debugf("Attempting build with image %s", opts.Image)
logger.Debugf("Attempting build with options: %s", opts)

//-----------------------------------------------------------------------------------
// Ensure the image exists locally, or pull it from a registry if it doesn't
Expand Down Expand Up @@ -145,6 +149,7 @@ func DockerBuild(opts DockerBuildOptions, client *docker.Client) error {
}

if retval > 0 {
logger.Errorf("Docker build failed using options: %s", opts)
return fmt.Errorf("Error returned from build: %d \"%s\"", retval, stdout.String())
}

Expand Down
12 changes: 12 additions & 0 deletions core/chaincode/platforms/util/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,15 @@ func TestTwoDigitVersion(t *testing.T) {
actual = twoDigitVersion(version)
assert.Equal(t, expected, actual, `Error parsing two digit version. Expected "%s", got "%s"`, expected, actual)
}

func TestDockerBuildOptions(t *testing.T) {
buildOptions := DockerBuildOptions{
Image: "imageName",
Cmd: "theCommand",
Env: []string{"ENV_VARIABLE"},
}

actualBuildOptionsString := buildOptions.String()
expectedBuildOptionsString := "Image=imageName Env=[ENV_VARIABLE] Cmd=theCommand)"
assert.Equal(t, expectedBuildOptionsString, actualBuildOptionsString, `Expected "%s", got "%s"`, expectedBuildOptionsString, actualBuildOptionsString)
}
2 changes: 1 addition & 1 deletion vagrant/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# SPDX-License-Identifier: Apache-2.0

GOROOT='/opt/go'
GO_VERSION=1.15.7
GO_VERSION=1.16.7

# ----------------------------------------------------------------
# Install Golang
Expand Down

0 comments on commit 1eedcff

Please sign in to comment.