From ab19b8e01dcb50ce767aee35925bb67839772628 Mon Sep 17 00:00:00 2001 From: jkneubuh <86427252+jkneubuh@users.noreply.github.com> Date: Fri, 19 Nov 2021 11:09:58 -0500 Subject: [PATCH] Address Issue #511 with docs and better error handling (#533) * Address Issue #511 with docs and better error handling Signed-off-by: Josh Kneubuhl * Set the TEST_NETWORK_FABRIC_VERSION in documentation for local development. Signed-off-by: Josh Kneubuhl --- test-network-k8s/docs/KUBERNETES.md | 39 ++++++++++++++++++++++++++- test-network-k8s/network | 4 ++- test-network-k8s/scripts/chaincode.sh | 3 ++- test-network-k8s/scripts/utils.sh | 10 +++++-- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/test-network-k8s/docs/KUBERNETES.md b/test-network-k8s/docs/KUBERNETES.md index 6472e1cf..6570cebd 100644 --- a/test-network-k8s/docs/KUBERNETES.md +++ b/test-network-k8s/docs/KUBERNETES.md @@ -131,8 +131,45 @@ to Pods deployed to the local cluster. For dev/test/CI based flows using an external registry, the traditional Kubernetes practice of [Adding ImagePullSecrets to a service account](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#add-imagepullsecrets-to-a-service-account) -still applies. +still applies. +In some environments, KIND may encounter issues loading the Fabric docker images from the public container +registries. In addition, for Fabric development it can be advantageous to work with Docker images built +locally, bypassing the public images entirely. For these scenarios, images may also be [directly loaded](https://kind.sigs.k8s.io/docs/user/quick-start/#loading-an-image-into-your-cluster) +into the KIND image plane, bypassing the container registry. + +The `./network` script supports these additional modes via: + +1. For network-constrained environments, pull all images to the local docker cache and load to KIND: +```shell +export TEST_NETWORK_STAGE_DOCKER_IMAGES=true + +./network kind +./network up +``` + +2. For alternate registries (e.g. local or Fabric CI/CD builds): +```shell +./network kind + +export TEST_NETWORK_FABRIC_CONTAINER_REGISTRY=hyperledger-fabric.jfrog.io +export TEST_NETWORK_FABRIC_VERSION=amd64-latest +export TEST_NETWORK_FABRIC_CA_VERSION=amd64-latest + +./network up +``` + +3. For working with Fabric images built locally: +```shell +./network kind + +make docker # in hyperledger/fabric + +export TEST_NETWORK_FABRIC_VERSION=2.4.0 + +./network load-images +./network up +``` ## Cloud Vendors diff --git a/test-network-k8s/network b/test-network-k8s/network index f0f34a77..7836f1fe 100755 --- a/test-network-k8s/network +++ b/test-network-k8s/network @@ -35,7 +35,7 @@ STAGE_DOCKER_IMAGES=${TEST_NETWORK_STAGE_DOCKER_IMAGES:-false} NGINX_HTTP_PORT=${TEST_NETWORK_INGRESS_HTTP_PORT:-80} NGINX_HTTPS_PORT=${TEST_NETWORK_INGRESS_HTTPS_PORT:-443} CHAINCODE_NAME=${TEST_NETWORK_CHAINCODE_NAME:-asset-transfer-basic} -CHAINCODE_IMAGE=${TEST_NETWORK_CHAINCODE_IMAGE:-localhost:5000/fabric-ccaas-asset-transfer-basic} +CHAINCODE_IMAGE=${TEST_NETWORK_CHAINCODE_IMAGE:-ghcr.io/hyperledgendary/fabric-ccaas-asset-transfer-basic:latest} CHAINCODE_LABEL=${TEST_NETWORK_CHAINCODE_LABEL:-basic_1.0} # todo: more complicated config, as these bleed into the yaml descriptors (sed? kustomize? helm (no)? tkn? ansible?...) or other script locations @@ -59,6 +59,7 @@ function print_help() { log "--- Cluster Information" log "Cluster name \t\t: ${CLUSTER_NAME}" log "Cluster namespace \t: ${NS}" + log "Fabric Registry \t: ${FABRIC_CONTAINER_REGISTRY}" log "Local Registry \t\t: ${LOCAL_REGISTRY_NAME}" log "Local Registry port \t: ${LOCAL_REGISTRY_PORT}" log "nginx http port \t: ${NGINX_HTTP_PORT}" @@ -70,6 +71,7 @@ function print_help() { log + echo todo: help output, parse mode, flags, env, etc. } diff --git a/test-network-k8s/scripts/chaincode.sh b/test-network-k8s/scripts/chaincode.sh index cb066188..a4f8f691 100755 --- a/test-network-k8s/scripts/chaincode.sh +++ b/test-network-k8s/scripts/chaincode.sh @@ -154,7 +154,8 @@ function invoke_chaincode() { # Normally the chaincode ID is emitted by the peer install command. In this case, we'll generate the # package ID as the sha-256 checksum of the chaincode archive. function set_chaincode_id() { - local cc_sha256=$(shasum -a 256 build/chaincode/${CHAINCODE_NAME}.tgz | tr -s ' ' | cut -d ' ' -f 1) + local cc_package=build/chaincode/${CHAINCODE_NAME}.tgz + cc_sha256=$(shasum -a 256 ${cc_package} | tr -s ' ' | cut -d ' ' -f 1) CHAINCODE_ID=${CHAINCODE_LABEL}:${cc_sha256} } diff --git a/test-network-k8s/scripts/utils.sh b/test-network-k8s/scripts/utils.sh index b777865c..14f4697b 100644 --- a/test-network-k8s/scripts/utils.sh +++ b/test-network-k8s/scripts/utils.sh @@ -47,11 +47,14 @@ function log() { function pop_fn() { # echo exiting ${FUNCNAME[1]} - local res=$1 if [ $# -eq 0 ]; then echo -ne "\r✅" >> ${LOG_FILE} + echo "" >> ${LOG_FILE} + return + fi - elif [ $res -eq 0 ]; then + local res=$1 + if [ $res -eq 0 ]; then echo -ne "\r✅" >> ${LOG_FILE} elif [ $res -eq 1 ]; then @@ -60,6 +63,9 @@ function pop_fn() { elif [ $res -eq 2 ]; then echo -ne "\r☠️" >> ${LOG_FILE} + elif [ $res -eq 127 ]; then + echo -ne "\r☠️" >> ${LOG_FILE} + else echo -ne "\r" >> ${LOG_FILE} fi