Skip to content

Commit

Permalink
Merge "FAB-12608 Update pipeline script"
Browse files Browse the repository at this point in the history
  • Loading branch information
christo4ferris authored and Gerrit Code Review committed Nov 2, 2018
2 parents 24c5e47 + c05f172 commit 1c82113
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 89 deletions.
74 changes: 49 additions & 25 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@
// Pipeline script for fabric-samples

node ('hyp-x') { // trigger build on x86_64 node
timestamps {
try {
def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name>
env.NODE_VER = "8.11.3" // NodeJs version
env.ARCH = "amd64"
env.VERSION = sh(returnStdout: true, script: 'curl -O https://raw.githubusercontent.com/hyperledger/fabric/master/Makefile && cat Makefile | grep "BASE_VERSION =" | cut -d "=" -f2').trim()
env.VERSION = "$VERSION" // BASE_VERSION from fabric Makefile
env.BASE_IMAGE_VER = sh(returnStdout: true, script: 'cat Makefile | grep BASEIMAGE_RELEASE= | cut -d "=" -f2').trim() // BASEIMAGE Version from fabric Makefile
env.IMAGE_TAG = "${ARCH}-${VERSION}-stable" // fabric latest stable version from nexus
env.PROJECT_VERSION = "${VERSION}-stable"
env.BASE_IMAGE_TAG = "${ARCH}-${BASE_IMAGE_VER}" //fabric baseimage version
env.PROJECT_DIR = "gopath/src/github.com/hyperledger"
env.GOPATH = "$WORKSPACE/gopath"
env.PATH = "$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:~/npm/bin:/home/jenkins/.nvm/versions/node/v${NODE_VER}/bin:$PATH"

def failure_stage = "none"
// delete working directory
deleteDir()
Expand All @@ -24,10 +37,11 @@ node ('hyp-x') { // trigger build on x86_64 node
}
catch (err) {
failure_stage = "Fetch patchset"
currentBuild.result = 'FAILURE'
throw err
}
}
// clean environment and get env data
}
// clean environment and get env data
stage("Clean Environment - Get Env Info") {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
Expand All @@ -36,62 +50,72 @@ node ('hyp-x') { // trigger build on x86_64 node
}
catch (err) {
failure_stage = "Clean Environment - Get Env Info"
currentBuild.result = 'FAILURE'
throw err
}
}

}

// Pull Fabric Images
// Pull Third_party Images
stage("Pull third_party images") {
// making the output color coded
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --pull_Thirdparty_Images'
}
}
catch (err) {
failure_stage = "Pull third_party docker images"
currentBuild.result = 'FAILURE'
throw err
}
}
}

// Pull Fabric Images
stage("Pull fabric images") {
// Pull Fabric, fabric-ca Images
stage("Pull Docker images") {
// making the output color coded
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --pull_Fabric_Images'
sh './CI_Script.sh --pull_Docker_Images'
}
}
catch (err) {
failure_stage = "Pull fabric docker images"
failure_stage = "Pull fabric, fabric-ca docker images"
currentBuild.result = 'FAILURE'
throw err
}
}
}

// Pull Fabric-ca
stage("Pull fabric-ca images") {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --pull_Fabric_CA_Image'
}
}
catch (err) {
failure_stage = "Pull fabric-ca docker image"
throw err
}
}
// Run byfn, eyfn tests (default, custom channel, couchdb, nodejs chaincode, fabric-ca samples)
// Run byfn, eyfn tests (default, custom channel, couchdb, nodejs chaincode)
stage("Run byfn_eyfn Tests") {
// making the output color coded
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
try {
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") {
sh './CI_Script.sh --byfn_eyfn_Tests'
}
}
catch (err) {
failure_stage = "byfn_eyfn_Tests"
currentBuild.result = 'FAILURE'
throw err
}
}
}
stage("Archive Build artifacts") {
archiveArtifacts artifacts: '**/*.log'
}
} finally {
// Archive the artifacts
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.log'
// Sends notification to Rocket.Chat jenkins-robot channel
if (env.GERRIT_EVENT_TYPE == 'change-merged') {
if (currentBuild.result == 'FAILURE') { // Other values: SUCCESS, UNSTABLE
rocketSend channel: 'jenkins-robot', message: "Build Notification - STATUS: ${currentBuild.result} - BRANCH: ${env.GERRIT_BRANCH} - PROJECT: ${env.PROJECT} - (<${env.BUILD_URL}|Open>)"
}
}
}
// End Try block
}
// End Node block
}
80 changes: 31 additions & 49 deletions scripts/Jenkins_Scripts/CI_Script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,8 @@
# exit on first error

export BASE_FOLDER=$WORKSPACE/gopath/src/github.com/hyperledger
export PROJECT_VERSION=1.4.0-stable
export NEXUS_URL=nexus3.hyperledger.org:10001
export ORG_NAME="hyperledger/fabric"
export NODE_VER=8.11.3 # Default nodejs version

# Fetch baseimage version
curl -L https://raw.githubusercontent.com/hyperledger/fabric/master/Makefile > Makefile
export BASE_IMAGE_VER=`cat Makefile | grep BASEIMAGE_RELEASE= | cut -d "=" -f2`
echo "-----------> BASE_IMAGE_VER" $BASE_IMAGE_VER
export OS_VER=$(dpkg --print-architecture)
echo "-----------> OS_VER" $OS_VER
export BASE_IMAGE_TAG=$OS_VER-$BASE_IMAGE_VER

# Fetch Go Version from fabric ci.properties file
curl -L https://raw.githubusercontent.com/hyperledger/fabric/master/ci.properties > ci.properties
export GO_VER=`cat ci.properties | grep GO_VER | cut -d "=" -f 2`
echo "-----------> GO_VER" $GO_VER

# Published stable version from nexus
export STABLE_TAG=$OS_VER-$PROJECT_VERSION
echo "-----------> STABLE_TAG" $STABLE_TAG

Parse_Arguments() {
while [ $# -gt 0 ]; do
Expand All @@ -39,11 +20,11 @@ Parse_Arguments() {
--SetGopath)
setGopath
;;
--pull_Fabric_Images)
pull_Fabric_Images
--pull_Docker_Images)
pull_Docker_Images
;;
--pull_Fabric_CA_Image)
pull_Fabric_CA_Image
--pull_Fabric_CA_Images)
pull_Fabric_CA_Images
;;
--clean_Environment)
clean_Environment
Expand Down Expand Up @@ -117,55 +98,56 @@ env_Info() {
docker info
docker-compose version
pgrep -a docker
docker images
docker ps -a
}

setGopath() {
echo "-----------> set GOPATH"
echo
export GOPATH=$WORKSPACE/gopath
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
export PATH=$GOROOT/bin:$GOPATH/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:~/npm/bin:/home/jenkins/.nvm/versions/node/v6.9.5/bin:/home/jenkins/.nvm/versions/node/v$NODE_VER/bin:$PATH
export GOROOT=/opt/go/go$GO_VER.linux.$OS_VER
export PATH=$GOROOT/bin:$PATH
}
# Pull Thirdparty Docker images (Kafka, couchdb, zookeeper)
pull_Thirdparty_Images() {
echo "------> BASE_IMAGE_TAG:" $BASE_IMAGE_TAG
for IMAGES in kafka couchdb zookeeper; do
echo "-----------> Pull $IMAGE image"
echo "-----------> Pull $IMAGES image"
echo
docker pull $ORG_NAME-$IMAGES:$BASE_IMAGE_TAG
docker tag $ORG_NAME-$IMAGES:$BASE_IMAGE_TAG $ORG_NAME-$IMAGES
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
done
echo
docker images | grep hyperledger/fabric
}
# pull fabric images from nexus
pull_Fabric_Images() {
setGopath fabric # set gopath
pull_Docker_Images() {
pull_Fabric_CA_Image
for IMAGES in peer orderer tools ccenv; do
echo "-----------> pull $IMAGES image"
echo
docker pull $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES:$STABLE_TAG
docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG
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:$IMAGE_TAG
docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG
done
echo
docker images | grep hyperledger/fabric
}
# pull fabric-ca images from nexus
pull_Fabric_CA_Image() {
echo
setGopath fabric-ca
echo "------> IMAGE_TAG:" $IMAGE_TAG
for IMAGES in ca ca-peer ca-orderer ca-tools; do
echo "-----------> pull $IMAGES image"
echo
docker pull $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES
docker tag $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG $ORG_NAME-$IMAGES:$STABLE_TAG
docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$STABLE_TAG
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:$IMAGE_TAG
docker rmi -f $NEXUS_URL/$ORG_NAME-$IMAGES:$IMAGE_TAG
done
echo
docker images | grep hyperledger/fabric-ca
Expand Down
60 changes: 45 additions & 15 deletions scripts/Jenkins_Scripts/byfn_eyfn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,55 @@
# SPDX-License-Identifier: Apache-2.0
#

ARCH=$(dpkg --print-architecture)
echo "-----------> ARCH" $ARCH
# docker container list
CONTAINER_LIST=(peer0.org1 peer1.org1 peer0.org2 peer1.org2 peer0.org3 peer1.org3 orderer)
COUCHDB_CONTAINER_LIST=(couchdb0 couchdb1 couchdb2 couchdb3 couchdb4 couchdb5)

MARCH=$(uname -s|tr '[:upper:]' '[:lower:]')
echo "-----------> MARCH" $MARCH
VERSION=1.4.0
MVN_METADATA=$(echo "https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric-$VERSION-stable/maven-metadata.xml")
echo "-----------> PROJECT_VERSION:" $PROJECT_VERSION
MVN_METADATA=$(echo "https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric-$PROJECT_VERSION/maven-metadata.xml")
curl -L "$MVN_METADATA" > maven-metadata.xml
RELEASE_TAG=$(cat maven-metadata.xml | grep release)
COMMIT=$(echo $RELEASE_TAG | awk -F - '{ print $4 }' | cut -d "<" -f1)
echo "-----------> BASE_VERSION = $VERSION"
echo "-----------> COMMIT = $COMMIT"
cd $BASE_FOLDER/fabric-samples || exit
curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric-$VERSION-stable/$MARCH-$ARCH.$VERSION-stable-$COMMIT/hyperledger-fabric-$VERSION-stable-$MARCH-$ARCH.$VERSION-stable-$COMMIT.tar.gz | tar xz
curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric-$PROJECT_VERSION/$MARCH-$ARCH.$PROJECT_VERSION-$COMMIT/hyperledger-fabric-$PROJECT_VERSION-$MARCH-$ARCH.$PROJECT_VERSION-$COMMIT.tar.gz | tar xz

if [ $? -ne 0 ]; then
echo -e "\033[31m FAILED to download binaries" "\033[0m"
exit 1
fi

cd first-network || exit
export PATH=gopath/src/github.com/hyperledger/fabric-samples/bin:$PATH

err_Check() {
logs() {

# Create Logs directory
mkdir -p $WORKSPACE/Docker_Container_Logs

for CONTAINER in ${CONTAINER_LIST[*]}; do
docker logs $CONTAINER.example.com >& $WORKSPACE/Docker_Container_Logs/$CONTAINER-$1.log
echo
done
}

if [ ! -z $2 ]; then

for CONTAINER in ${COUCHDB_CONTAINER_LIST[*]}; do
docker logs $CONTAINER >& $WORKSPACE/Docker_Container_Logs/$CONTAINER-$1.log
echo
done
fi

copy_logs() {

# Call logs function
logs $2 $3

if [ $1 != 0 ]; then
echo "Error: -----------> $2 test case failed"
echo -e "\033[31m $2 test case is FAILED" "\033[0m"
exit 1
fi
}
Expand All @@ -32,32 +62,32 @@ fi
echo "#################################################################"
echo y | ./byfn.sh -m down
echo y | ./byfn.sh -m up -t 60
err_Check $? default-channel
copy_logs $? default-channel
echo y | ./eyfn.sh -m up -t 60
err_Check $? default-channel
copy_logs $? default-channel
echo y | ./eyfn.sh -m down
echo

echo "############### BYFN,EYFN CUSTOM CHANNEL WITH COUCHDB TEST ##############"
echo "#########################################################################"
echo y | ./byfn.sh -m up -c custom-channel-couchdb -s couchdb -t 75 -d 15
err_Check $? custom-channel-couch couchdb
copy_logs $? custom-channel-couch couchdb
echo y | ./eyfn.sh -m up -c custom-channel-couchdb -s couchdb -t 75 -d 15
err_Check $? custom-channel-couch
copy_logs $? custom-channel-couch
echo y | ./eyfn.sh -m down
echo

echo "############### BYFN,EYFN WITH NODE Chaincode. TEST ################"
echo "####################################################################"
echo y | ./byfn.sh -m up -l node -t 60
err_Check $? default-channel-node
copy_logs $? default-channel-node
echo y | ./eyfn.sh -m up -l node -t 60
err_Check $? default-channel-node
copy_logs $? default-channel-node
echo y | ./eyfn.sh -m down

echo "############### FABRIC-CA SAMPLES TEST ########################"
echo "###############################################################"
cd $WORKSPACE/gopath/src/github.com/hyperledger/fabric-samples/fabric-ca
./start.sh
err_Check $? fabric-ca
copy_logs $? fabric-ca
./stop.sh

0 comments on commit 1c82113

Please sign in to comment.