fabric-samples/test-network-k8s/scripts/utils.sh
jkneubuh eeb4e611c7
Provide clear guidance for debugging Java chaincode as a service #684 (#724)
* Addresses Issue #548 by providing a simple guide for running Java chaincode as a service with a local debugger.

Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>

* missed a couple of bash syntax errors

Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>

* Add metadata and activate examples to the CC README

Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>

* move ccpackage/ contents into network script

Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>

* Fix CI test - Azure mounts git checkout at a different folder root path

Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>

* Update test-network-k8s README with updated cc deploy commands

Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>

* Run basic-asset transfer CI tests with Java + golang CC in Azure

Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>

* remove (obsolete) test-net chaincode/ folder

Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>

* Address some PR review feedback points - README reorg

Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>

* Use the SDKs contract router Main, not a local entrypoint

Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>

* bump the build - remove trailing newlines from a README

Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>
2022-04-26 15:33:14 +01:00

112 lines
2.4 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#
# Copyright IBM Corp All Rights Reserved
#
# SPDX-License-Identifier: Apache-2.0
#
function logging_init() {
# Reset the output and debug log files
printf '' > ${LOG_FILE} > ${DEBUG_FILE}
# Write all output to the control flow log to STDOUT
tail -f ${LOG_FILE} &
# Call the exit handler when we exit.
trap "exit_fn" EXIT
# Send stdout and stderr from child programs to the debug log file
exec 1>>${DEBUG_FILE} 2>>${DEBUG_FILE}
# There can be a race between the tail starting and the next log statement
sleep 0.5
}
function exit_fn() {
rc=$?
set +x
set +x
# Write an error icon to the current logging statement.
if [ "0" -ne $rc ]; then
pop_fn $rc
fi
# always remove the log trailer when the process exits.
pkill -P $$
}
function push_fn() {
#echo -ne " - entering ${FUNCNAME[1]} with arguments $@"
echo -ne " - $@ ..." >> ${LOG_FILE}
}
function log() {
echo -e $@ >> ${LOG_FILE}
}
function pop_fn() {
# echo exiting ${FUNCNAME[1]}
if [ $# -eq 0 ]; then
echo -ne "\r✅" >> ${LOG_FILE}
echo "" >> ${LOG_FILE}
return
fi
local res=$1
if [ $res -eq 0 ]; then
echo -ne "\r✅" >> ${LOG_FILE}
elif [ $res -eq 1 ]; then
echo -ne "\r⚠" >> ${LOG_FILE}
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
echo "" >> ${LOG_FILE}
}
# Apply the current environment to a k8s template and apply to the cluster.
function apply_template() {
echo "Applying template $1:"
cat $1 | envsubst
cat $1 | envsubst | kubectl -n $NS apply -f -
}
# Set the calling context to refer the peer binary to the correct org / peer instance
#
# todo: Expose the output of this function to a target that prints the context to STDOUT.
#
# e.g.:
# bash $ source $(network set-peer-context org1 peer2)
# bash $ peer chaincode list
# bash $ ...
function export_peer_context() {
local org=$1
local peer=$2
export FABRIC_CFG_PATH=${PWD}/config/${org}
export CORE_PEER_ADDRESS=${org}-${peer}.${DOMAIN}:443
export CORE_PEER_MSPCONFIGPATH=${TEMP_DIR}/enrollments/${org}/users/${org}admin/msp
export CORE_PEER_TLS_ROOTCERT_FILE=${TEMP_DIR}/channel-msp/peerOrganizations/${org}/msp/tlscacerts/tlsca-signcert.pem
}
function absolute_path() {
local relative_path=$1
local abspath="$( cd "${relative_path}" && pwd )"
echo $abspath
}