Skip to content

Commit d177119

Browse files
author
Jason Yellick
committed
FAB-14493 Use externalbuilder in basic netwrk test
This creates a sample golang chaincode external builder, and utilizes it in one of the peers in the basic solo end to end test. Change-Id: I336bea3cd9e89b83ec06395fb9d7cd4b35a54389 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 367de92 commit d177119

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

integration/e2e/e2e_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ var _ = Describe("EndToEnd", func() {
9393
})
9494

9595
network.GenerateConfigTree()
96+
97+
// Enable externabuilders for peer0
98+
cwd, err := os.Getwd()
99+
Expect(err).NotTo(HaveOccurred())
100+
peer := network.Peer("Org1", "peer0")
101+
core := network.ReadPeerConfig(peer)
102+
core.Chaincode.ExternalBuilders = []string{filepath.Join(cwd, "..", "externalbuilders", "golang")}
103+
network.WritePeerConfig(peer, core)
104+
96105
network.Bootstrap()
97106

98107
networkRunner := network.NetworkGroupRunner()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# Copyright IBM Corp. All Rights Reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
set -euo pipefail
8+
9+
DIR="${BASH_SOURCE%/*}"
10+
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
11+
. "$DIR/parse.sh"
12+
13+
GOPATH=$SOURCE:$GOPATH go build -o "$OUTPUT/chaincode" -ldflags "-linkmode external -extldflags '-static'" "$GO_PACKAGE_PATH"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# Copyright IBM Corp. All Rights Reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
set -euo pipefail
8+
9+
DIR="${BASH_SOURCE%/*}"
10+
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
11+
. "$DIR/parse.sh"
12+
13+
if [ "$TYPE" = "GOLANG" ] ; then
14+
exit 0
15+
fi
16+
17+
echo "Supported types is only golang -- got type '$TYPE'"
18+
exit 1
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Copyright IBM Corp. All Rights Reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
set -euo pipefail
8+
9+
DIR="${BASH_SOURCE%/*}"
10+
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
11+
. "$DIR/parse.sh"
12+
13+
export CORE_CHAINCODE_ID_NAME="${PACKAGE_ID}"
14+
15+
export CORE_TLS_CLIENT_CERT_PATH="$ARTIFACTS/client.crt"
16+
export CORE_TLS_CLIENT_KEY_PATH="$ARTIFACTS/client.key"
17+
export CORE_PEER_TLS_ROOTCERT_FILE="$ARTIFACTS/root.crt"
18+
19+
jq -r .ClientCert $ARTIFACTS/chaincode.json | base64 --decode > "$CORE_TLS_CLIENT_CERT_PATH"
20+
jq -r .ClientKey $ARTIFACTS/chaincode.json | base64 --decode > "$CORE_TLS_CLIENT_KEY_PATH"
21+
jq -r .RootCert $ARTIFACTS/chaincode.json | base64 --decode > "$CORE_PEER_TLS_ROOTCERT_FILE"
22+
23+
if [ -z "$(cat $CORE_TLS_CLIENT_CERT_PATH)" ] ; then
24+
export CORE_PEER_TLS_ENABLED=false
25+
else
26+
export CORE_PEER_TLS_ENABLED=true
27+
fi
28+
29+
"$OUTPUT/chaincode" -peer.address=$(jq -r .PeerAddress "$ARTIFACTS/chaincode.json") &
30+
31+
PID=$?
32+
33+
sleep 5
34+
35+
disown
36+
37+
kill -0 $PID
38+
exit $?
39+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Copyright IBM Corp. All Rights Reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
while (( "$#" )); do
8+
case "$1" in
9+
--artifacts)
10+
ARTIFACTS=$2
11+
shift 2
12+
;;
13+
"--package-id")
14+
PACKAGE_ID=$2
15+
shift 2
16+
;;
17+
"--path")
18+
GO_PACKAGE_PATH=$2
19+
shift 2
20+
;;
21+
"--type")
22+
TYPE=$2
23+
shift 2
24+
;;
25+
"--source")
26+
SOURCE=$2
27+
shift 2
28+
;;
29+
"--output")
30+
OUTPUT=$2
31+
shift 2
32+
;;
33+
--) # end argument parsing
34+
shift
35+
break
36+
;;
37+
-*|--*=) # unsupported flags
38+
echo "Error: Unsupported flag $1" >&2
39+
exit 1
40+
;;
41+
esac
42+
done

0 commit comments

Comments
 (0)