-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FAB-10074 CI Script for pipeline project type
This patch supports Jenkins CI pipeline project type for master branch. Script will pull docker images (1.2.0-stable) and binaries from Nexus and run byfn and eyfn tests. The pipeline script supports only master branch and release branches supports regular freestyle flow. Change-Id: I85938f66b588b2e37a2a12d4941672632d52c8dd Signed-off-by: rameshthoomu <rameshbabu.thoomu@gmail.com>
- Loading branch information
1 parent
f65f493
commit e95210e
Showing
3 changed files
with
336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright IBM Corp All Rights Reserved | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
// Pipeline script for fabric-samples | ||
|
||
node ('hyp-x') { // trigger build on x86_64 node | ||
def ROOTDIR = pwd() // workspace dir (/w/workspace/<job_name> | ||
env.PROJECT_DIR = "gopath/src/github.com/hyperledger" | ||
def failure_stage = "none" | ||
// delete working directory | ||
deleteDir() | ||
stage("Fetch Patchset") { // fetch gerrit refspec on latest commit | ||
try { | ||
dir("${ROOTDIR}"){ | ||
sh ''' | ||
[ -e gopath/src/github.com/hyperledger/fabric-samples ] || mkdir -p $PROJECT_DIR | ||
cd $PROJECT_DIR | ||
git clone git://cloud.hyperledger.org/mirror/fabric-samples && cd fabric-samples | ||
git fetch origin "$GERRIT_REFSPEC" && git checkout FETCH_HEAD | ||
''' | ||
} | ||
} | ||
catch (err) { | ||
failure_stage = "Fetch patchset" | ||
throw err | ||
} | ||
} | ||
// clean environment and get env data | ||
stage("Clean Environment - Get Env Info") { | ||
try { | ||
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { | ||
sh './CI_Script.sh --clean_Environment --env_Info' | ||
} | ||
} | ||
catch (err) { | ||
failure_stage = "Clean Environment - Get Env Info" | ||
throw err | ||
} | ||
} | ||
|
||
|
||
// Pull Fabric Images | ||
stage("Pull third_party images") { | ||
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" | ||
throw err | ||
} | ||
} | ||
|
||
// Pull Fabric Images | ||
stage("Pull fabric images") { | ||
try { | ||
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { | ||
sh './CI_Script.sh --pull_Fabric_Images' | ||
} | ||
} | ||
catch (err) { | ||
failure_stage = "Pull fabric docker images" | ||
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) | ||
stage("Run byfn_eyfn Tests") { | ||
try { | ||
dir("${ROOTDIR}/$PROJECT_DIR/fabric-samples/scripts/Jenkins_Scripts") { | ||
sh './CI_Script.sh --byfn_eyfn_Tests' | ||
} | ||
} | ||
catch (err) { | ||
failure_stage = "byfn_eyfn_Tests" | ||
throw err | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
#!/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 PROJECT_VERSION=1.2.0-stable | ||
export NEXUS_URL=nexus3.hyperledger.org:10001 | ||
export ORG_NAME="hyperledger/fabric" | ||
export NODE_VER=8.9.4 # 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 | ||
case $1 in | ||
--env_Info) | ||
env_Info | ||
;; | ||
--SetGopath) | ||
setGopath | ||
;; | ||
--pull_Fabric_Images) | ||
pull_Fabric_Images | ||
;; | ||
--pull_Fabric_CA_Image) | ||
pull_Fabric_CA_Image | ||
;; | ||
--clean_Environment) | ||
clean_Environment | ||
;; | ||
--byfn_eyfn_Tests) | ||
byfn_eyfn_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() { | ||
DOCKER_IMAGES_SNAPSHOTS=$(docker images | grep snapshot | grep -v grep | awk '{print $1":" $2}') | ||
|
||
if [ -z "$DOCKER_IMAGES_SNAPSHOTS" ] || [ "$DOCKER_IMAGES_SNAPSHOTS" = " " ]; then | ||
echo "---- No snapshot images available for deletion ----" | ||
else | ||
docker rmi -f $DOCKER_IMAGES_SNAPSHOTS || true | ||
fi | ||
DOCKER_IMAGE_IDS=$(docker images | grep -v 'base*\|couchdb\|kafka\|zookeeper\|cello' | awk '{print $3}') | ||
|
||
if [ -z "$DOCKER_IMAGE_IDS" ] || [ "$DOCKER_IMAGE_IDS" = " " ]; then | ||
echo "---- No images available for deletion ----" | ||
else | ||
docker rmi -f $DOCKER_IMAGE_IDS || true | ||
docker images | ||
fi | ||
} | ||
|
||
# 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 | ||
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() { | ||
for IMAGES in kafka couchdb zookeeper; do | ||
echo "-----------> Pull $IMAGE image" | ||
echo | ||
docker pull $ORG_NAME-$IMAGES:$BASE_IMAGE_TAG | ||
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 | ||
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 | ||
done | ||
echo | ||
docker images | grep hyperledger/fabric | ||
} | ||
# pull fabric-ca images from nexus | ||
pull_Fabric_CA_Image() { | ||
echo | ||
setGopath fabric-ca | ||
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 | ||
done | ||
echo | ||
docker images | grep hyperledger/fabric-ca | ||
} | ||
# run byfn,eyfn tests | ||
byfn_eyfn_Tests() { | ||
echo | ||
echo "-----------> Execute Byfn and Eyfn Tests" | ||
./byfn_eyfn.sh | ||
} | ||
Parse_Arguments $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright IBM Corp All Rights Reserved | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
ARCH=$(dpkg --print-architecture) | ||
echo "-----------> ARCH" $ARCH | ||
MARCH=$(uname -s|tr '[:upper:]' '[:lower:]') | ||
echo "-----------> MARCH" $MARCH | ||
MVN_METADATA=$(echo "https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric-stable/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) | ||
VERSION=1.2.0 | ||
echo "-----------> BASE_VERSION = $VERSION" | ||
cd $BASE_FOLDER/fabric-samples || exit | ||
curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric-stable/$MARCH-$ARCH.$VERSION-stable-$COMMIT/hyperledger-fabric-stable-$MARCH-$ARCH.$VERSION-stable-$COMMIT.tar.gz | tar xz | ||
|
||
cd first-network || exit | ||
export PATH=gopath/src/github.com/hyperledger/fabric-samples/bin:$PATH | ||
|
||
err_Check() { | ||
if [ $1 != 0 ]; then | ||
echo "Error: -----------> $2 test case failed" | ||
exit 1 | ||
fi | ||
} | ||
|
||
echo "############## BYFN,EYFN DEFAULT CHANNEL TEST ###################" | ||
echo "#################################################################" | ||
echo y | ./byfn.sh -m down | ||
echo y | ./byfn.sh -m up -t 60 | ||
err_Check $? default-channel | ||
echo y | ./eyfn.sh -m up -t 60 | ||
err_Check $? 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 60 | ||
err_check $? custom-channel-couch couchdb | ||
echo y | ./eyfn.sh -m up -c custom-channel-couchdb -s couchdb -t 60 | ||
err_check $? 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 | ||
echo y | ./eyfn.sh -m up -l node -t 60 | ||
err_check $? 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 | ||
./stop.sh |