diff --git a/Jenkinsfile b/Jenkinsfile index 9dad95861..036ee15d7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,87 +1,76 @@ 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') } } @@ -89,18 +78,14 @@ node('lisk-nano-01'){ 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') } } @@ -108,53 +93,59 @@ node('lisk-nano-01'){ 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}" + } 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 + ''' + dir('node_modules') { + deleteDir() + } + + def pr_branch = '' + if (env.CHANGE_BRANCH != null) { + pr_branch = " (${env.CHANGE_BRANCH})" + } + if (currentBuild.result == 'SUCCESS') { + /* delete all files on success */ + deleteDir() /* 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' } } } diff --git a/features/step_definitions/generic.step.js b/features/step_definitions/generic.step.js index e083f8c9d..344cf00d7 100644 --- a/features/step_definitions/generic.step.js +++ b/features/step_definitions/generic.step.js @@ -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); }); diff --git a/features/step_definitions/login.step.js b/features/step_definitions/login.step.js index df91b9cf4..8a4873992 100644 --- a/features/step_definitions/login.step.js +++ b/features/step_definitions/login.step.js @@ -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) => { diff --git a/features/top.feature b/features/top.feature index c80e93092..55b17c173 100644 --- a/features/top.feature +++ b/features/top.feature @@ -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" diff --git a/protractor.conf.js b/protractor.conf.js index 825942ee9..3b99832a5 100644 --- a/protractor.conf.js +++ b/protractor.conf.js @@ -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', @@ -24,5 +22,7 @@ exports.config = { params: { screenshotFolder: 'e2e-test-screenshots', + baseURL: 'http://localhost:8080/', + liskCoreURL: 'http://localhost:4000/', }, };