From e22d20d6d309da7ac39c9e0a0b014a62e54c86d1 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Wed, 4 Oct 2017 12:35:28 +0200 Subject: [PATCH 01/19] Remove pkill selenium from Jenkinsfile since we no longer use global selenium --- Jenkinsfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9dad95861..92530e784 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,7 +18,6 @@ node('lisk-nano-01'){ # 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 @@ -124,7 +123,6 @@ node('lisk-nano-01'){ 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 From 7247f02353a60e7d99b1e43ef795613d3e990cbf Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Wed, 4 Oct 2017 12:50:55 +0200 Subject: [PATCH 02/19] Separate e2e test urls into protractor.conf.js --- features/step_definitions/generic.step.js | 6 +++--- features/step_definitions/login.step.js | 2 +- protractor.conf.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) 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/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/', }, }; From 4424ca04d6473c9b40b8f15f8d8ca4cea40dbb20 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Wed, 4 Oct 2017 12:57:05 +0200 Subject: [PATCH 03/19] Expose e2e test urls in Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 92530e784..b4c00e13f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -119,7 +119,7 @@ node('lisk-nano-01'){ ./node_modules/protractor/bin/webdriver-manager update # Run End to End Tests - npm run e2e-test + npm run e2e-test -- --params.baseURL 'http://localhost:8080/' --params.liskCoreUrl 'http://localhost:4000' cd ~/lisk-test-nano bash lisk.sh stop_node From 5665d31cced6590efe4707bd8a7fa60af950529f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Wed, 4 Oct 2017 15:28:47 +0200 Subject: [PATCH 04/19] Use executor number to customize port numbers --- Jenkinsfile | 234 +++++++++++++++++++++++++--------------------------- 1 file changed, 111 insertions(+), 123 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b4c00e13f..49a17c33d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,149 +11,137 @@ def fail(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 Xvfb -9 || true - rm -rf /tmp/.X0-lock || true - pkill -f webpack -9 || true - ''' - } catch (err) { - fail('Stopping build, installation failed') - } - - try { - deleteDir() - checkout scm - } catch (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 - ''' - } catch (err) { - fail('Stopping build, Lisk Core failed to start') - } + stage ('Cleanup, Checkout, and Start Lisk Core') { + try { + deleteDir() + checkout scm + } catch (err) { + fail('Stopping build, Checkout failed') } - stage ('Install npm dependencies') { - try { - sh ''' - npm install - # Build nano - cd $WORKSPACE - npm install - - ''' - } catch (err) { - fail('Stopping build, npm install failed') - } + try { + sh ''' + N=${EXECUTOR_NUMBER:-0} + cp -r ~/lisk-test-nano $WORKSPACE + cd "$WORKSPACE/lisk-test-nano" + sed -i -r -e "s/^(\\s*\\"port\\":) 4000,/\\1 400$N,/" config.json + bash lisk.sh rebuild -f "$WORKSPACE/lisk-test-nano/blockchain_explorer.db.gz" + ''' + } catch (err) { + fail('Stopping build, Lisk Core failed to start') } + } - stage ('Run Eslint') { - try { - ansiColor('xterm') { - sh ''' - cd $WORKSPACE - npm run eslint - ''' - } - } catch (err) { - fail('Stopping build, Eslint failed') - } + stage ('Install npm dependencies') { + try { + sh ''' + npm install + # Build nano + cd $WORKSPACE + npm install + ''' + } catch (err) { + fail('Stopping build, npm install 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') + stage ('Run Eslint') { + try { + ansiColor('xterm') { + sh ''' + cd $WORKSPACE + npm run eslint + ''' } + } catch (err) { + fail('Stopping build, Eslint failed') } + } - stage ('Run Unit Tests') { - try { - ansiColor('xterm') { - sh ''' - export ON_JENKINS=true - - # Run test - cd $WORKSPACE - npm run test + stage ('Build Nano') { + try { + sh ''' + # Add coveralls config file + cp ~/.coveralls.yml-nano .coveralls.yml - # Submit coverage to coveralls - cat coverage/*/lcov.info | coveralls -v - ''' - } - } catch (err) { - fail('Stopping build, Test suite failed') - } + # Run Build + npm run build + ''' + } catch (err) { + fail('Stopping build, Nano build 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 & - sleep 30 + stage ('Run Unit Tests') { + try { + ansiColor('xterm') { + sh ''' + export ON_JENKINS=true - # End to End test configuration - export DISPLAY=:99 - Xvfb :99 -ac -screen 0 1280x1024x24 & - ./node_modules/protractor/bin/webdriver-manager update + # Run test + cd $WORKSPACE + npm run test - # Run End to End Tests - npm run e2e-test -- --params.baseURL 'http://localhost:8080/' --params.liskCoreUrl 'http://localhost:4000' + # Submit coverage to coveralls + cat coverage/*/lcov.info | coveralls -v + ''' + } + } catch (err) { + fail('Stopping build, Test suite failed') + } + } - cd ~/lisk-test-nano - bash lisk.sh stop_node - pkill -f Xvfb -9 || true - rm -rf /tmp/.X0-lock || true - pkill -f webpack -9 || true - ''' - } - } catch (err) { - fail('Stopping build, End to End Test suite failed') + stage ('Start Dev Server and Run E2E Tests') { + try { + ansiColor('xterm') { + sh ''' + N=${EXECUTOR_NUMBER:-0} + # Run Dev build and Build + cd $WORKSPACE + export NODE_ENV= + npm run dev -- --port 8080 &> .lisk-nano.log & + sleep 30 + + # End to End test configuration + 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 -- --params.baseURL "http://localhost:808$N/" --params.liskCoreUrl "http://localhost:400$N" + + cd "$WORKSPACE/lisk-test-nano" + bash lisk.sh stop_node + pkill -f Xvfb -9 || true + rm -rf "/tmp/.X1$N-lock" || true + pkill -f webpack -9 || true + ''' } + } catch (err) { + fail('Stopping build, End to End Test suite failed') } + } - stage ('Deploy and Set milestone') { - 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/" + stage ('Deploy and Set milestone') { + 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/*" - ''' - } catch (err) { - fail('Stopping build, Deploy failed') - } - milestone 1 - /* 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' + # Cleanup - delete all files on success + rm -rf "$WORKSPACE/*" + ''' + } catch (err) { + fail('Stopping build, Deploy failed') + } + milestone 1 + /* 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' } } } From 18fb0a9a8fb78e491d0464046247d1d904bc21e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Thu, 5 Oct 2017 11:37:55 +0200 Subject: [PATCH 05/19] Work around pm2 silently failing when pm2_home is longer than 99 chars --- Jenkinsfile | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 49a17c33d..dd5b42d6f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,6 +6,7 @@ def fail(reason) { 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/"' + sh 'N=${EXECUTOR_NUMBER:-0}; rm -rf ~/lisk-Linux-x86_64_$N' milestone 1 error("${reason}") } @@ -22,10 +23,13 @@ node('lisk-nano-01'){ try { sh ''' N=${EXECUTOR_NUMBER:-0} - cp -r ~/lisk-test-nano $WORKSPACE - cd "$WORKSPACE/lisk-test-nano" - sed -i -r -e "s/^(\\s*\\"port\\":) 4000,/\\1 400$N,/" config.json - bash lisk.sh rebuild -f "$WORKSPACE/lisk-test-nano/blockchain_explorer.db.gz" + cp -r ~/lisk-Linux-x86_64 ~/lisk-Linux-x86_64_$N + cd ~/lisk-Linux-x86_64_$N + sed -i -r -e "s/^(.*ort\\":) 4000,/\\1 400$N,/" config.json + sed -i -r -e "s/^(\\s*\\"port\\": 543)2,/\\1$N,/" config.json + sed -i -r -e "s/^#(port\\s*=\\s*).*/\\1 543$N/" ~/lisk-Linux-x86_64_$N/pgsql/data/postgresql.conf + export PGPORT=543$N + bash lisk.sh rebuild -f ~/lisk-Linux-x86_64_$N/blockchain_explorer.db.gz ''' } catch (err) { fail('Stopping build, Lisk Core failed to start') @@ -96,10 +100,11 @@ node('lisk-nano-01'){ ansiColor('xterm') { sh ''' N=${EXECUTOR_NUMBER:-0} + export PGPORT=543$N # Run Dev build and Build cd $WORKSPACE export NODE_ENV= - npm run dev -- --port 8080 &> .lisk-nano.log & + npm run dev -- --port 808$N &> .lisk-nano.log & sleep 30 # End to End test configuration @@ -110,7 +115,7 @@ node('lisk-nano-01'){ # Run End to End Tests npm run e2e-test -- --params.baseURL "http://localhost:808$N/" --params.liskCoreUrl "http://localhost:400$N" - cd "$WORKSPACE/lisk-test-nano" + cd "~/lisk-Linux-x86_64_$N" bash lisk.sh stop_node pkill -f Xvfb -9 || true rm -rf "/tmp/.X1$N-lock" || true From 552b0144707e357244399b3a0dd86437dd638d25 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 6 Oct 2017 12:04:52 +0200 Subject: [PATCH 06/19] Fix "should show peer" e2e test Don't check for the address, since now we can run e2e tests with any custom node --- features/top.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From 235abdc69e23f64b9cca70858ab63cf7e4f82d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Fri, 6 Oct 2017 14:58:12 +0200 Subject: [PATCH 07/19] parameterized core and lisk ports, database name; disabled redis --- Jenkinsfile | 235 +++++++++++++++++++++++++--------------------------- 1 file changed, 111 insertions(+), 124 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index dd5b42d6f..f9e8ff18c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,152 +1,139 @@ 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/"' - sh 'N=${EXECUTOR_NUMBER:-0}; rm -rf ~/lisk-Linux-x86_64_$N' - milestone 1 error("${reason}") } -node('lisk-nano-01'){ - stage ('Cleanup, Checkout, and Start Lisk Core') { - try { - deleteDir() - checkout scm - } catch (err) { - fail('Stopping build, Checkout failed') - } +node('lisk-nano-01') { + try { + stage ('Cleanup, Checkout and Start Lisk Core') { + try { + deleteDir() + checkout scm + } catch (err) { + fail('Stopping build: checkout failed') + } - try { - sh ''' - N=${EXECUTOR_NUMBER:-0} - cp -r ~/lisk-Linux-x86_64 ~/lisk-Linux-x86_64_$N - cd ~/lisk-Linux-x86_64_$N - sed -i -r -e "s/^(.*ort\\":) 4000,/\\1 400$N,/" config.json - sed -i -r -e "s/^(\\s*\\"port\\": 543)2,/\\1$N,/" config.json - sed -i -r -e "s/^#(port\\s*=\\s*).*/\\1 543$N/" ~/lisk-Linux-x86_64_$N/pgsql/data/postgresql.conf - export PGPORT=543$N - bash lisk.sh rebuild -f ~/lisk-Linux-x86_64_$N/blockchain_explorer.db.gz - ''' - } catch (err) { - fail('Stopping build, Lisk Core failed to start') + try { + sh ''' + N=${EXECUTOR_NUMBER:-0} + cp -r ~/lisk-Linux-x86_64 ~/lisk-Linux-x86_64_$N + cd ~/lisk-Linux-x86_64_$N + # change core port + sed -i -r -e "s/^(.*ort\\":) 4000,/\\1 400$N,/" config.json + # disable redis + sed -i -r -e "s/^(\\s*\\"cacheEnabled\\":) true/\\1 false/" config.json + # change postgres databse + sed -i -r -e "s/^(\\s*\\"database\\": \\"lisk_test)\\",/\\1_$N\\",/" config.json + JENKINS_NODE_COOKIE=dontKillMe bash lisk.sh start_db + bash lisk.sh rebuild -f blockchain_explorer.db.gz + ''' + } catch (err) { + fail('Stopping build: Lisk Core failed to start') + } } - } - stage ('Install npm dependencies') { - try { - sh ''' - npm install - # Build nano - cd $WORKSPACE - npm install - ''' - } catch (err) { - fail('Stopping build, npm install failed') + stage ('Install npm dependencies') { + try { + sh 'npm install' + } catch (err) { + fail('Stopping build: npm install failed') + } } - } - stage ('Run Eslint') { - try { - ansiColor('xterm') { - sh ''' - cd $WORKSPACE - npm run eslint - ''' + stage ('Run Eslint') { + try { + ansiColor('xterm') { + sh 'npm run eslint' + } + } catch (err) { + fail('Stopping build: Eslint failed') } - } catch (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') + stage ('Build Nano') { + try { + sh ''' + cp ~/.coveralls.yml-nano .coveralls.yml + npm run build + ''' + } catch (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 - # Submit coverage to coveralls - cat coverage/*/lcov.info | coveralls -v - ''' - } - } catch (err) { - fail('Stopping build, Test suite failed') + stage ('Run Unit Tests') { + try { + ansiColor('xterm') { + sh ''' + ON_JENKINS=true npm run test + # Submit coverage to coveralls + cat coverage/*/lcov.info | coveralls -v + ''' + } + } catch (err) { + fail('Stopping build: test suite failed') + } } - } - - stage ('Start Dev Server and Run E2E Tests') { - try { - ansiColor('xterm') { - sh ''' - N=${EXECUTOR_NUMBER:-0} - export PGPORT=543$N - # Run Dev build and Build - cd $WORKSPACE - export NODE_ENV= - npm run dev -- --port 808$N &> .lisk-nano.log & - sleep 30 - # End to End test configuration - export DISPLAY=":1$N" - Xvfb ":1$N" -ac -screen 0 1280x1024x24 & - ./node_modules/protractor/bin/webdriver-manager update + stage ('Start Dev Server and Run E2E Tests') { + try { + ansiColor('xterm') { + sh ''' + N=${EXECUTOR_NUMBER:-0} + NODE_ENV= npm run dev -- --port 808$N &> .lisk-nano.log & + sleep 30 - # Run End to End Tests - npm run e2e-test -- --params.baseURL "http://localhost:808$N/" --params.liskCoreUrl "http://localhost:400$N" + # End to End test configuration + export DISPLAY=:1$N + Xvfb :1$N -ac -screen 0 1280x1024x24 & + ./node_modules/protractor/bin/webdriver-manager update - cd "~/lisk-Linux-x86_64_$N" - bash lisk.sh stop_node - pkill -f Xvfb -9 || true - rm -rf "/tmp/.X1$N-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') } - } catch (err) { - fail('Stopping build, End to End Test suite failed') } - } - stage ('Deploy and Set milestone') { - 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/" + stage ('Deploy and Set Milestone') { + milestone 1 + 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/"' + } catch (err) { + fail('Stopping build: deploy failed') + } + } + } catch(err) { + fail('Stopping build: unexpected failure') + } finally { + sh ''' + N=${EXECUTOR_NUMBER:-0} + ( cd ~/lisk-Linux-x86_64_$N && bash lisk.sh stop_node ) || true + pkill -f "Xvfb :1$N" -9 || true + pkill -f "webpack.*808$N" -9 || true + rm -rf ~/lisk-Linux-x86_64_$N + rm -rf $WORKSPACE/node_modules/ + ''' - # Cleanup - delete all files on success - rm -rf "$WORKSPACE/*" - ''' - } catch (err) { - fail('Stopping build, Deploy failed') + def pr_branch = '' + if (env.CHANGE_BRANCH != null) { + pr_branch = " (${env.CHANGE_BRANCH})" } - milestone 1 - /* 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})" + if (currentBuild.result == 'SUCCESS') { + /* delete all files on success */ + sh 'rm -rf $WORKSPACE/*' + /* notify of success if previous build failed */ + if (previous_build != null && previous_build.result == 'FAILURE') { + 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' } } } From 09a1a71daefe41a10ef8e3e919ef828d45c5e3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Sat, 7 Oct 2017 22:18:33 +0200 Subject: [PATCH 08/19] run one postgres instance with several databases --- Jenkinsfile | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f9e8ff18c..123ae9272 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,18 +15,20 @@ node('lisk-nano-01') { try { sh ''' - N=${EXECUTOR_NUMBER:-0} - cp -r ~/lisk-Linux-x86_64 ~/lisk-Linux-x86_64_$N - cd ~/lisk-Linux-x86_64_$N - # change core port - sed -i -r -e "s/^(.*ort\\":) 4000,/\\1 400$N,/" config.json - # disable redis - sed -i -r -e "s/^(\\s*\\"cacheEnabled\\":) true/\\1 false/" config.json - # change postgres databse - sed -i -r -e "s/^(\\s*\\"database\\": \\"lisk_test)\\",/\\1_$N\\",/" config.json - JENKINS_NODE_COOKIE=dontKillMe bash lisk.sh start_db - bash lisk.sh rebuild -f blockchain_explorer.db.gz - ''' + N=${EXECUTOR_NUMBER:-0} + cd ~/lisk-Linux-x86_64 + 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 + 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') } @@ -43,7 +45,7 @@ node('lisk-nano-01') { stage ('Run Eslint') { try { ansiColor('xterm') { - sh 'npm run eslint' + sh 'npm run eslint' } } catch (err) { fail('Stopping build: Eslint failed') @@ -64,11 +66,11 @@ node('lisk-nano-01') { stage ('Run Unit Tests') { try { ansiColor('xterm') { - sh ''' - ON_JENKINS=true npm run test - # Submit coverage to coveralls - cat coverage/*/lcov.info | coveralls -v - ''' + sh ''' + ON_JENKINS=true npm run test + # Submit coverage to coveralls + cat coverage/*/lcov.info | coveralls -v + ''' } } catch (err) { fail('Stopping build: test suite failed') @@ -110,10 +112,9 @@ node('lisk-nano-01') { } finally { sh ''' N=${EXECUTOR_NUMBER:-0} - ( cd ~/lisk-Linux-x86_64_$N && bash lisk.sh stop_node ) || true + ( 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 ~/lisk-Linux-x86_64_$N rm -rf $WORKSPACE/node_modules/ ''' From c7215b238a5836d956515459762ed27bcaf1c891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Mon, 9 Oct 2017 09:27:45 +0200 Subject: [PATCH 09/19] work around bug in core --- Jenkinsfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 123ae9272..d4bf4e06b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,7 +17,8 @@ node('lisk-nano-01') { sh ''' N=${EXECUTOR_NUMBER:-0} cd ~/lisk-Linux-x86_64 - cp config.json config_$N.json + # 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 @@ -26,6 +27,7 @@ node('lisk-nano-01') { 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 ''' @@ -99,8 +101,7 @@ node('lisk-nano-01') { } } - stage ('Deploy and Set Milestone') { - milestone 1 + 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/"' } catch (err) { From 8a89c8acff3e7d10ab5bf930e86ab433bcf7c843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Mon, 9 Oct 2017 11:00:02 +0200 Subject: [PATCH 10/19] Use new "lisk-nano" node to prevent conflicts with old builds using locking --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index d4bf4e06b..6122ce017 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,7 @@ def fail(reason) { error("${reason}") } -node('lisk-nano-01') { +node('lisk-nano') { try { stage ('Cleanup, Checkout and Start Lisk Core') { try { From 7ce9491ff50ec3d9b151237ee79d25ffd2b6a14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Mon, 9 Oct 2017 12:29:54 +0200 Subject: [PATCH 11/19] log errors when some are caught --- Jenkinsfile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6122ce017..91e788edc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,6 +10,7 @@ node('lisk-nano') { deleteDir() checkout scm } catch (err) { + echo "Error: ${err}" fail('Stopping build: checkout failed') } @@ -32,6 +33,7 @@ node('lisk-nano') { bash lisk.sh rebuild -p etc/pm2-lisk_$N.json -f blockchain_explorer.db.gz ''' } catch (err) { + echo "Error: ${err}" fail('Stopping build: Lisk Core failed to start') } } @@ -40,6 +42,7 @@ node('lisk-nano') { try { sh 'npm install' } catch (err) { + echo "Error: ${err}" fail('Stopping build: npm install failed') } } @@ -50,6 +53,7 @@ node('lisk-nano') { sh 'npm run eslint' } } catch (err) { + echo "Error: ${err}" fail('Stopping build: Eslint failed') } } @@ -61,6 +65,7 @@ node('lisk-nano') { npm run build ''' } catch (err) { + echo "Error: ${err}" fail('Stopping build: nano build failed') } } @@ -75,6 +80,7 @@ node('lisk-nano') { ''' } } catch (err) { + echo "Error: ${err}" fail('Stopping build: test suite failed') } } @@ -97,18 +103,21 @@ node('lisk-nano') { ''' } } catch (err) { + echo "Error: ${err}" fail('Stopping build: end-to-end test suite failed') } } 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/"' + 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) { + echo "Error: ${err}" fail('Stopping build: deploy failed') } } } catch(err) { + echo "Error: ${err}" fail('Stopping build: unexpected failure') } finally { sh ''' From 1607f6fc3c5725c9ff9b8ab5d03808e6bf1d2e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Mon, 9 Oct 2017 15:25:20 +0200 Subject: [PATCH 12/19] Use deleteDir instead of rm in sh step --- Jenkinsfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 91e788edc..0f75efc29 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -125,8 +125,10 @@ node('lisk-nano') { ( 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/ ''' + dir('node_modules') { + deleteDir() + } def pr_branch = '' if (env.CHANGE_BRANCH != null) { @@ -134,7 +136,7 @@ node('lisk-nano') { } if (currentBuild.result == 'SUCCESS') { /* delete all files on success */ - sh 'rm -rf $WORKSPACE/*' + deleteDir() /* notify of success if previous build failed */ if (previous_build != null && previous_build.result == 'FAILURE') { slackSend color: 'good', From a74eb066570a7ffac3dbd5b4f8a5c591d1782298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Mon, 9 Oct 2017 15:31:53 +0200 Subject: [PATCH 13/19] notify of failures inside of fail() to have access to the $reason --- Jenkinsfile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0f75efc29..96afc9c90 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,10 @@ def fail(reason) { + 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' error("${reason}") } @@ -143,10 +149,6 @@ node('lisk-nano') { 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' } } } From 29267f40949746d54c75ef9c7386bd72cc19a4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Mon, 9 Oct 2017 15:47:20 +0200 Subject: [PATCH 14/19] do not call error in fail() --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 96afc9c90..36445514e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,6 @@ def fail(reason) { 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' - error("${reason}") } node('lisk-nano') { From f35c91751068376531c8d54243edad0e08d8e4b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Mon, 9 Oct 2017 16:37:03 +0200 Subject: [PATCH 15/19] Revert "do not call error in fail()" This reverts commit 29267f40949746d54c75ef9c7386bd72cc19a4f3. --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 36445514e..96afc9c90 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,6 +6,7 @@ def fail(reason) { 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' + error("${reason}") } node('lisk-nano') { From a16957b88ab4413679a8f9f29c0179c2b7ebbe68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Mon, 9 Oct 2017 16:41:14 +0200 Subject: [PATCH 16/19] do not call fail twice --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 96afc9c90..04e6bdd17 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -124,7 +124,6 @@ node('lisk-nano') { } } catch(err) { echo "Error: ${err}" - fail('Stopping build: unexpected failure') } finally { sh ''' N=${EXECUTOR_NUMBER:-0} From 8745442411720edb3d87d67283c0bc50320763a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Mon, 9 Oct 2017 17:10:33 +0200 Subject: [PATCH 17/19] fix recovery notifications --- Jenkinsfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 04e6bdd17..036ee15d7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,9 +2,7 @@ def fail(reason) { 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' + 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' error("${reason}") } @@ -143,6 +141,7 @@ node('lisk-nano') { /* 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') { slackSend color: 'good', message: "Recovery: build #${env.BUILD_NUMBER} of <${env.BUILD_URL}|${env.JOB_NAME}>${pr_branch} was successful.", From 940bb95f16bc1e21e2b33d01aff637b165b99232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Tue, 10 Oct 2017 10:28:11 +0200 Subject: [PATCH 18/19] Add logging to debug concurrency issues --- Jenkinsfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 036ee15d7..3948f9a2f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -125,8 +125,12 @@ node('lisk-nano') { } finally { sh ''' N=${EXECUTOR_NUMBER:-0} + ps ux ( cd ~/lisk-Linux-x86_64 && bash lisk.sh stop_node -p etc/pm2-lisk_$N.json ) || true + ps ux + ps -fp $( pgrep -d, -f "Xvfb :1$N" ) || true; pkill -f "Xvfb :1$N" -9 || true + ps -fp $( pgrep -d, -f "webpack.*808$N" ) || true pkill -f "webpack.*808$N" -9 || true ''' dir('node_modules') { From 7748f530f4c3b55b80f72694c4d7a99f20f825d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chavant?= Date: Tue, 10 Oct 2017 16:09:34 +0200 Subject: [PATCH 19/19] Revert "Add logging to debug concurrency issues" This reverts commit 940bb95f16bc1e21e2b33d01aff637b165b99232. --- Jenkinsfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3948f9a2f..036ee15d7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -125,12 +125,8 @@ node('lisk-nano') { } finally { sh ''' N=${EXECUTOR_NUMBER:-0} - ps ux ( cd ~/lisk-Linux-x86_64 && bash lisk.sh stop_node -p etc/pm2-lisk_$N.json ) || true - ps ux - ps -fp $( pgrep -d, -f "Xvfb :1$N" ) || true; pkill -f "Xvfb :1$N" -9 || true - ps -fp $( pgrep -d, -f "webpack.*808$N" ) || true pkill -f "webpack.*808$N" -9 || true ''' dir('node_modules') {