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 Nov 18, 2021
1 parent 271dfbb commit c82338c
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"address": "org1-cc-asset-transfer-basic:9999",
"address": "org1-{{.peername}}-cc-asset-transfer-basic:9999",
"dial_timeout": "10s",
"tls_required": false
}
10 changes: 4 additions & 6 deletions test-network-k8s/config/org1/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,10 @@ 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
propagateEnvironment:
- CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG
path: /opt/hyperledger/ccaas_builder

# 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
propagateEnvironment:
- CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG
path: /etc/hyperledger/fabric/ccaas_builder

# 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\":\"peer1\"}"
---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -60,29 +60,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\":\"peer2\"}"
---
apiVersion: apps/v1
kind: Deployment
Expand Down
16 changes: 1 addition & 15 deletions 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

EXTERNAL_CHAINCODE_BUILDER_CONFIG: "{\"peername\":\"peer2\"}"
---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -60,20 +60,6 @@ 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:
Expand Down
3 changes: 1 addition & 2 deletions 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

EXTERNAL_CHAINCODE_BUILDER_CONFIG: "{\"peername\":\"peer2\"}"
---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -60,7 +60,6 @@ spec:
mountPath: /var/hyperledger
- name: fabric-config
mountPath: /var/hyperledger/fabric/config

volumes:
- name: fabric-volume
persistentVolumeClaim:
Expand Down
25 changes: 20 additions & 5 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 @@ -111,10 +114,20 @@ function query_chaincode_metadata() {
set -x
local args='{"Args":["org.hyperledger.fabric:GetMetadata"]}'
# todo: mangle additional $@ parameters with bash escape quotations
log 'Peer1:'
echo '
export CORE_PEER_ADDRESS=org1-peer1: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

log ''
log 'Peer2:'
echo '
export CORE_PEER_ADDRESS=org1-peer2: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 @@ -148,7 +161,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 @@ -166,7 +180,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
}

0 comments on commit c82338c

Please sign in to comment.