Skip to content

Commit

Permalink
Update Go to v1.16.7
Browse files Browse the repository at this point in the history
Update Go to v1.16.7.
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.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
  • Loading branch information
denyeart committed Aug 23, 2021
1 parent 38348fb commit 1fbdc18
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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 @@ -221,7 +221,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 @@ -378,7 +378,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 @@ -419,7 +419,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 @@ -124,3 +124,15 @@ func TestTwoDigitVersion(t *testing.T) {
actual = twoDigitVersion(version)
require.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)"
require.Equal(t, expectedBuildOptionsString, actualBuildOptionsString, `Expected "%s", got "%s"`, expectedBuildOptionsString, actualBuildOptionsString)
}
8 changes: 4 additions & 4 deletions docs/source/prereqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ docker-compose version 1.27.2, build 18f557f9
### Go

Optional: Install the latest version of [Go](https://golang.org/doc/install) if it is not already installed
(only required if you will be writing Go chaincode or SDK applications).
Optional: Install the latest Fabric supported version of [Go](https://golang.org/doc/install) if it is not already
installed (only required if you will be writing Go chaincode or SDK applications).

```shell
$ brew install go
$ brew install go@1.16.7
$ go version
go1.15.7 darwin/amd64
go1.16.7 darwin/amd64
```

### JQ
Expand Down
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 1fbdc18

Please sign in to comment.