github.com/IBM-Blockchain/fabric-operator@v1.0.4/sample-network/network (about) 1 #!/bin/bash 2 # 3 # Copyright contributors to the Hyperledger Fabric Operator project 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 # Licensed under the Apache License, Version 2.0 (the "License"); 8 # you may not use this file except in compliance with the License. 9 # You may obtain a copy of the License at: 10 # 11 # http://www.apache.org/licenses/LICENSE-2.0 12 # 13 # Unless required by applicable law or agreed to in writing, software 14 # distributed under the License is distributed on an "AS IS" BASIS, 15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 # See the License for the specific language governing permissions and 17 # limitations under the License. 18 # 19 set -o errexit 20 21 cd "$(dirname "$0")" 22 23 # Set an environment variable based on an optional override (TEST_NETWORK_${name}) 24 # from the calling shell. If the override is not available, assign the parameter 25 # to a default value. 26 function context() { 27 local name=$1 28 local default_value=$2 29 local override_name=TEST_NETWORK_${name} 30 31 export ${name}="${!override_name:-${default_value}}" 32 } 33 34 context FABRIC_VERSION 2.4.4 35 context FABRIC_CA_VERSION 1.5.5 36 37 context CLUSTER_RUNTIME kind # or k3s for Rancher 38 context CONTAINER_CLI docker # or nerdctl for containerd 39 context CONTAINER_NAMESPACE "" # or "--namespace k8s.io" for containerd / nerdctl 40 context STORAGE_CLASS standard 41 context KUSTOMIZE_BUILD "kubectl kustomize" 42 context STAGE_DOCKER_IMAGES false 43 context FABRIC_CONTAINER_REGISTRY hyperledger 44 45 context NAME test-network 46 context NS $NAME 47 context CLUSTER_NAME $CLUSTER_RUNTIME 48 context CLUSTER_IMAGE kindest/node:v1.25.3 # Pin k8s to v1.25.x 49 context KUBE_DNS_DOMAIN ${NS}.svc.cluster.local 50 context INGRESS_DOMAIN localho.st 51 context COREDNS_DOMAIN_OVERRIDE true 52 context LOG_FILE network.log 53 context DEBUG_FILE network-debug.log 54 context LOG_ERROR_LINES 1 55 context USE_LOCAL_REGISTRY true 56 context LOCAL_REGISTRY_NAME kind-registry 57 context LOCAL_REGISTRY_PORT 5000 58 context LOCAL_REGISTRY_INTERFACE 127.0.0.1 59 context NGINX_HTTP_PORT 80 60 context NGINX_HTTPS_PORT 443 61 62 context CONSOLE_DOMAIN ${INGRESS_DOMAIN} 63 context CONSOLE_USERNAME admin 64 context CONSOLE_PASSWORD password 65 66 # TODO: use new cc logic from test-network 67 context CHANNEL_NAME mychannel 68 context ORDERER_TIMEOUT 15s 69 context CHAINCODE_NAME asset-transfer-basic 70 context CHAINCODE_IMAGE ghcr.io/hyperledgendary/fabric-ccaas-asset-transfer-basic:latest 71 context CHAINCODE_LABEL basic_1.0 72 73 context CA_IMAGE ${FABRIC_CONTAINER_REGISTRY}/fabric-ca 74 context CA_IMAGE_LABEL ${FABRIC_CA_VERSION} 75 context PEER_IMAGE ${FABRIC_CONTAINER_REGISTRY}/fabric-peer 76 context PEER_IMAGE_LABEL ${FABRIC_VERSION} 77 context ORDERER_IMAGE ${FABRIC_CONTAINER_REGISTRY}/fabric-orderer 78 context ORDERER_IMAGE_LABEL ${FABRIC_VERSION} 79 context TOOLS_IMAGE ${FABRIC_CONTAINER_REGISTRY}/fabric-tools 80 context TOOLS_IMAGE_LABEL ${FABRIC_VERSION} 81 context OPERATOR_IMAGE ghcr.io/hyperledger-labs/fabric-operator 82 context OPERATOR_IMAGE_LABEL latest-amd64 83 context INIT_IMAGE registry.access.redhat.com/ubi8/ubi-minimal 84 context INIT_IMAGE_LABEL latest 85 context GRPCWEB_IMAGE ghcr.io/hyperledger-labs/grpc-web 86 context GRPCWEB_IMAGE_LABEL latest 87 context COUCHDB_IMAGE couchdb 88 context COUCHDB_IMAGE_LABEL 3.2.2 89 context CONSOLE_IMAGE ghcr.io/hyperledger-labs/fabric-console 90 context CONSOLE_IMAGE_LABEL latest 91 context DEPLOYER_IMAGE ghcr.io/ibm-blockchain/fabric-deployer 92 context DEPLOYER_IMAGE_LABEL latest-amd64 93 94 export FABRIC_OPERATOR_IMAGE=${OPERATOR_IMAGE}:${OPERATOR_IMAGE_LABEL} 95 export FABRIC_CONSOLE_IMAGE=${CONSOLE_IMAGE}:${CONSOLE_IMAGE_LABEL} 96 export FABRIC_DEPLOYER_IMAGE=${DEPLOYER_IMAGE}:${DEPLOYER_IMAGE_LABEL} 97 export FABRIC_CA_IMAGE=${CA_IMAGE}:${CA_IMAGE_LABEL} 98 export FABRIC_PEER_IMAGE=${PEER_IMAGE}:${PEER_IMAGE_LABEL} 99 export FABRIC_ORDERER_IMAGE=${ORDERER_IMAGE}:${ORDERER_IMAGE_LABEL} 100 export FABRIC_TOOLS_IMAGE=${TOOLS_IMAGE}:${TOOLS_IMAGE_LABEL} 101 102 export TEMP_DIR=${PWD}/temp 103 104 105 function print_help() { 106 log 107 log "--- Fabric Information" 108 log "Fabric Version \t\t: ${FABRIC_VERSION}" 109 log "Fabric CA Version \t: ${FABRIC_CA_VERSION}" 110 log "Container Registry \t: ${FABRIC_CONTAINER_REGISTRY}" 111 log "Network name \t\t: ${NAME}" 112 log "Channel name \t\t: ${CHANNEL_NAME}" 113 log 114 log "--- Chaincode Information" 115 log "Chaincode name \t\t: ${CHAINCODE_NAME}" 116 log "Chaincode image \t: ${CHAINCODE_IMAGE}" 117 log "Chaincode label \t: ${CHAINCODE_LABEL}" 118 log 119 log "--- Cluster Information" 120 log "Cluster runtime \t: ${CLUSTER_RUNTIME}" 121 log "Cluster name \t\t: ${CLUSTER_NAME}" 122 log "Cluster namespace \t: ${NS}" 123 log "Fabric Registry \t: ${FABRIC_CONTAINER_REGISTRY}" 124 log "Local Registry \t\t: ${LOCAL_REGISTRY_NAME}" 125 log "Local Registry port \t: ${LOCAL_REGISTRY_PORT}" 126 log "nginx http port \t: ${NGINX_HTTP_PORT}" 127 log "nginx https port \t: ${NGINX_HTTPS_PORT}" 128 log 129 log "--- Script Information" 130 log "Log file \t\t: ${LOG_FILE}" 131 log "Debug log file \t\t: ${DEBUG_FILE}" 132 log 133 134 echo todo: help output, parse mode, flags, env, etc. 135 } 136 137 . scripts/utils.sh 138 . scripts/prereqs.sh 139 . scripts/kind.sh 140 . scripts/cluster.sh 141 . scripts/console.sh 142 . scripts/test_network.sh 143 . scripts/channel.sh 144 . scripts/chaincode.sh 145 146 # check for kind, kubectl, etc. 147 check_prereqs 148 149 # Initialize the logging system - control output to 'network.log' and everything else to 'network-debug.log' 150 logging_init 151 152 ## Parse mode 153 if [[ $# -lt 1 ]] ; then 154 print_help 155 exit 0 156 else 157 MODE=$1 158 shift 159 fi 160 161 if [ "${MODE}" == "kind" ]; then 162 log "Initializing kind cluster \"${CLUSTER_NAME}\":" 163 kind_init 164 log "🏁 - Cluster is ready." 165 166 elif [ "${MODE}" == "unkind" ]; then 167 log "Deleting kind cluster \"${CLUSTER_NAME}\":" 168 kind_unkind 169 log "🏁 - Cluster is gone." 170 171 elif [[ "${MODE}" == "cluster" || "${MODE}" == "k8s" || "${MODE}" == "kube" ]]; then 172 cluster_command_group $@ 173 174 elif [ "${MODE}" == "channel" ]; then 175 channel_command_group $@ 176 177 elif [[ "${MODE}" == "chaincode" || "${MODE}" == "cc" ]]; then 178 chaincode_command_group $@ 179 180 elif [ "${MODE}" == "up" ]; then 181 log "Launching network \"${NAME}\":" 182 network_up 183 log "🏁 - Network is ready." 184 185 elif [ "${MODE}" == "down" ]; then 186 log "Shutting down test network \"${NAME}\":" 187 network_down 188 log "🏁 - Fabric network is down." 189 190 elif [ "${MODE}" == "operator" ]; then 191 log "Launching Fabric operator" 192 launch_operator 193 log "🏁 - Operator is ready." 194 195 elif [ "${MODE}" == "console" ]; then 196 log "Launching Fabric Operations Console" 197 console_up 198 log "🏁 - Console is ready" 199 200 else 201 print_help 202 exit 1 203 fi