From 5056a23cbfc8176817435ffca67ed907fbc22e5e Mon Sep 17 00:00:00 2001 From: Wenjian Qiao Date: Fri, 5 Apr 2019 13:15:15 -0400 Subject: [PATCH] [FABN-1184] Add CI script for fabtoken sample app Change-Id: I611d9249c177a8bbc7e36d0406b81eb8e69dfa3e Signed-off-by: Wenjian Qiao --- Jenkinsfile | 21 ++++ scripts/Jenkins_Scripts/CI_Script.sh | 148 --------------------------- scripts/ci_scripts/ciScript.sh | 21 ++++ scripts/ci_scripts/fabtoken.sh | 48 +++++++++ 4 files changed, 90 insertions(+), 148 deletions(-) delete mode 100755 scripts/Jenkins_Scripts/CI_Script.sh create mode 100755 scripts/ci_scripts/fabtoken.sh diff --git a/Jenkinsfile b/Jenkinsfile index 21965e5413..304305ca86 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -136,6 +136,27 @@ } } } + // Run fabtoken tests + stage('Run FabToken Tests') { + steps { + script { + // making the output color coded + wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) { + try { + dir("$ROOTDIR/$BASE_DIR/scripts/ci_scripts") { + // Run fabtoken tests + sh './ciScript.sh --fabtoken_Tests' + } + } + catch (err) { + failure_stage = "fabtoken_Tests" + currentBuild.result = 'FAILURE' + throw err + } + } + } + } + } } // stages post { always { diff --git a/scripts/Jenkins_Scripts/CI_Script.sh b/scripts/Jenkins_Scripts/CI_Script.sh deleted file mode 100755 index 8f1343ab46..0000000000 --- a/scripts/Jenkins_Scripts/CI_Script.sh +++ /dev/null @@ -1,148 +0,0 @@ -#!/bin/bash -e -# -# Copyright IBM Corp All Rights Reserved -# -# SPDX-License-Identifier: Apache-2.0 -# - -# exit on first error - -export BASE_FOLDER=$WORKSPACE/gopath/src/github.com/hyperledger -export NEXUS_URL=nexus3.hyperledger.org:10001 -export ORG_NAME="hyperledger/fabric" - -Parse_Arguments() { - while [ $# -gt 0 ]; do - case $1 in - --env_Info) - env_Info - ;; - --pull_Docker_Images) - pull_Docker_Images - ;; - --pull_Fabric_CA_Images) - pull_Fabric_CA_Images - ;; - --clean_Environment) - clean_Environment - ;; - --byfn_eyfn_Tests) - byfn_eyfn_Tests - ;; - --fabcar_Tests) - fabcar_Tests - ;; - --pull_Thirdparty_Images) - pull_Thirdparty_Images - ;; - esac - shift - done -} - -clean_Environment() { - -echo "-----------> Clean Docker Containers & Images, unused/lefover build artifacts" -function clearContainers () { - CONTAINER_IDS=$(docker ps -aq) - if [ -z "$CONTAINER_IDS" ] || [ "$CONTAINER_IDS" = " " ]; then - echo "---- No containers available for deletion ----" - else - docker rm -f $CONTAINER_IDS || true - docker ps -a - fi -} - -function removeUnwantedImages() { - - for i in $(docker images | grep none | awk '{print $3}'); do - docker rmi ${i} || true - done - - for i in $(docker images | grep -vE ".*baseimage.*(0.4.13|0.4.14)" | grep -vE ".*baseos.*(0.4.13|0.4.14)" | grep -vE ".*couchdb.*(0.4.13|0.4.14)" | grep -vE ".*zoo.*(0.4.13|0.4.14)" | grep -vE ".*kafka.*(0.4.13|0.4.14)" | grep -v "REPOSITORY" | awk '{print $1":" $2}'); do - docker rmi ${i} || true - done -} - -# Remove /tmp/fabric-shim -docker run -v /tmp:/tmp library/alpine rm -rf /tmp/fabric-shim || true - -# remove tmp/hfc and hfc-key-store data -rm -rf /home/jenkins/.nvm /home/jenkins/npm /tmp/fabric-shim /tmp/hfc* /tmp/npm* /home/jenkins/kvsTemp /home/jenkins/.hfc-key-store - -rm -rf /var/hyperledger/* - -rm -rf gopath/src/github.com/hyperledger/fabric-ca/vendor/github.com/cloudflare/cfssl/vendor/github.com/cloudflare/cfssl_trust/ca-bundle || true -# yamllint disable-line rule:line-length -rm -rf gopath/src/github.com/hyperledger/fabric-ca/vendor/github.com/cloudflare/cfssl/vendor/github.com/cloudflare/cfssl_trust/intermediate_ca || true - -clearContainers -removeUnwantedImages -} - -env_Info() { - # This function prints system info - - #### Build Env INFO - echo "-----------> Build Env INFO" - # Output all information about the Jenkins environment - uname -a - cat /etc/*-release - env - gcc --version - docker version - docker info - docker-compose version - pgrep -a docker -} - -# Pull Thirdparty Docker images (kafka, couchdb, zookeeper baseos) -pull_Thirdparty_Images() { - echo "------> BASE_IMAGE_TAG:" $BASE_IMAGE_TAG - for IMAGES in kafka couchdb zookeeper baseos; do - echo "-----------> Pull $IMAGES image" - echo - docker pull $ORG_NAME-$IMAGES:${BASE_IMAGE_TAG} > /dev/null 2>&1 - if [ $? -ne 0 ]; then - echo -e "\033[31m FAILED to pull docker images" "\033[0m" - exit 1 - fi - docker tag $ORG_NAME-$IMAGES:${BASE_IMAGE_TAG} $ORG_NAME-$IMAGES - docker tag $ORG_NAME-$IMAGES:${BASE_IMAGE_TAG} $ORG_NAME-$IMAGES:$VERSION - done - echo - docker images | grep hyperledger/fabric -} -# pull Docker images from nexus -pull_Docker_Images() { - for IMAGES in ca peer orderer tools ccenv nodeenv; do - echo "-----------> pull $IMAGES image" - echo - docker pull $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG > /dev/null 2>&1 - if [ $? -ne 0 ]; then - echo -e "\033[31m FAILED to pull docker images" "\033[0m" - exit 1 - fi - docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES - docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES:$ARCH-$VERSION - docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG $ORG_NAME-$IMAGES:$VERSION - docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG - done - echo - docker images | grep hyperledger/fabric -} -# run byfn,eyfn tests -byfn_eyfn_Tests() { - echo - echo "-----------> Execute Byfn and Eyfn Tests" - ./byfn_eyfn.sh -} -# run fabcar tests -fabcar_Tests() { - echo - echo "npm version ------> $(npm -v)" - echo "node version ------> $(node -v)" - echo "-----------> Execute FabCar Tests" - ./fabcar.sh -} -Parse_Arguments $@ diff --git a/scripts/ci_scripts/ciScript.sh b/scripts/ci_scripts/ciScript.sh index f2edebf10a..8b2ffa03b4 100755 --- a/scripts/ci_scripts/ciScript.sh +++ b/scripts/ci_scripts/ciScript.sh @@ -16,6 +16,9 @@ Parse_Arguments() { --fabcar_Tests) fabcar_Tests ;; + --fabtoken_Tests) + fabtoken_Tests + ;; esac shift done @@ -51,4 +54,22 @@ fabcar_Tests() { ./fabcar.sh } +# run fabtoken tests +fabtoken_Tests() { + + echo " #############################" + echo "npm version ------> $(npm -v)" + echo "node version ------> $(node -v)" + echo " #############################" + + echo + echo " _____ _ ____ _______ __ ___ __ _____ __ __ " + echo " | ___| / \ | __ ) |__ __| / _ \ | | / / | ____| | |\ | | " + echo " | |_ / _ \ | _ \ | | | | | | | |/ / | |___ | | \ | | " + echo " | _| / ___ \ | |_) | | | | |_ | | | |\ \ | ___| | | \ | | " + echo " |_| /_/ \_\ |____/ |_| \ __ / |_| \_\ |_|____ |_| \|_| " + + ./fabtoken.sh +} + Parse_Arguments $@ diff --git a/scripts/ci_scripts/fabtoken.sh b/scripts/ci_scripts/fabtoken.sh new file mode 100755 index 0000000000..336c92cf9e --- /dev/null +++ b/scripts/ci_scripts/fabtoken.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# SPDX-License-Identifier: Apache-2.0 +# + +# docker container list - Check these from basic-network/docker-compose.yaml +CONTAINER_LIST=(peer0.org1 orderer ca) + +logs() { + +for CONTAINER in ${CONTAINER_LIST[*]}; do + docker logs $CONTAINER.example.com >& $WORKSPACE/$CONTAINER-$1.log + echo +done +# Write couchdb container logs into couchdb.log file +docker logs couchdb >& couchdb.log + +} + +copy_logs() { + +# Call logs function +logs $2 $3 + +if [ $1 != 0 ]; then + echo -e "\033[31m $2 test case is FAILED" "\033[0m" + exit 1 +fi +} + +cd $WORKSPACE/$BASE_DIR/fabtoken || exit +export PATH=gopath/src/github.com/hyperledger/fabric-samples/bin:$PATH + +LANGUAGE="javascript" + +echo -e "\033[32m starting fabtoken test (${LANGUAGE})" "\033[0m" +./startFabric.sh +copy_logs $? fabtoken-start-script-${LANGUAGE} + +pushd ${LANGUAGE} +npm install +node fabtoken.js +copy_logs $? fabtoken-${LANGUAGE} +popd + +docker ps -aq | xargs docker rm -f +docker rmi -f $(docker images -aq dev-*) +echo -e "\033[32m finished fabtoken tests (${LANGUAGE})" "\033[0m"