Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions samples/deployment/k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ make these images available inside the k8s environment.
With minikube we can easily do that by calling the following commands:

```bash
minikube cache add fpc/ercc:latest
minikube cache add fpc/fpccc:latest
minikube cache add fpc/fpcclient:latest
minikube image load fpc/ercc:latest
minikube image load fpc/fpccc:latest
minikube image load fpc/fpcclient:latest
```

You can double check if the images are available. Please also carefully check if the image ID corresponds to the image you want to use.
Expand Down Expand Up @@ -165,6 +165,7 @@ Show all pods
# list all pods
kubectl get pods -n hyperledger
```
Before moving on ensure that all the pods status appears as running. You might have to wait a while for them to be at that status.

Org1
```bash
Expand Down Expand Up @@ -229,8 +230,8 @@ kubectl exec -it cli_orgX_pod_name bash -n hyperledger
# for all peers of orgX we install ercc and fpccc
export ERCC=ercc-peer0-$ORG; export FPCCC=fpccc-peer0-$ORG

peer lifecycle chaincode install packages/$ERCC.tgz
peer lifecycle chaincode install packages/$FPCCC.tgz
peer lifecycle chaincode install packages/$ERCC.tar.gz
peer lifecycle chaincode install packages/$FPCCC.tar.gz
peer lifecycle chaincode queryinstalled

export ERCC_PKG_ID=$(peer lifecycle chaincode queryinstalled | grep ercc | awk '{print $3}' | sed 's/.$//')
Expand Down
9 changes: 6 additions & 3 deletions samples/deployment/k8s/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,12 @@ chaincode:
# - GOPROXY
externalBuilders:
# FPC Addition 0: external builder for fpc-c chaincode
- path: /builders/external
name: fpc-c
propagateEnvironment:
# - path: /builders/external
# name: fpc-c
- name: ccaas_builder
path: /opt/hyperledger/ccaas_builder
propagateEnvironment:
- CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG
- CORE_PEER_ID
- FPC_HOSTING_MODE
- FABRIC_LOGGING_SPEC
Expand Down
81 changes: 69 additions & 12 deletions samples/deployment/k8s/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
# Copyright IBM Corp. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

C_RESET='\033[0m'
C_RED='\033[0;31m'
C_GREEN='\033[0;32m'
C_BLUE='\033[0;34m'
C_YELLOW='\033[1;33m'
# successln echos in green color
function successln() {
println "${C_GREEN}${1}${C_RESET}"
}
# println echos string
function println() {
echo -e "$1"
}
set -euo pipefail

if [[ -z "${FPC_PATH}" ]]; then
Expand All @@ -19,9 +32,10 @@ cryptoConfigDir="${outDir}/crypto-config"
channelArtifactsDir="${outDir}/channel-artifacts"
packageDir="${outDir}/packages"


CHAINCODE_SERVER_PORT=9999

FABRIC_BIN_DIR="${FABRIC_BIN_DIR:-${FABRIC_PATH}/build/bin}"
FABRIC_BIN_DIR="${FPC_PATH}/fabric/_internal/bin"
if [[ -z "${FABRIC_BIN_DIR}" ]]; then
echo "Error: FABRIC_BIN_DIR not set"
echo "Error: FABRIC_BIN_DIR must point to the location of cryptogen and configtxgen"
Expand All @@ -32,9 +46,9 @@ CRYPPTOGEN_CMD="${FABRIC_BIN_DIR}/cryptogen"
CONFIGTXGEN_CMD="${FABRIC_BIN_DIR}/configtxgen"

echo "Clean existing deployment artifacts"
rm -rf ${cryptoConfigDir}
rm -rf ${channelArtifactsDir}
rm -rf ${packageDir}
rm -rf $cryptoConfigDir
rm -rf $channelArtifactsDir
rm -rf $packageDir

echo "Generate crypto material for orgs"
$CRYPPTOGEN_CMD generate --output=${cryptoConfigDir} --config=./crypto-config.yaml
Expand All @@ -54,7 +68,44 @@ do
done

echo "Package ercc and fpccc"
CC_TYPE="external"
function packageChaincode() {

address="{{.peername}}_${CC_NAME}_ccaas:${CHAINCODE_SERVER_PORT}"
prefix=$(basename "$0")
tempdir=$(mktemp -d -t "$prefix.XXXXXXXX") || error_exit "Error creating temporary directory"
label=${CC_NAME}_${CC_VERSION}
mkdir -p "$tempdir/src"

cat > "$tempdir/src/connection.json" <<CONN_EOF
{
"address": "${address}",
"dial_timeout": "10s",
"tls_required": false
}
CONN_EOF

mkdir -p "$tempdir/pkg"

cat << METADATA-EOF > "$tempdir/pkg/metadata.json"
{
"type": "ccaas",
"label": "$label"
}
METADATA-EOF

tar -C "$tempdir/src" -czf "$tempdir/pkg/code.tar.gz" .
tar -C "$tempdir/pkg" -czf "$CC_NAME-$peer.tar.gz" metadata.json code.tar.gz
rm -Rf "$tempdir"

# PACKAGE_ID=$(peer lifecycle chaincode calculatepackageid ${CC_NAME}.tar.gz)
# commenting due to the network not yet being setup to calculate package_id

mv $CC_NAME-$1.tar.gz $packageDir
successln "Chaincode is packaged ${address} and in ${packageDir}/${CC_NAME}-${1}.tar.gz"

}

CC_TYPE="ccaas"
ERCC_ID="ercc"
ERCC_VER="1.0"
FPCCC_ID="fpccc"
Expand All @@ -66,19 +117,25 @@ if [[ -z "${TEST_CC_PATH}" ]]; then
fi

FPC_MRENCLAVE="$(cat "${FPCCC_PATH}"/_build/lib/mrenclave)"

mkdir $packageDir
for peer in $(shopt -s globstar; find ${cryptoConfigDir}/**/peers/ -mindepth 1 -maxdepth 1 -execdir echo {} ';' | sed 's/^\.\///g');
do
# ercc
endpoint="${ERCC_ID}-${peer}:${CHAINCODE_SERVER_PORT}"
packageName="${ERCC_ID}-${peer}.tgz"
packageChaincode "${packageDir}" "${packageName}" "${ERCC_ID}" "${ERCC_VER}" "${CC_TYPE}" "${endpoint}" "${peer}"
CC_NAME="${ERCC_ID}"
CC_VERSION=$ERCC_VER
# endpoint="${ERCC_ID}-${peer}:${CHAINCODE_SERVER_PORT}"
# packageName="${ERCC_ID}-${peer}.tgz"
# packageChaincode "${packageDir}" "${packageName}" "${ERCC_ID}" "${ERCC_VER}" "${CC_TYPE}" "${endpoint}" "${peer}"
packageChaincode "${peer}"

# fpc cc
endpoint="${FPCCC_ID}-${peer}:${CHAINCODE_SERVER_PORT}"
packageName="${FPCCC_ID}-${peer}.tgz"
packageChaincode "${packageDir}" "${packageName}" "${FPCCC_ID}" "${FPC_MRENCLAVE}" "${CC_TYPE}" "${endpoint}" "${peer}"
CC_NAME="${FPCCC_ID}"
# endpoint="${FPCCC_ID}-${peer}:${CHAINCODE_SERVER_PORT}"
# packageName="${FPCCC_ID}-${peer}.tgz"
# packageChaincode "${packageDir}" "${packageName}" "${FPCCC_ID}" "${FPC_MRENCLAVE}" "${CC_TYPE}" "${endpoint}" "${peer}"
packageChaincode "${peer}"
done


echo "Store mrenclave for fpccc"
echo "FPC_MRENCLAVE=${FPC_MRENCLAVE}" >> ${packageDir}/chaincode-config.properties
3 changes: 3 additions & 0 deletions samples/deployment/k8s/org1/org1-fpcclient-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ spec:
- mountPath: /opt/gopath/src/github.com/hyperledger/fabric-private-chaincode/
name: fpc-claim
workingDir: /opt/gopath/src/github.com/hyperledger/fabric/peer
# nodeSelector:
# kubernetes.io/arch: amd64
# test to see if minikube can start a docker amd64 image even though it is running arm64
restartPolicy: Always
volumes:
- name: fpcclient-claim3
Expand Down
14 changes: 8 additions & 6 deletions samples/deployment/k8s/org1/org1-peer0-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ spec:
value: 0.0.0.0:9443
- name: CORE_METRICS_PROVIDER
value: prometheus
- name: CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG
value: "{\"peername\":\"peer0org1\"}"
image: hyperledger/fabric-peer:2.5.9
name: peer0
ports:
Expand All @@ -74,8 +76,8 @@ spec:
- mountPath: /etc/hyperledger/fabric/core.yaml
name: peer0-config
subPath: core.yaml
- mountPath: /builders/external/bin/
name: external-builder
# - mountPath: /builders/external/bin/
# name: external-builder
restartPolicy: Always
volumes:
- name: peer0-org1-claim1
Expand All @@ -96,10 +98,10 @@ spec:
items:
- key: core.yaml
path: core.yaml
- name: external-builder
hostPath:
path: /fpc/fabric/externalBuilder/chaincode_server/bin
type: Directory
# - name: external-builder
# hostPath:
# path: /fpc/fabric/externalBuilder/chaincode_server/bin
# type: Directory
---
apiVersion: v1
kind: Service
Expand Down
14 changes: 8 additions & 6 deletions samples/deployment/k8s/org2/org2-peer0-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ spec:
value: 0.0.0.0:9443
- name: CORE_METRICS_PROVIDER
value: prometheus
- name: CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG
value: "{\"peername\":\"peer0org2\"}"
image: hyperledger/fabric-peer:2.5.9
name: peer0
ports:
Expand All @@ -74,8 +76,8 @@ spec:
- mountPath: /etc/hyperledger/fabric/core.yaml
name: peer0-config
subPath: core.yaml
- mountPath: /builders/external/bin/
name: external-builder
# - mountPath: /builders/external/bin/
# name: external-builder
restartPolicy: Always
volumes:
- name: peer0-org2-claim1
Expand All @@ -96,10 +98,10 @@ spec:
items:
- key: core.yaml
path: core.yaml
- name: external-builder
hostPath:
path: /fpc/fabric/externalBuilder/chaincode_server/bin
type: Directory
# - name: external-builder
# hostPath:
# path: /fpc/fabric/externalBuilder/chaincode_server/bin
# type: Directory
---
apiVersion: v1
kind: Service
Expand Down
14 changes: 8 additions & 6 deletions samples/deployment/k8s/org3/org3-peer0-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ spec:
value: 0.0.0.0:9443
- name: CORE_METRICS_PROVIDER
value: prometheus
- name: CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG
value: "{\"peername\":\"peer0org3\"}"
image: hyperledger/fabric-peer:2.5.9
name: peer0
ports:
Expand All @@ -74,8 +76,8 @@ spec:
- mountPath: /etc/hyperledger/fabric/core.yaml
name: peer0-config
subPath: core.yaml
- mountPath: /builders/external/bin/
name: external-builder
# - mountPath: /builders/external/bin/
# name: external-builder
restartPolicy: Always
volumes:
- name: peer0-org3-claim1
Expand All @@ -96,10 +98,10 @@ spec:
items:
- key: core.yaml
path: core.yaml
- name: external-builder
hostPath:
path: /fpc/fabric/externalBuilder/chaincode_server/bin
type: Directory
# - name: external-builder
# hostPath:
# path: /fpc/fabric/externalBuilder/chaincode_server/bin
# type: Directory
---
apiVersion: v1
kind: Service
Expand Down
4 changes: 2 additions & 2 deletions samples/deployment/k8s/scripts/installCC.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ set -euo pipefail
ERCC=ercc-peer0-$ORG
FPCCC=fpccc-peer0-$ORG

peer lifecycle chaincode install packages/$ERCC.tgz
peer lifecycle chaincode install packages/$FPCCC.tgz
peer lifecycle chaincode install packages/$ERCC.tar.gz
peer lifecycle chaincode install packages/$FPCCC.tar.gz
peer lifecycle chaincode queryinstalled

ERCC_PKG_ID=$(peer lifecycle chaincode queryinstalled | grep ercc | awk '{print $3}' | sed 's/.$//')
Expand Down