Skip to content

Commit

Permalink
Changes to the test-network k8s deployment to use the
Browse files Browse the repository at this point in the history
built-in as-a-service chaincode builder from the Peer Container

Signed-off-by: Matthew B White <[email protected]>
  • Loading branch information
mbwhite committed Dec 10, 2021
1 parent 72559df commit 059a1d0
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"address": "org1-cc-asset-transfer-basic:9999",
"address": "{{.peername}}-cc-asset-transfer-basic:9999",
"dial_timeout": "10s",
"tls_required": false
}
4 changes: 2 additions & 2 deletions test-network-k8s/chaincode/asset-transfer-basic/metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "external",
"type": "ccaas",
"label": "basic_1.0"
}
}
13 changes: 6 additions & 7 deletions test-network-k8s/config/org1/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ vm:
# unix:///var/run/docker.sock
# http://localhost:2375
# https://localhost:2376
endpoint: unix:///var/run/docker.sock
# endpoint: unix:///var/run/docker.sock

# settings for docker vms
docker:
Expand Down Expand Up @@ -558,12 +558,11 @@ chaincode:
# chaincode. The external builder detection processing will iterate over the
# builders in the order specified below.
externalBuilders:
- path: /var/hyperledger/fabric/chaincode/ccs-builder
name: ccs-builder
propagateEnvironment:
- HOME
- CORE_PEER_ID
- CORE_PEER_LOCALMSPID
- name: ccaas_builder
path: /opt/hyperledger/ccaas_builder
propagateEnvironment:
- CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG


# The maximum duration to wait for the chaincode build and install process
# to complete.
Expand Down
12 changes: 5 additions & 7 deletions test-network-k8s/config/org2/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,11 @@ chaincode:
# chaincode. The external builder detection processing will iterate over the
# builders in the order specified below.
externalBuilders:
- path: /var/hyperledger/fabric/chaincode/ccs-builder
name: ccs-builder
propagateEnvironment:
- HOME
- CORE_PEER_ID
- CORE_PEER_LOCALMSPID

- name: ccaas_builder
path: /opt/hyperledger/ccaas_builder
propagateEnvironment:
- CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG

# The maximum duration to wait for the chaincode build and install process
# to complete.
installTimeout: 300s
Expand Down
10 changes: 5 additions & 5 deletions test-network-k8s/kube/org1/org1-cc-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: org1-cc-{{CHAINCODE_NAME}}
name: org1{{PEER_NAME}}-cc-{{CHAINCODE_NAME}}
spec:
replicas: 1
selector:
matchLabels:
app: org1-cc-{{CHAINCODE_NAME}}
app: org1{{PEER_NAME}}-cc-{{CHAINCODE_NAME}}
template:
metadata:
labels:
app: org1-cc-{{CHAINCODE_NAME}}
app: org1{{PEER_NAME}}-cc-{{CHAINCODE_NAME}}
spec:
containers:
- name: main
Expand All @@ -35,11 +35,11 @@ spec:
apiVersion: v1
kind: Service
metadata:
name: org1-cc-{{CHAINCODE_NAME}}
name: org1{{PEER_NAME}}-cc-{{CHAINCODE_NAME}}
spec:
ports:
- name: chaincode
port: 9999
protocol: TCP
selector:
app: org1-cc-{{CHAINCODE_NAME}}
app: org1{{PEER_NAME}}-cc-{{CHAINCODE_NAME}}
19 changes: 2 additions & 17 deletions test-network-k8s/kube/org1/org1-peer1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data:
CORE_OPERATIONS_LISTENADDRESS: 0.0.0.0:9443
CORE_PEER_FILESYSTEMPATH: /var/hyperledger/fabric/data/org1-peer1.org1.example.com
CORE_LEDGER_SNAPSHOTS_ROOTDIR: /var/hyperledger/fabric/data/org1-peer1.org1.example.com/snapshots

CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG: "{\"peername\":\"org1peer1\"}"
---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -61,29 +61,14 @@ spec:
mountPath: /var/hyperledger
- name: fabric-config
mountPath: /var/hyperledger/fabric/config
- name: ccs-builder
mountPath: /var/hyperledger/fabric/chaincode/ccs-builder/bin

# load the external chaincode builder into the peer image prior to peer launch.
initContainers:
- name: fabric-ccs-builder
image: ghcr.io/hyperledgendary/fabric-ccs-builder
imagePullPolicy: IfNotPresent
command: [sh, -c]
args: ["cp /go/bin/* /var/hyperledger/fabric/chaincode/ccs-builder/bin/"]
volumeMounts:
- name: ccs-builder
mountPath: /var/hyperledger/fabric/chaincode/ccs-builder/bin

volumes:
- name: fabric-volume
persistentVolumeClaim:
claimName: fabric-org1
- name: fabric-config
configMap:
name: org1-config
- name: ccs-builder
emptyDir: {}

---
apiVersion: v1
kind: Service
Expand Down
2 changes: 1 addition & 1 deletion test-network-k8s/kube/org1/org1-peer2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data:
CORE_OPERATIONS_LISTENADDRESS: 0.0.0.0:9443
CORE_PEER_FILESYSTEMPATH: /var/hyperledger/fabric/data/org1-peer2.org1.example.com
CORE_LEDGER_SNAPSHOTS_ROOTDIR: /var/hyperledger/fabric/data/org1-peer2.org1.example.com/snapshots

CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG: "{\"peername\":\"org1peer2\"}"
---
apiVersion: apps/v1
kind: Deployment
Expand Down
2 changes: 1 addition & 1 deletion test-network-k8s/kube/org2/org2-peer1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data:
CORE_OPERATIONS_LISTENADDRESS: 0.0.0.0:9443
CORE_PEER_FILESYSTEMPATH: /var/hyperledger/fabric/data/org2-peer1.org2.example.com
CORE_LEDGER_SNAPSHOTS_ROOTDIR: /var/hyperledger/fabric/data/org2-peer1.org2.example.com/snapshots

CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG: "{\"peername\":\"org2peer1\"}"
---
apiVersion: apps/v1
kind: Deployment
Expand Down
2 changes: 1 addition & 1 deletion test-network-k8s/kube/org2/org2-peer2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data:
CORE_OPERATIONS_LISTENADDRESS: 0.0.0.0:9443
CORE_PEER_FILESYSTEMPATH: /var/hyperledger/fabric/data/org2-peer2.org2.example.com
CORE_LEDGER_SNAPSHOTS_ROOTDIR: /var/hyperledger/fabric/data/org2-peer2.org2.example.com/snapshots

CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG: "{\"peername\":\"org2peer2\"}"
---
apiVersion: apps/v1
kind: Deployment
Expand Down
23 changes: 10 additions & 13 deletions test-network-k8s/scripts/chaincode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ function transfer_chaincode_archive_for() {

function install_chaincode_for() {
local org=$1
push_fn "Installing chaincode for org ${org}"
local peer=$2
push_fn "Installing chaincode for org ${org} peer ${peer}"

# Install the chaincode
echo 'set -x
export CORE_PEER_ADDRESS='${org}'-peer1:7051
export CORE_PEER_ADDRESS='${org}'-'${peer}':7051
peer lifecycle chaincode install build/chaincode/'${CHAINCODE_NAME}'.tgz
' | exec kubectl -n $NS exec deploy/${org}-admin-cli -c main -i -- /bin/bash

Expand All @@ -51,6 +52,7 @@ function launch_chaincode_service() {
local org=$1
local cc_id=$2
local cc_image=$3
local peer=$4
push_fn "Launching chaincode container \"${cc_image}\""

# The chaincode endpoint needs to have the generated chaincode ID available in the environment.
Expand All @@ -60,9 +62,10 @@ function launch_chaincode_service() {
| sed 's,{{CHAINCODE_NAME}},'${CHAINCODE_NAME}',g' \
| sed 's,{{CHAINCODE_ID}},'${cc_id}',g' \
| sed 's,{{CHAINCODE_IMAGE}},'${cc_image}',g' \
| sed 's,{{PEER_NAME}},'${peer}',g' \
| exec kubectl -n $NS apply -f -

kubectl -n $NS rollout status deploy/${org}-cc-${CHAINCODE_NAME}
kubectl -n $NS rollout status deploy/${org}${peer}-cc-${CHAINCODE_NAME}

pop_fn
}
Expand Down Expand Up @@ -124,14 +127,6 @@ function query_chaincode_metadata() {
peer chaincode query -n '${CHAINCODE_NAME}' -C '${CHANNEL_NAME}' -c '"'$args'"'
' | exec kubectl -n $NS exec deploy/org1-admin-cli -c main -i -- /bin/bash

log ''
log 'Org1-Peer-SVC:'
echo '
export CORE_PEER_ADDRESS=org1-peer-svc:7051
peer chaincode query -n '${CHAINCODE_NAME}' -C '${CHANNEL_NAME}' -c '"'$args'"'
' | exec kubectl -n $NS exec deploy/org1-admin-cli -c main -i -- /bin/bash


}

function invoke_chaincode() {
Expand Down Expand Up @@ -168,7 +163,8 @@ function install_chaincode() {

package_chaincode_for ${org}
transfer_chaincode_archive_for ${org}
install_chaincode_for ${org}
install_chaincode_for ${org} peer1
install_chaincode_for ${org} peer2

set_chaincode_id
}
Expand All @@ -186,7 +182,8 @@ function deploy_chaincode() {
set -x

install_chaincode
launch_chaincode_service org1 $CHAINCODE_ID $CHAINCODE_IMAGE
launch_chaincode_service org1 $CHAINCODE_ID $CHAINCODE_IMAGE peer1
launch_chaincode_service org1 $CHAINCODE_ID $CHAINCODE_IMAGE peer2
activate_chaincode
}

4 changes: 2 additions & 2 deletions test-network/scripts/deployCC.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ elif [ -z "$CC_SRC_LANGUAGE" ] || [ "$CC_SRC_LANGUAGE" = "NA" ]; then
fatalln "No chaincode language was provided. Valid call example: ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go"

## Make sure that the path to the chaincode exists
elif [ ! -d "$CC_SRC_PATH" ]; then
fatalln "Path to chaincode does not exist. Please provide different path."
elif [ ! -d "$CC_SRC_PATH" ] && [ ! -f "$CC_SRC_PATH" ]; then
fatalln "dfghPath to chaincode does not exist. Please provide different path."
fi

CC_SRC_LANGUAGE=$(echo "$CC_SRC_LANGUAGE" | tr [:upper:] [:lower:])
Expand Down

0 comments on commit 059a1d0

Please sign in to comment.