From 3a69e1ff6437fd32f7c17cddc902820003dcb615 Mon Sep 17 00:00:00 2001 From: kudlaty Date: Thu, 22 Mar 2018 18:30:13 +0100 Subject: [PATCH 01/10] feature/jenkinsfile hello world --- Jenkinsfile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..d15b9d7 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,15 @@ +pipeline{ + agent none + stages { + stage('Build') { + agent { + docker { + image 'python:2-alpine' + } + } + steps { + sh 'echo Hello World!' + } + } + } +} \ No newline at end of file From 0267d9af1af20ff8ae93e5878771ed260512c48a Mon Sep 17 00:00:00 2001 From: kudlaty Date: Thu, 22 Mar 2018 18:33:28 +0100 Subject: [PATCH 02/10] feature/kjug added build step --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index d15b9d7..bdb116c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,8 @@ pipeline{ } } steps { - sh 'echo Hello World!' + sh 'pip install flask' + sh 'python -m py_compile sources/webapp.py' } } } From 83a400bebaff8fa2e177fa10baf0c1c17b30c231 Mon Sep 17 00:00:00 2001 From: kudlaty Date: Thu, 22 Mar 2018 18:38:31 +0100 Subject: [PATCH 03/10] feature/kjug added build stephb --- sources/test_webapp.py | 15 +++++++++++++++ sources/webapp.py | 10 ++++++++++ 2 files changed, 25 insertions(+) create mode 100644 sources/test_webapp.py create mode 100644 sources/webapp.py diff --git a/sources/test_webapp.py b/sources/test_webapp.py new file mode 100644 index 0000000..41b67b4 --- /dev/null +++ b/sources/test_webapp.py @@ -0,0 +1,15 @@ +from webapp import app +import unittest + + +class BasicTestCase(unittest.TestCase): + + def test_index(self): + tester = app.test_client(self) + response = tester.get('/', content_type='html/text') + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data, b'Hello, World!') + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/webapp.py b/sources/webapp.py new file mode 100644 index 0000000..c91e8eb --- /dev/null +++ b/sources/webapp.py @@ -0,0 +1,10 @@ +from flask import Flask +app = Flask(__name__) + +@app.route('/') +def hello(): + return "Hello, World!" + + +if __name__ == '__main__': + app.run() \ No newline at end of file From d50c9cdc39f531e756e50b1ed0bbf5eacf24fc9f Mon Sep 17 00:00:00 2001 From: kudlaty Date: Thu, 22 Mar 2018 18:40:50 +0100 Subject: [PATCH 04/10] feature/kjug added test step --- Jenkinsfile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index bdb116c..3be0382 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,5 +12,21 @@ pipeline{ sh 'python -m py_compile sources/webapp.py' } } + stage('Tests') { + agent { + docker { + image 'qnib/pytest' + } + } + steps { + sh 'pip install flask' + sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_webapp.py || true' + } + post { + always { + junit 'test-reports/results.xml' + } + } + } } } \ No newline at end of file From 2a7b665d52bd4bd9da2e7af7e86cd1e6c95cd08b Mon Sep 17 00:00:00 2001 From: kudlaty Date: Thu, 22 Mar 2018 18:43:07 +0100 Subject: [PATCH 05/10] feature/kjug bad test --- sources/test_webapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/test_webapp.py b/sources/test_webapp.py index 41b67b4..36a8dbe 100644 --- a/sources/test_webapp.py +++ b/sources/test_webapp.py @@ -8,7 +8,7 @@ class BasicTestCase(unittest.TestCase): tester = app.test_client(self) response = tester.get('/', content_type='html/text') self.assertEqual(response.status_code, 200) - self.assertEqual(response.data, b'Hello, World!') + self.assertEqual(response.data, b'Hello, World!kdsjflsd') if __name__ == '__main__': From 3e5f628132e1f06ef05411dda42fd34ba00e6a78 Mon Sep 17 00:00:00 2001 From: kudlaty Date: Thu, 22 Mar 2018 18:47:40 +0100 Subject: [PATCH 06/10] feature/kjug artifacts added --- Jenkinsfile | 63 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3be0382..02eb740 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,18 +13,61 @@ pipeline{ } } stage('Tests') { - agent { - docker { - image 'qnib/pytest' + parallel { + stage('on centos') { + agent { + docker { + image 'qnib/pytest' + } + } + steps { + sh 'ls -la' + sh 'pip install flask' + sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_webapp.py || true' + } + post { + always { + junit 'test-reports/results.xml' + } + } } + stage('on debian') { + agent { + docker { + image 'qnib/pytest' + } + } + steps { + sh 'pip install flask' + sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_webapp.py || true' + } + post { + always { + junit 'test-reports/results.xml' + } + + } + } + } - steps { - sh 'pip install flask' - sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_webapp.py || true' - } - post { - always { - junit 'test-reports/results.xml' + + stage('Create Artifacts') { + agent { + docker { + image 'cdrx/pyinstaller-linux:python2' + } + } + steps { + sh 'pip install flask' + sh 'pyinstaller --paths=/usr/lib64/python2.7/site-packages/ --onefile sources/webapp.py' + stash includes: 'dist/webapp', name: 'exec_files' + + } + post { + success { + archiveArtifacts 'dist/webapp' + } + } } } From 5050f8210061ceea77ccdfaf59e62ac8e0aa938b Mon Sep 17 00:00:00 2001 From: kudlaty Date: Thu, 22 Mar 2018 18:49:34 +0100 Subject: [PATCH 07/10] feature/kjug artifacts added --- Jenkinsfile | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 02eb740..04cd439 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,7 +12,8 @@ pipeline{ sh 'python -m py_compile sources/webapp.py' } } - stage('Tests') { + stage('Test') { + parallel { stage('on centos') { agent { @@ -50,26 +51,25 @@ pipeline{ } } - - stage('Create Artifacts') { - agent { - docker { - image 'cdrx/pyinstaller-linux:python2' - } - } - steps { - sh 'pip install flask' - sh 'pyinstaller --paths=/usr/lib64/python2.7/site-packages/ --onefile sources/webapp.py' - stash includes: 'dist/webapp', name: 'exec_files' - - } - post { - success { - archiveArtifacts 'dist/webapp' - } - + } + stage('Create Artifacts') { + agent { + docker { + image 'cdrx/pyinstaller-linux:python2' } } + steps { + sh 'pip install flask' + sh 'pyinstaller --paths=/usr/lib64/python2.7/site-packages/ --onefile sources/webapp.py' + stash includes: 'dist/webapp', name: 'exec_files' + + } + post { + success { + archiveArtifacts 'dist/webapp' + } + + } } - } -} \ No newline at end of file + } + } \ No newline at end of file From e02ea3fd3f8f58931e54f4d232a721dc89f91c7a Mon Sep 17 00:00:00 2001 From: kudlaty Date: Thu, 22 Mar 2018 18:51:09 +0100 Subject: [PATCH 08/10] feature/kjug artifacts added --- sources/test_webapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/test_webapp.py b/sources/test_webapp.py index 36a8dbe..41b67b4 100644 --- a/sources/test_webapp.py +++ b/sources/test_webapp.py @@ -8,7 +8,7 @@ class BasicTestCase(unittest.TestCase): tester = app.test_client(self) response = tester.get('/', content_type='html/text') self.assertEqual(response.status_code, 200) - self.assertEqual(response.data, b'Hello, World!kdsjflsd') + self.assertEqual(response.data, b'Hello, World!') if __name__ == '__main__': From e45b50d2e32f172a7c7a04ad4478c9ca7a998c63 Mon Sep 17 00:00:00 2001 From: kudlaty Date: Thu, 22 Mar 2018 18:54:44 +0100 Subject: [PATCH 09/10] feature/kjug deploy added --- Jenkinsfile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 04cd439..8ae1fb8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -71,5 +71,16 @@ pipeline{ } } + stage('Deploy') { + when { + branch 'kjug' + } + agent { label 'master' } + steps { + input message: 'Are you sure to deploy?' + unstash 'exec_files' + sh 'scp -r -o StrictHostKeyChecking=no dist/webapp root@172.17.0.3:/var/' + } + } } } \ No newline at end of file From 25a54e37ea3dd39668632b7b08cb533d08bc75cd Mon Sep 17 00:00:00 2001 From: kudlaty Date: Thu, 22 Mar 2018 19:00:47 +0100 Subject: [PATCH 10/10] feature/kjug smoke test --- Jenkinsfile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 8ae1fb8..61a1d8f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -82,5 +82,14 @@ pipeline{ sh 'scp -r -o StrictHostKeyChecking=no dist/webapp root@172.17.0.3:/var/' } } + stage('Smoke Test') { + when { + branch 'kjug' + } + agent { label 'master' } + steps { + sh 'ssh -o StrictHostKeyChecking=no root@172.17.0.3 ls -la /var/webapp' + } + } } } \ No newline at end of file