Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Parallel jenkins builds - Closes #825 #845

Merged
merged 21 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e22d20d
Remove pkill selenium from Jenkinsfile
slaweet Oct 4, 2017
7247f02
Separate e2e test urls into protractor.conf.js
slaweet Oct 4, 2017
4424ca0
Expose e2e test urls in Jenkinsfile
slaweet Oct 4, 2017
5665d31
Use executor number to customize port numbers
francoilol Oct 4, 2017
18fb0a9
Work around pm2 silently failing when pm2_home is longer than 99 chars
francoilol Oct 5, 2017
a1689a4
Merge branch 'development' into 825-paralel-jenkins-builds
francoilol Oct 6, 2017
d6add7a
Merge branch 'development' into 825-paralel-jenkins-builds
francoilol Oct 6, 2017
552b014
Fix "should show peer" e2e test
slaweet Oct 6, 2017
235abdc
parameterized core and lisk ports, database name; disabled redis
francoilol Oct 6, 2017
09a1a71
run one postgres instance with several databases
francoilol Oct 7, 2017
c7215b2
work around bug in core
francoilol Oct 9, 2017
8a89c8a
Use new "lisk-nano" node to prevent conflicts with old builds using l…
francoilol Oct 9, 2017
7ce9491
log errors when some are caught
francoilol Oct 9, 2017
1607f6f
Use deleteDir instead of rm in sh step
francoilol Oct 9, 2017
a74eb06
notify of failures inside of fail() to have access to the $reason
francoilol Oct 9, 2017
29267f4
do not call error in fail()
francoilol Oct 9, 2017
f35c917
Revert "do not call error in fail()"
francoilol Oct 9, 2017
a16957b
do not call fail twice
francoilol Oct 9, 2017
8745442
fix recovery notifications
francoilol Oct 9, 2017
940bb95
Add logging to debug concurrency issues
francoilol Oct 10, 2017
7748f53
Revert "Add logging to debug concurrency issues"
francoilol Oct 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 75 additions & 86 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,161 +1,150 @@
def fail(reason) {
def pr_branch = ''
if (env.CHANGE_BRANCH != null) {
pr_branch = " (${env.CHANGE_BRANCH})"
}
slackSend color: 'danger', message: "Build #${env.BUILD_NUMBER} of <${env.BUILD_URL}|${env.JOB_NAME}>${pr_branch} failed (<${env.BUILD_URL}/console|console>, <${env.BUILD_URL}/changes|changes>)\nCause: ${reason}", channel: '#lisk-nano-jenkins'
currentBuild.result = 'FAILURE'
sh 'rm -rf "$WORKSPACE/node_modules/"'
milestone 1
error("${reason}")
}

node('lisk-nano-01'){
lock(resource: "lisk-nano-01", inversePrecedence: true) {
stage ('Cleanup, Checkout, and Start Lisk Core') {
try {
sh '''
# Clean up old processes
cd ~/lisk-test-nano
bash lisk.sh stop_node
pkill -f selenium -9 || true
pkill -f Xvfb -9 || true
rm -rf /tmp/.X0-lock || true
pkill -f webpack -9 || true
'''
} catch (err) {
fail('Stopping build, installation failed')
}

node('lisk-nano') {
try {
stage ('Cleanup, Checkout and Start Lisk Core') {
try {
deleteDir()
checkout scm
} catch (err) {
fail('Stopping build, Checkout failed')
echo "Error: ${err}"
fail('Stopping build: checkout failed')
}

try {
sh '''
cd ~/lisk-test-nano
bash lisk.sh rebuild -f /home/lisk/lisk-test-nano/blockchain_explorer.db.gz
'''
N=${EXECUTOR_NUMBER:-0}
cd ~/lisk-Linux-x86_64
# work around core bug: config.json gets overwritten; use backup
cp .config.json config_$N.json
# change core port
sed -i -r -e "s/^(.*ort\\":) 4000,/\\1 400$N,/" config_$N.json
# disable redis
sed -i -r -e "s/^(\\s*\\"cacheEnabled\\":) true/\\1 false/" config_$N.json
# change postgres databse
sed -i -r -e "s/^(\\s*\\"database\\": \\"lisk_test)\\",/\\1_$N\\",/" config_$N.json
cp etc/pm2-lisk.json etc/pm2-lisk_$N.json
sed -i -r -e "s/config.json/config_$N.json/" etc/pm2-lisk_$N.json
sed -i -r -e "s/(lisk.app)/\\1_$N/" etc/pm2-lisk_$N.json
JENKINS_NODE_COOKIE=dontKillMe bash lisk.sh start_db -p etc/pm2-lisk_$N.json
bash lisk.sh rebuild -p etc/pm2-lisk_$N.json -f blockchain_explorer.db.gz
'''
} catch (err) {
fail('Stopping build, Lisk Core failed to start')
echo "Error: ${err}"
fail('Stopping build: Lisk Core failed to start')
}
}

stage ('Install npm dependencies') {
try {
sh '''
npm install
# Build nano
cd $WORKSPACE
npm install

'''
sh 'npm install'
} catch (err) {
fail('Stopping build, npm install failed')
echo "Error: ${err}"
fail('Stopping build: npm install failed')
}
}

stage ('Run Eslint') {
try {
ansiColor('xterm') {
sh '''
cd $WORKSPACE
npm run eslint
'''
}
sh 'npm run eslint'
}
} catch (err) {
fail('Stopping build, Eslint failed')
echo "Error: ${err}"
fail('Stopping build: Eslint failed')
}
}

stage ('Build Nano') {
try {
sh '''
# Add coveralls config file
cp ~/.coveralls.yml-nano .coveralls.yml

# Run Build
npm run build
'''
} catch (err) {
fail('Stopping build, Nano build failed')
echo "Error: ${err}"
fail('Stopping build: nano build failed')
}
}

stage ('Run Unit Tests') {
try {
ansiColor('xterm') {
sh '''
export ON_JENKINS=true

# Run test
cd $WORKSPACE
npm run test

ON_JENKINS=true npm run test
# Submit coverage to coveralls
cat coverage/*/lcov.info | coveralls -v
'''
}
}
} catch (err) {
fail('Stopping build, Test suite failed')
echo "Error: ${err}"
fail('Stopping build: test suite failed')
}
}

stage ('Start Dev Server and Run E2E Tests') {
try {
ansiColor('xterm') {
sh '''
# Run Dev build and Build
cd $WORKSPACE
export NODE_ENV=
npm run dev &> .lisk-nano.log &
N=${EXECUTOR_NUMBER:-0}
NODE_ENV= npm run dev -- --port 808$N &> .lisk-nano.log &
sleep 30

# End to End test configuration
export DISPLAY=:99
Xvfb :99 -ac -screen 0 1280x1024x24 &
export DISPLAY=:1$N
Xvfb :1$N -ac -screen 0 1280x1024x24 &
./node_modules/protractor/bin/webdriver-manager update

# Run End to End Tests
npm run e2e-test

cd ~/lisk-test-nano
bash lisk.sh stop_node
pkill -f selenium -9 || true
pkill -f Xvfb -9 || true
rm -rf /tmp/.X0-lock || true
pkill -f webpack -9 || true
# Run end-to-end tests
npm run e2e-test -- --params.baseURL http://localhost:808$N/ --params.liskCoreURL http://localhost:400$N
'''
}
} catch (err) {
fail('Stopping build, End to End Test suite failed')
echo "Error: ${err}"
fail('Stopping build: end-to-end test suite failed')
}
}

stage ('Deploy and Set milestone') {
stage ('Deploy') {
try {
sh '''
rsync -axl --delete --rsync-path="mkdir -p '/var/www/test/lisk-nano/$BRANCH_NAME/' && rsync" "$WORKSPACE/app/dist/" "jenkins@master-01:/var/www/test/lisk-nano/$BRANCH_NAME/"

# Cleanup - delete all files on success
rm -rf "$WORKSPACE/*"
'''
sh 'rsync -axl --delete --rsync-path="mkdir -p /var/www/test/lisk-nano/$BRANCH_NAME/ && rsync" $WORKSPACE/app/dist/ jenkins@master-01:/var/www/test/lisk-nano/$BRANCH_NAME/'
} catch (err) {
fail('Stopping build, Deploy failed')
echo "Error: ${err}"
fail('Stopping build: deploy failed')
}
milestone 1
}
} catch(err) {
echo "Error: ${err}"
fail('Stopping build: unexpected failure')
} finally {
sh '''
N=${EXECUTOR_NUMBER:-0}
( cd ~/lisk-Linux-x86_64 && bash lisk.sh stop_node -p etc/pm2-lisk_$N.json ) || true
pkill -f "Xvfb :1$N" -9 || true
pkill -f "webpack.*808$N" -9 || true
rm -rf $WORKSPACE/node_modules/
'''

def pr_branch = ''
if (env.CHANGE_BRANCH != null) {
pr_branch = " (${env.CHANGE_BRANCH})"
}
if (currentBuild.result == 'SUCCESS') {
/* delete all files on success */
sh 'rm -rf $WORKSPACE/*'
/* notify of success if previous build failed */
previous_build = currentBuild.getPreviousBuild()
if (previous_build != null && previous_build.result == 'FAILURE') {
def pr_branch = ''
if (env.CHANGE_BRANCH != null) {
pr_branch = " (${env.CHANGE_BRANCH})"
}
slackSend color: 'good', message: "Recovery: build #${env.BUILD_NUMBER} of <${env.BUILD_URL}|${env.JOB_NAME}>${pr_branch} was successful.", channel: '#lisk-nano-jenkins'
slackSend color: 'good',
message: "Recovery: build #${env.BUILD_NUMBER} of <${env.BUILD_URL}|${env.JOB_NAME}>${pr_branch} was successful.",
channel: '#lisk-nano-jenkins'
}
} else if (currentBuild.result == 'FAILURE') {
slackSend color: 'danger',
message: "Build #${env.BUILD_NUMBER} of <${env.BUILD_URL}|${env.JOB_NAME}>${pr_branch} failed (<${env.BUILD_URL}/console|console>, <${env.BUILD_URL}/changes|changes>)",
channel: '#lisk-nano-jenkins'
}
}
}
6 changes: 3 additions & 3 deletions features/step_definitions/generic.step.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ defineSupportCode(({ Given, When, Then, setDefaultTimeout }) => {
Given('I\'m logged in as "{accountName}"', (accountName, callback) => {
browser.ignoreSynchronization = true;
browser.driver.manage().window().setSize(1000, 1000);
browser.get('http://localhost:8080/');
browser.get(browser.params.baseURL);
localStorage.clear();
localStorage.setItem('address', 'http://localhost:4000');
localStorage.setItem('address', browser.params.liskCoreURL);
localStorage.setItem('network', 2);
browser.get('http://localhost:8080/');
browser.get(browser.params.baseURL);
waitForElemAndSendKeys('.passphrase input', accounts[accountName].passphrase);
waitForElemAndClickIt('.login-button', callback);
});
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/login.step.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defineSupportCode(({ Given, Then, When }) => {
browser.ignoreSynchronization = true;
browser.driver.manage().window().setSize(1000, 1000);
browser.driver.get('about:blank');
browser.get('http://localhost:8080/#/').then(callback);
browser.get(browser.params.baseURL).then(callback);
});

When('I refresh the page', (callback) => {
Expand Down
2 changes: 1 addition & 1 deletion features/top.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Main page top area

Scenario: should show peer
Given I'm logged in as "any account"
Then I should see text "localhost : 4000" in "peer" element
Then I should see text "Custom Node" in "peer network" element

Scenario: should show address
Given I'm logged in as "genesis"
Expand Down
4 changes: 2 additions & 2 deletions protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ exports.config = {
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),

baseURL: 'http://localhost:8080/',

cucumberOpts: {
require: 'features/step_definitions/*.js',
tags: '~@ignore',
Expand All @@ -24,5 +22,7 @@ exports.config = {

params: {
screenshotFolder: 'e2e-test-screenshots',
baseURL: 'http://localhost:8080/',
liskCoreURL: 'http://localhost:4000/',
},
};