From bbe4e2d32f631981f26de9a108c5fc74b2859280 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 18 May 2018 14:06:48 +1200 Subject: [PATCH 01/82] Moving it from docker to k8s example --- Makefile | 22 ---------------------- README.md | 22 +++++----------------- index.js | 4 ++-- 3 files changed, 7 insertions(+), 41 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 7dae9a3..0000000 --- a/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -NAME ?= node-hello - -install: - npm install - -build: - docker build -t $(NAME) . - -bash: build - docker run -it --rm --entrypoint /bin/bash $(NAME) - -run: build - docker run -i -t -p 43567:8080 -d $(NAME) - -test: - curl localhost:43567 - -clean: - rm -rf node_modules - - -.PHONY: install build run test clean diff --git a/README.md b/README.md index 8e7428e..386c669 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,8 @@ -# Docker node.js example app +# Kubernetes node.js example app To build a container: -``` -$ make build -``` +docker build -t . -Following command will start Docker image in background -``` -$ make run -``` - -you can test it with: -``` -$ make test -``` -or simply run: -``` -curl -v localhost:43567 -``` +docker push tlitovsk/docker-nodejs-helloworld:latest +kubectl.exe run --image tlitovsk/docker-nodejs-helloworld:latest test +kubectl delete deployment test \ No newline at end of file diff --git a/index.js b/index.js index 3be9fcd..1479a65 100644 --- a/index.js +++ b/index.js @@ -10,5 +10,5 @@ app.get('/', function (req, res) { res.send('Hello World\n'); }); -app.listen(PORT) -console.log('Running on http://localhost:' + PORT); +app.listen(PORT,"0.0.0.0") +console.log('Running on http://0.0.0.0:' + PORT); From bb17dd33224e0643b08c63c53dc000f7fc91866d Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 21 May 2018 15:27:27 +1200 Subject: [PATCH 02/82] From Pod to Ingress --- README.md | 11 +++++++---- hello-1.yaml | 19 +++++++++++++++++++ hello-2.yaml | 21 +++++++++++++++++++++ hello-3-service.yaml | 11 +++++++++++ hello-4-ingress.yaml | 14 ++++++++++++++ 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 hello-1.yaml create mode 100644 hello-2.yaml create mode 100644 hello-3-service.yaml create mode 100644 hello-4-ingress.yaml diff --git a/README.md b/README.md index 386c669..c19465d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ # Kubernetes node.js example app To build a container: -docker build -t . +docker build -t tlitovsk/kubernetes-nodejs-helloworld:latest . -docker push tlitovsk/docker-nodejs-helloworld:latest -kubectl.exe run --image tlitovsk/docker-nodejs-helloworld:latest test -kubectl delete deployment test \ No newline at end of file +docker push tlitovsk/kubernetes-nodejs-helloworld:latest +kubectl.exe run --image tlitovsk/kubernetes-nodejs-helloworld:latest test +kubectl delete deployment test + + +https://159.65.132.157/k8s/clusters/c-q6rkn/api/v1/namespaces/example/services/hello-service:8080/proxy/ \ No newline at end of file diff --git a/hello-1.yaml b/hello-1.yaml new file mode 100644 index 0000000..5afa084 --- /dev/null +++ b/hello-1.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello-deployment + labels: + app: hello-world +spec: + selector: + matchLabels: + app: hello-world + template: + metadata: + labels: + app: hello-world + spec: + containers: + - name: hello-world + image: tlitovsk/kubernetes-nodejs-helloworld:latest + \ No newline at end of file diff --git a/hello-2.yaml b/hello-2.yaml new file mode 100644 index 0000000..7ec112c --- /dev/null +++ b/hello-2.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello-deployment + labels: + app: hello-world +spec: + replicas: 3 + selector: + matchLabels: + app: hello-world + template: + metadata: + labels: + app: hello-world + spec: + containers: + - name: hello-world + image: tlitovsk/kubernetes-nodejs-helloworld:latest + ports: + - containerPort: 8080 \ No newline at end of file diff --git a/hello-3-service.yaml b/hello-3-service.yaml new file mode 100644 index 0000000..a4e0325 --- /dev/null +++ b/hello-3-service.yaml @@ -0,0 +1,11 @@ +kind: Service +apiVersion: v1 +metadata: + name: hello-service +spec: + selector: + app: hello-world + ports: + - protocol: TCP + port: 8080 + targetPort: 8080 \ No newline at end of file diff --git a/hello-4-ingress.yaml b/hello-4-ingress.yaml new file mode 100644 index 0000000..34312ac --- /dev/null +++ b/hello-4-ingress.yaml @@ -0,0 +1,14 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: hello-ingress + annotations: + nginx.ingress.kubernetes.io/rewrite-target: / +spec: + rules: + - http: + paths: + - path: /hello + backend: + serviceName: hello-service + servicePort: 8080 \ No newline at end of file From c9cc1f754b8a161bdaf7a58b9b03983e163c6ede Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Tue, 22 May 2018 16:53:17 +1200 Subject: [PATCH 03/82] More readme for the demo --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c19465d..14867d9 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,11 @@ kubectl.exe run --image tlitovsk/kubernetes-nodejs-helloworld:latest test kubectl delete deployment test -https://159.65.132.157/k8s/clusters/c-q6rkn/api/v1/namespaces/example/services/hello-service:8080/proxy/ \ No newline at end of file + + +https://159.65.132.157/k8s/clusters/c-swqn4/api/v1/namespaces/example/services/hello-service:8080/proxy/ + +kubectl proxy +https://127.0.0.1:8001/k8s/clusters/c-swqn4/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ + +https://128.199.223.176/hello \ No newline at end of file From fccf189f519260f0605779011e3e5471ce15cfab Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 28 May 2018 11:34:48 +1200 Subject: [PATCH 04/82] adding pull policy and switch to versioned containers --- hello-1.yaml | 3 ++- hello-2.yaml | 3 ++- index.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/hello-1.yaml b/hello-1.yaml index 5afa084..3489c59 100644 --- a/hello-1.yaml +++ b/hello-1.yaml @@ -15,5 +15,6 @@ spec: spec: containers: - name: hello-world - image: tlitovsk/kubernetes-nodejs-helloworld:latest + image: tlitovsk/kubernetes-nodejs-helloworld:ver1 + imagePullPolicy: Always \ No newline at end of file diff --git a/hello-2.yaml b/hello-2.yaml index 7ec112c..315c869 100644 --- a/hello-2.yaml +++ b/hello-2.yaml @@ -16,6 +16,7 @@ spec: spec: containers: - name: hello-world - image: tlitovsk/kubernetes-nodejs-helloworld:latest + image: tlitovsk/kubernetes-nodejs-helloworld:ver1 + imagePullPolicy: Always ports: - containerPort: 8080 \ No newline at end of file diff --git a/index.js b/index.js index 1479a65..f753b9b 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ var PORT = process.env.PORT || DEFAULT_PORT; // App var app = express(); app.get('/', function (req, res) { - res.send('Hello World\n'); + res.send('Hello World version 1\n'); }); app.listen(PORT,"0.0.0.0") From 9b4d4c4a9a35c47f9eaa8bacd503b6a69d9a69d3 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 28 May 2018 13:25:36 +1200 Subject: [PATCH 05/82] Adding jenkins file --- Jenkinsfile.txt | 46 ++++++++++++++++++++++++++++++++++++++++++++++ hello-1.yaml | 2 -- hello-2.yaml | 2 -- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 Jenkinsfile.txt diff --git a/Jenkinsfile.txt b/Jenkinsfile.txt new file mode 100644 index 0000000..48c5777 --- /dev/null +++ b/Jenkinsfile.txt @@ -0,0 +1,46 @@ +node('master') { + + + currentBuild.result = "SUCCESS" + + try { + + stage('Checkout'){ + + checkout scm + } + + stage('Test'){ + + env.NODE_ENV = "test" + + print "Environment will be : ${env.NODE_ENV}" + + sh 'node -v' + + + } + + stage('Build Docker'){ + + + } + + stage('Deploy'){ + + + } + + stage('Cleanup'){ + + } + + + } + catch (err) { + + currentBuild.result = "FAILURE" + throw err + } + +} \ No newline at end of file diff --git a/hello-1.yaml b/hello-1.yaml index 3489c59..ca0af2d 100644 --- a/hello-1.yaml +++ b/hello-1.yaml @@ -2,8 +2,6 @@ apiVersion: apps/v1 kind: Deployment metadata: name: hello-deployment - labels: - app: hello-world spec: selector: matchLabels: diff --git a/hello-2.yaml b/hello-2.yaml index 315c869..1a30b3c 100644 --- a/hello-2.yaml +++ b/hello-2.yaml @@ -2,8 +2,6 @@ apiVersion: apps/v1 kind: Deployment metadata: name: hello-deployment - labels: - app: hello-world spec: replicas: 3 selector: From cddace4fd5f3573f8cf658d3506d693e01a60960 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 28 May 2018 13:27:51 +1200 Subject: [PATCH 06/82] removing extension on jenkins file --- Jenkinsfile.txt => Jenkinsfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Jenkinsfile.txt => Jenkinsfile (100%) diff --git a/Jenkinsfile.txt b/Jenkinsfile similarity index 100% rename from Jenkinsfile.txt rename to Jenkinsfile From 589e82eb1c9b14cc2e056f013304f90adc5890a4 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 28 May 2018 13:38:58 +1200 Subject: [PATCH 07/82] fixing the node tempate --- Jenkinsfile | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 48c5777..3a36b43 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,38 +1,17 @@ -node('master') { - - +node('k8s-slave') { currentBuild.result = "SUCCESS" - try { - stage('Checkout'){ - checkout scm } stage('Test'){ - env.NODE_ENV = "test" - print "Environment will be : ${env.NODE_ENV}" - sh 'node -v' - - - } - - stage('Build Docker'){ - - - } - - stage('Deploy'){ - - } - stage('Cleanup'){ - + stage('Build container'){ } From 83952c6862bc39973703a86bbe97e123b088c6e5 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 28 May 2018 16:13:44 +1200 Subject: [PATCH 08/82] Now lets make some node js testing --- .eslintrc.js | 3 +++ .gitignore | 1 + BuildContainer/Dockerfile | 13 +++++++++++++ Jenkinsfile | 4 ++-- README.md | 16 ++++------------ package.json | 9 ++++++++- 6 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 .eslintrc.js create mode 100644 BuildContainer/Dockerfile diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..923c92b --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,3 @@ +module.exports = { + "extends": "airbnb-base" +}; \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5a23aa6..d7a12b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /node_modules/* +package-lock.json diff --git a/BuildContainer/Dockerfile b/BuildContainer/Dockerfile new file mode 100644 index 0000000..37f1cbf --- /dev/null +++ b/BuildContainer/Dockerfile @@ -0,0 +1,13 @@ +FROM jenkins/jnlp-slave:latest +ARG DEBIAN_FRONTEND=noninteractive + +USER root +RUN apt-get update && apt-get install --no-install-recommends -y curl dirmngr gnupg apt-transport-https ca-certificates +RUN curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -\ + && echo 'deb https://deb.nodesource.com/node_8.x stretch main' > /etc/apt/sources.list.d/nodesource.list\ + && apt-get update\ + && apt-get install -y nodejs && apt-get clean && rm -rf /var/lib/apt/lists/* + +USER ${user} + +ENTRYPOINT ["jenkins-slave"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 3a36b43..180c0b7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,12 +9,12 @@ node('k8s-slave') { env.NODE_ENV = "test" print "Environment will be : ${env.NODE_ENV}" sh 'node -v' + sh 'npm install' + sh 'npm test' } stage('Build container'){ } - - } catch (err) { diff --git a/README.md b/README.md index 14867d9..bf6125d 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,10 @@ -# Kubernetes node.js example app +## Kubernetes node.js example app -To build a container: +#To build a container: docker build -t tlitovsk/kubernetes-nodejs-helloworld:latest . -docker push tlitovsk/kubernetes-nodejs-helloworld:latest -kubectl.exe run --image tlitovsk/kubernetes-nodejs-helloworld:latest test -kubectl delete deployment test - - - - -https://159.65.132.157/k8s/clusters/c-swqn4/api/v1/namespaces/example/services/hello-service:8080/proxy/ +#To build the test container +docker build --rm -t tlitovsk/jenkins-jnlp:latest . kubectl proxy https://127.0.0.1:8001/k8s/clusters/c-swqn4/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ - -https://128.199.223.176/hello \ No newline at end of file diff --git a/package.json b/package.json index 030ab98..51688f5 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,13 @@ "express": "4.16.1" }, "scripts": { - "start": "node ./index.js" + "start": "node ./index.js", + "test": "eslint index.js", + "coverage": "jest --collectCoverageFrom=src/**.js --coverage src" + }, + "devDependencies": { + "eslint": "^4.9.0", + "eslint-config-airbnb-base": "^12.1.0", + "eslint-plugin-import": "^2.12.0" } } From 3f4b89bc9b31c0c9a3729ec71a0f0a315caa0913 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 28 May 2018 16:36:17 +1200 Subject: [PATCH 09/82] Some quick fixes --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index f753b9b..1b2f875 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,14 @@ -var express = require('express'); +let express = require('express'); // Constants -var DEFAULT_PORT = 8080; -var PORT = process.env.PORT || DEFAULT_PORT; +const DEFAULT_PORT = 8080; +let PORT = process.env.PORT || DEFAULT_PORT; // App -var app = express(); +let app = express(); app.get('/', function (req, res) { res.send('Hello World version 1\n'); }); -app.listen(PORT,"0.0.0.0") +app.listen(PORT, "0.0.0.0") console.log('Running on http://0.0.0.0:' + PORT); From cf8a71bd9cb594514a8c57748dd9aa62549b6c86 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 28 May 2018 18:02:33 +1200 Subject: [PATCH 10/82] Fixing more eslint errors --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 1b2f875..3a66817 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,14 @@ -let express = require('express'); +const express = require('express'); // Constants const DEFAULT_PORT = 8080; -let PORT = process.env.PORT || DEFAULT_PORT; +const PORT = process.env.PORT || DEFAULT_PORT; // App -let app = express(); -app.get('/', function (req, res) { +const app = express(); +app.get('/', (req, res) => { res.send('Hello World version 1\n'); }); -app.listen(PORT, "0.0.0.0") -console.log('Running on http://0.0.0.0:' + PORT); +app.listen(PORT, '0.0.0.0'); +console.log(`Running on http://0.0.0.0:${PORT}`); From e7199d77b5e39b95f450f6172e41fbbc0f175127 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 28 May 2018 18:14:01 +1200 Subject: [PATCH 11/82] Remove the build container stage will be done by the rancher ci --- Jenkinsfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 180c0b7..9f96311 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,9 +12,6 @@ node('k8s-slave') { sh 'npm install' sh 'npm test' } - - stage('Build container'){ - } } catch (err) { From 5f16ae1a0fa2e464084369fae7c0d9321e031224 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Tue, 29 May 2018 11:00:57 +1200 Subject: [PATCH 12/82] Some unit testing --- index.js | 30 ++++++++++++++++++------------ index.test.js | 11 +++++++++++ package.json | 7 ++++++- 3 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 index.test.js diff --git a/index.js b/index.js index 3a66817..78dec67 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,20 @@ const express = require('express'); -// Constants -const DEFAULT_PORT = 8080; -const PORT = process.env.PORT || DEFAULT_PORT; - -// App -const app = express(); -app.get('/', (req, res) => { - res.send('Hello World version 1\n'); -}); - -app.listen(PORT, '0.0.0.0'); -console.log(`Running on http://0.0.0.0:${PORT}`); +function server() +{ + // Constants + const DEFAULT_PORT = 8080; + const PORT = process.env.PORT || DEFAULT_PORT; + + // App + const app = express(); + app.get('/', (req, res) => { + res.send('Hello World version 1\n'); + }); + + app.listen(PORT, '0.0.0.0'); + console.log(`Running on http://0.0.0.0:${PORT}`); +} +module.export = server; + +server() diff --git a/index.test.js b/index.test.js new file mode 100644 index 0000000..dd8b29d --- /dev/null +++ b/index.test.js @@ -0,0 +1,11 @@ +const request = require('supertest'); +const app = require('index,js') +describe('Test the root path', () => { + test('It should response the GET method', (done) => { + request(app).get('/').then((response) => { + expect(response.statusCode).toBe(200); + expect(response.body).toBe('Hello World version 1\n'); + done(); + }); + }); +}); \ No newline at end of file diff --git a/package.json b/package.json index 51688f5..86a1d11 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,13 @@ "coverage": "jest --collectCoverageFrom=src/**.js --coverage src" }, "devDependencies": { + "babel-cli": "^6.26.0", + "babel-preset-env": "^1.7.0", "eslint": "^4.9.0", "eslint-config-airbnb-base": "^12.1.0", - "eslint-plugin-import": "^2.12.0" + "eslint-plugin-import": "^2.12.0", + "jest": "^23.0.1", + "superagent": "^3.8.3", + "supertest": "^3.1.0" } } From 3fbf3a422814b1d58ddfbe4bb136bd7cd1ca3f44 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 31 May 2018 09:55:03 +1200 Subject: [PATCH 13/82] Readme and file clenaup --- .gitignore | 1 + README.md | 18 +-- package-lock.json | 362 ---------------------------------------------- 3 files changed, 8 insertions(+), 373 deletions(-) delete mode 100644 package-lock.json diff --git a/.gitignore b/.gitignore index 5a23aa6..d7a12b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /node_modules/* +package-lock.json diff --git a/README.md b/README.md index 14867d9..a6aa3ef 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,14 @@ # Kubernetes node.js example app To build a container: -docker build -t tlitovsk/kubernetes-nodejs-helloworld:latest . - -docker push tlitovsk/kubernetes-nodejs-helloworld:latest -kubectl.exe run --image tlitovsk/kubernetes-nodejs-helloworld:latest test -kubectl delete deployment test - - +docker build -t tlitovsk/kubernetes-nodejs-helloworld:ver1 . +docker build -t tlitovsk/kubernetes-nodejs-helloworld:ver2 . +Push it +docker push tlitovsk/kubernetes-nodejs-helloworld:ver1 +docker push tlitovsk/kubernetes-nodejs-helloworld:ver2 +URL access inside the container https://159.65.132.157/k8s/clusters/c-swqn4/api/v1/namespaces/example/services/hello-service:8080/proxy/ - -kubectl proxy -https://127.0.0.1:8001/k8s/clusters/c-swqn4/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ - +https://159.65.132.157/k8s/clusters/c-swqn4/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ https://128.199.223.176/hello \ No newline at end of file diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 85549e5..0000000 --- a/package-lock.json +++ /dev/null @@ -1,362 +0,0 @@ -{ - "name": "docker-debian-hello-world", - "version": "0.0.2", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "accepts": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.4.tgz", - "integrity": "sha1-hiRnWMfdbSGmR0/whKR0DsBesh8=", - "requires": { - "mime-types": "2.1.17", - "negotiator": "0.6.1" - } - }, - "array-flatten": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" - }, - "body-parser": { - "version": "1.18.2", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", - "integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=", - "requires": { - "bytes": "3.0.0", - "content-type": "1.0.4", - "debug": "2.6.9", - "depd": "1.1.2", - "http-errors": "1.6.2", - "iconv-lite": "0.4.19", - "on-finished": "2.3.0", - "qs": "6.5.1", - "raw-body": "2.3.2", - "type-is": "1.6.15" - } - }, - "bytes": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", - "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" - }, - "content-disposition": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", - "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" - }, - "content-type": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", - "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" - }, - "cookie": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", - "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" - }, - "cookie-signature": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", - "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" - }, - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - }, - "depd": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", - "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" - }, - "destroy": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", - "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" - }, - "ee-first": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" - }, - "encodeurl": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz", - "integrity": "sha1-eePVhlU0aQn+bw9Fpd5oEDspTSA=" - }, - "escape-html": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" - }, - "etag": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", - "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" - }, - "express": { - "version": "4.16.1", - "resolved": "https://registry.npmjs.org/express/-/express-4.16.1.tgz", - "integrity": "sha512-STB7LZ4N0L+81FJHGla2oboUHTk4PaN1RsOkoRh9OSeEKylvF5hwKYVX1xCLFaCT7MD0BNG/gX2WFMLqY6EMBw==", - "requires": { - "accepts": "1.3.4", - "array-flatten": "1.1.1", - "body-parser": "1.18.2", - "content-disposition": "0.5.2", - "content-type": "1.0.4", - "cookie": "0.3.1", - "cookie-signature": "1.0.6", - "debug": "2.6.9", - "depd": "1.1.2", - "encodeurl": "1.0.1", - "escape-html": "1.0.3", - "etag": "1.8.1", - "finalhandler": "1.1.0", - "fresh": "0.5.2", - "merge-descriptors": "1.0.1", - "methods": "1.1.2", - "on-finished": "2.3.0", - "parseurl": "1.3.2", - "path-to-regexp": "0.1.7", - "proxy-addr": "2.0.2", - "qs": "6.5.1", - "range-parser": "1.2.0", - "safe-buffer": "5.1.1", - "send": "0.16.1", - "serve-static": "1.13.1", - "setprototypeof": "1.1.0", - "statuses": "1.3.1", - "type-is": "1.6.15", - "utils-merge": "1.0.1", - "vary": "1.1.2" - } - }, - "finalhandler": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.0.tgz", - "integrity": "sha1-zgtoVbRYU+eRsvzGgARtiCU91/U=", - "requires": { - "debug": "2.6.9", - "encodeurl": "1.0.1", - "escape-html": "1.0.3", - "on-finished": "2.3.0", - "parseurl": "1.3.2", - "statuses": "1.3.1", - "unpipe": "1.0.0" - } - }, - "forwarded": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", - "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" - }, - "fresh": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", - "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" - }, - "http-errors": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", - "integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=", - "requires": { - "depd": "1.1.1", - "inherits": "2.0.3", - "setprototypeof": "1.0.3", - "statuses": "1.3.1" - }, - "dependencies": { - "depd": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", - "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" - }, - "setprototypeof": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", - "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" - } - } - }, - "iconv-lite": { - "version": "0.4.19", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", - "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" - }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - }, - "ipaddr.js": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.5.2.tgz", - "integrity": "sha1-1LUFvemUaYfM8PxY2QEP+WB+P6A=" - }, - "media-typer": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" - }, - "merge-descriptors": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" - }, - "methods": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" - }, - "mime": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", - "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==" - }, - "mime-db": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz", - "integrity": "sha1-dMZD2i3Z1qRTmZY0ZbJtXKfXHwE=" - }, - "mime-types": { - "version": "2.1.17", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz", - "integrity": "sha1-Cdejk/A+mVp5+K+Fe3Cp4KsWVXo=", - "requires": { - "mime-db": "1.30.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - }, - "negotiator": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", - "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" - }, - "on-finished": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", - "requires": { - "ee-first": "1.1.1" - } - }, - "parseurl": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", - "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" - }, - "path-to-regexp": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" - }, - "proxy-addr": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.2.tgz", - "integrity": "sha1-ZXFQT0e7mI7IGAJT+F3X4UlSvew=", - "requires": { - "forwarded": "0.1.2", - "ipaddr.js": "1.5.2" - } - }, - "qs": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", - "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" - }, - "range-parser": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", - "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" - }, - "raw-body": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz", - "integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=", - "requires": { - "bytes": "3.0.0", - "http-errors": "1.6.2", - "iconv-lite": "0.4.19", - "unpipe": "1.0.0" - } - }, - "safe-buffer": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" - }, - "send": { - "version": "0.16.1", - "resolved": "https://registry.npmjs.org/send/-/send-0.16.1.tgz", - "integrity": "sha512-ElCLJdJIKPk6ux/Hocwhk7NFHpI3pVm/IZOYWqUmoxcgeyM+MpxHHKhb8QmlJDX1pU6WrgaHBkVNm73Sv7uc2A==", - "requires": { - "debug": "2.6.9", - "depd": "1.1.2", - "destroy": "1.0.4", - "encodeurl": "1.0.1", - "escape-html": "1.0.3", - "etag": "1.8.1", - "fresh": "0.5.2", - "http-errors": "1.6.2", - "mime": "1.4.1", - "ms": "2.0.0", - "on-finished": "2.3.0", - "range-parser": "1.2.0", - "statuses": "1.3.1" - } - }, - "serve-static": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.1.tgz", - "integrity": "sha512-hSMUZrsPa/I09VYFJwa627JJkNs0NrfL1Uzuup+GqHfToR2KcsXFymXSV90hoyw3M+msjFuQly+YzIH/q0MGlQ==", - "requires": { - "encodeurl": "1.0.1", - "escape-html": "1.0.3", - "parseurl": "1.3.2", - "send": "0.16.1" - } - }, - "setprototypeof": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", - "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" - }, - "statuses": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", - "integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4=" - }, - "type-is": { - "version": "1.6.15", - "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz", - "integrity": "sha1-yrEPtJCeRByChC6v4a1kbIGARBA=", - "requires": { - "media-typer": "0.3.0", - "mime-types": "2.1.17" - } - }, - "unpipe": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" - }, - "utils-merge": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" - }, - "vary": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", - "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" - } - } -} From 13e8c98b65736030cd8780ec59ef78ef555b3bc8 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 31 May 2018 12:48:29 +1200 Subject: [PATCH 14/82] Linting dockerfiles --- Dockerfile | 2 +- Jenkinsfile | 7 +++++++ {BuildContainer => TestContainer}/Dockerfile | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) rename {BuildContainer => TestContainer}/Dockerfile (94%) diff --git a/Dockerfile b/Dockerfile index 475b72d..55223bb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,4 @@ WORKDIR /web RUN npm install EXPOSE 8080 -ENTRYPOINT ["nodejs", "./index.js"] +ENTRYPOINT ["nodejs", "./server.js"] diff --git a/Jenkinsfile b/Jenkinsfile index 9f96311..93bcc6b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,12 +5,19 @@ node('k8s-slave') { checkout scm } + stage('Lint Dockerfiles') + { + sh 'dockerlint Dockerfile' + sh 'dockerlint TestContainer/Dockerfile' + } + stage('Test'){ env.NODE_ENV = "test" print "Environment will be : ${env.NODE_ENV}" sh 'node -v' sh 'npm install' sh 'npm test' + } } catch (err) { diff --git a/BuildContainer/Dockerfile b/TestContainer/Dockerfile similarity index 94% rename from BuildContainer/Dockerfile rename to TestContainer/Dockerfile index 37f1cbf..a0faac2 100644 --- a/BuildContainer/Dockerfile +++ b/TestContainer/Dockerfile @@ -7,6 +7,8 @@ RUN curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && echo 'deb https://deb.nodesource.com/node_8.x stretch main' > /etc/apt/sources.list.d/nodesource.list\ && apt-get update\ && apt-get install -y nodejs && apt-get clean && rm -rf /var/lib/apt/lists/* + + RUN npm install -g dockerlint USER ${user} From 37b4a6c1bb0b43909ad9c400d8db4bc3ca91a830 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 31 May 2018 13:13:33 +1200 Subject: [PATCH 15/82] Refactoring the code to enable unit testing, adding linting --- .eslintrc.js | 7 ++++++- .vscode/launch.json | 23 +++++++++++++++++++++++ README.md | 8 ++++---- app.js | 10 ++++++++++ app.test.js | 12 ++++++++++++ index.js | 20 -------------------- index.test.js | 11 ----------- package.json | 5 +++-- server.js | 8 ++++++++ 9 files changed, 66 insertions(+), 38 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 app.js create mode 100644 app.test.js delete mode 100644 index.js delete mode 100644 index.test.js create mode 100644 server.js diff --git a/.eslintrc.js b/.eslintrc.js index 923c92b..676357f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,3 +1,8 @@ module.exports = { - "extends": "airbnb-base" + "extends": "airbnb-base", + "plugins":["jasmine"], + "env": { + "jasmine": true, + "jest":true + } }; \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f0a9cea --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,23 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Jest All", + "program": "${workspaceFolder}/node_modules/jest/bin/jest", + "args": ["--runInBand"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + }, + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}\\server.js" + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 0fd4117..8ed5ea2 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ ## Kubernetes node.js example app -#To build a container: +# To build a container: docker build -t tlitovsk/kubernetes-nodejs-helloworld:ver1 . docker build -t tlitovsk/kubernetes-nodejs-helloworld:ver2 . docker build -t tlitovsk/kubernetes-nodejs-helloworld:latest . -#Push it +# Push it docker push tlitovsk/kubernetes-nodejs-helloworld:ver1 docker push tlitovsk/kubernetes-nodejs-helloworld:ver2 -#URL access inside the container +# URL access inside the container https://159.65.132.157/k8s/clusters/c-swqn4/api/v1/namespaces/example/services/hello-service:8080/proxy/ https://159.65.132.157/k8s/clusters/c-swqn4/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ https://128.199.223.176/hello -#To build the test container +# To build the test container docker build --rm -t tlitovsk/jenkins-jnlp:latest . diff --git a/app.js b/app.js new file mode 100644 index 0000000..bd30bdb --- /dev/null +++ b/app.js @@ -0,0 +1,10 @@ +const express = require('express'); + +const app = express(); + +app.get('/', (req, res) => { + res.send('Hello World version 1\n'); +}); + +module.exports = app; + diff --git a/app.test.js b/app.test.js new file mode 100644 index 0000000..87186b9 --- /dev/null +++ b/app.test.js @@ -0,0 +1,12 @@ +const request = require('supertest'); +const app = require('./app.js'); + +describe('Test the root path', () => { + test('It should response the GET method', (done) => { + request(app).get('/').then((response) => { + expect(response.statusCode).toBe(200); + expect(response.text).toBe('Hello World version 1\n'); + done(); + }); + }); +}); diff --git a/index.js b/index.js deleted file mode 100644 index 78dec67..0000000 --- a/index.js +++ /dev/null @@ -1,20 +0,0 @@ -const express = require('express'); - -function server() -{ - // Constants - const DEFAULT_PORT = 8080; - const PORT = process.env.PORT || DEFAULT_PORT; - - // App - const app = express(); - app.get('/', (req, res) => { - res.send('Hello World version 1\n'); - }); - - app.listen(PORT, '0.0.0.0'); - console.log(`Running on http://0.0.0.0:${PORT}`); -} -module.export = server; - -server() diff --git a/index.test.js b/index.test.js deleted file mode 100644 index dd8b29d..0000000 --- a/index.test.js +++ /dev/null @@ -1,11 +0,0 @@ -const request = require('supertest'); -const app = require('index,js') -describe('Test the root path', () => { - test('It should response the GET method', (done) => { - request(app).get('/').then((response) => { - expect(response.statusCode).toBe(200); - expect(response.body).toBe('Hello World version 1\n'); - done(); - }); - }); -}); \ No newline at end of file diff --git a/package.json b/package.json index 86a1d11..0fc7ed6 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "express": "4.16.1" }, "scripts": { - "start": "node ./index.js", - "test": "eslint index.js", + "start": "node ./server.js", + "test": "eslint *.js && jest", "coverage": "jest --collectCoverageFrom=src/**.js --coverage src" }, "devDependencies": { @@ -18,6 +18,7 @@ "eslint": "^4.9.0", "eslint-config-airbnb-base": "^12.1.0", "eslint-plugin-import": "^2.12.0", + "eslint-plugin-jasmine": "^2.10.1", "jest": "^23.0.1", "superagent": "^3.8.3", "supertest": "^3.1.0" diff --git a/server.js b/server.js new file mode 100644 index 0000000..699ef1b --- /dev/null +++ b/server.js @@ -0,0 +1,8 @@ +const app = require('./app.js'); + +const PORT = 8080; + +app.listen(PORT, '0.0.0.0', () => { + console.log(`Running on http://0.0.0.0:${PORT}`); // eslint-disable-line no-console +}); + From 35aade095b998fadb28af9dfd879e97c53571bef Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 31 May 2018 13:15:03 +1200 Subject: [PATCH 16/82] Readme formating update --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8ed5ea2..16f77d8 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ -## Kubernetes node.js example app +# Kubernetes node.js example app -# To build a container: +## To build a container: docker build -t tlitovsk/kubernetes-nodejs-helloworld:ver1 . docker build -t tlitovsk/kubernetes-nodejs-helloworld:ver2 . docker build -t tlitovsk/kubernetes-nodejs-helloworld:latest . -# Push it +## Push it docker push tlitovsk/kubernetes-nodejs-helloworld:ver1 docker push tlitovsk/kubernetes-nodejs-helloworld:ver2 -# URL access inside the container +## URL access inside the container https://159.65.132.157/k8s/clusters/c-swqn4/api/v1/namespaces/example/services/hello-service:8080/proxy/ https://159.65.132.157/k8s/clusters/c-swqn4/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ https://128.199.223.176/hello -# To build the test container +## To build the test container docker build --rm -t tlitovsk/jenkins-jnlp:latest . From 5ac750d9616627ef12e9c573b9dec08e05b36093 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 31 May 2018 13:27:53 +1200 Subject: [PATCH 17/82] Fixing user argument statment --- TestContainer/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TestContainer/Dockerfile b/TestContainer/Dockerfile index a0faac2..59917d4 100644 --- a/TestContainer/Dockerfile +++ b/TestContainer/Dockerfile @@ -8,8 +8,8 @@ RUN curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && apt-get update\ && apt-get install -y nodejs && apt-get clean && rm -rf /var/lib/apt/lists/* - RUN npm install -g dockerlint +RUN npm install -g dockerlint -USER ${user} +USER jenkins ENTRYPOINT ["jenkins-slave"] \ No newline at end of file From b359cd52c90b2fe81ab97dc4fed530a42a1dde9e Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 09:14:33 +1200 Subject: [PATCH 18/82] Reorganizing the charts --- hello-1.yaml => deployment/hello-1.yaml | 0 hello-2.yaml => deployment/hello-2.yaml | 0 hello-3-service.yaml => deployment/hello-3-service.yaml | 0 hello-4-ingress.yaml => deployment/hello-4-ingress.yaml | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename hello-1.yaml => deployment/hello-1.yaml (100%) rename hello-2.yaml => deployment/hello-2.yaml (100%) rename hello-3-service.yaml => deployment/hello-3-service.yaml (100%) rename hello-4-ingress.yaml => deployment/hello-4-ingress.yaml (100%) diff --git a/hello-1.yaml b/deployment/hello-1.yaml similarity index 100% rename from hello-1.yaml rename to deployment/hello-1.yaml diff --git a/hello-2.yaml b/deployment/hello-2.yaml similarity index 100% rename from hello-2.yaml rename to deployment/hello-2.yaml diff --git a/hello-3-service.yaml b/deployment/hello-3-service.yaml similarity index 100% rename from hello-3-service.yaml rename to deployment/hello-3-service.yaml diff --git a/hello-4-ingress.yaml b/deployment/hello-4-ingress.yaml similarity index 100% rename from hello-4-ingress.yaml rename to deployment/hello-4-ingress.yaml From 030c56e61ce9461375ab5fd1eef252cc9d6054b6 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 09:14:55 +1200 Subject: [PATCH 19/82] Building the image --- Jenkinsfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 93bcc6b..22779a9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,6 +19,11 @@ node('k8s-slave') { sh 'npm test' } + + stage('Build'){ + def hello_image = docker.build("kubernetes-nodejs-helloworld:${env.BUILD_ID}") + //customImage.push() + } } catch (err) { From be4cfd2d6725af364f83a53151e50bdb1762a5ed Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 10:06:10 +1200 Subject: [PATCH 20/82] Adding junit results --- Jenkinsfile | 9 +++++++-- junit.xml | 6 ++++++ package.json | 6 ++++-- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 junit.xml diff --git a/Jenkinsfile b/Jenkinsfile index 22779a9..cd34671 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,8 +21,13 @@ node('k8s-slave') { } stage('Build'){ - def hello_image = docker.build("kubernetes-nodejs-helloworld:${env.BUILD_ID}") - //customImage.push() + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() + def hello_image = docker.build("kubernetes-nodejs-helloworld:${shortCommit}${env.BUILD_ID}") + } + post { + always { + junit('junit.xml') + } } } catch (err) { diff --git a/junit.xml b/junit.xml new file mode 100644 index 0000000..43292ba --- /dev/null +++ b/junit.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/package.json b/package.json index 0fc7ed6..2bf8f02 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,9 @@ }, "scripts": { "start": "node ./server.js", - "test": "eslint *.js && jest", - "coverage": "jest --collectCoverageFrom=src/**.js --coverage src" + "pretest": "eslint *.js", + "test": "jest --ci --testResultsProcessor=jest-junit", + "coverage": "jest --collectCoverageFrom=**.js --coverage src" }, "devDependencies": { "babel-cli": "^6.26.0", @@ -20,6 +21,7 @@ "eslint-plugin-import": "^2.12.0", "eslint-plugin-jasmine": "^2.10.1", "jest": "^23.0.1", + "jest-junit": "^4.0.0", "superagent": "^3.8.3", "supertest": "^3.1.0" } From acffae23efb7c487e9ae5c9cf7b2006709c84801 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 10:06:30 +1200 Subject: [PATCH 21/82] Adding docker into the test container --- TestContainer/Dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/TestContainer/Dockerfile b/TestContainer/Dockerfile index 59917d4..1b5c225 100644 --- a/TestContainer/Dockerfile +++ b/TestContainer/Dockerfile @@ -5,11 +5,14 @@ USER root RUN apt-get update && apt-get install --no-install-recommends -y curl dirmngr gnupg apt-transport-https ca-certificates RUN curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -\ && echo 'deb https://deb.nodesource.com/node_8.x stretch main' > /etc/apt/sources.list.d/nodesource.list\ + && curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - \ + && echo 'deb https://download.docker.com/linux/debian stretch stable' > /etc/apt/sources.list.d/docker.list \ && apt-get update\ - && apt-get install -y nodejs && apt-get clean && rm -rf /var/lib/apt/lists/* + && apt-get install -y nodejs docker-ce && apt-get clean && rm -rf /var/lib/apt/lists/* RUN npm install -g dockerlint USER jenkins -ENTRYPOINT ["jenkins-slave"] \ No newline at end of file +ENTRYPOINT ["jenkins-slave"] +#docker build --rm -t tlitovsk/jenkins-jnlp:latest . \ No newline at end of file From acf830b7edbec1098378d0038eba6dddc9b51e05 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 10:31:08 +1200 Subject: [PATCH 22/82] Cosmetic image name change --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index cd34671..309281e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -22,7 +22,7 @@ node('k8s-slave') { stage('Build'){ shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - def hello_image = docker.build("kubernetes-nodejs-helloworld:${shortCommit}${env.BUILD_ID}") + def hello_image = docker.build("kubernetes-nodejs-helloworld:${shortCommit}-${env.BUILD_ID}") } post { always { From 2d8ec784376fee0e48477af7a432b96ad972f00f Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 10:34:41 +1200 Subject: [PATCH 23/82] fix post command location --- Jenkinsfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 309281e..274bd64 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,11 +24,11 @@ node('k8s-slave') { shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() def hello_image = docker.build("kubernetes-nodejs-helloworld:${shortCommit}-${env.BUILD_ID}") } - post { - always { - junit('junit.xml') - } - } + } + post { + always { + junit('junit.xml') + } } catch (err) { From 3215f62e943fa629c6c388d2595cdff18e9812e2 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 11:00:23 +1200 Subject: [PATCH 24/82] fixing the catch location --- Jenkinsfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 274bd64..846a0ce 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,19 +21,21 @@ node('k8s-slave') { } stage('Build'){ + docker.withRegistry('https://docker-registry-docker-registry.docker-registry.svc.cluster.local') shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() def hello_image = docker.build("kubernetes-nodejs-helloworld:${shortCommit}-${env.BUILD_ID}") + hello_image.push() } } - post { - always { - junit('junit.xml') - } - } catch (err) { currentBuild.result = "FAILURE" throw err } + post { + always { + junit('junit.xml') + } + } } \ No newline at end of file From 34646d5856af7acde96eab36fb594957960daa4c Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 11:17:45 +1200 Subject: [PATCH 25/82] Comment out docker push for now --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 846a0ce..d3a0ced 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,10 +21,10 @@ node('k8s-slave') { } stage('Build'){ - docker.withRegistry('https://docker-registry-docker-registry.docker-registry.svc.cluster.local') + //docker.withRegistry('https://registry-docker-registry.docker-registry.svc.cluster.local') shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() def hello_image = docker.build("kubernetes-nodejs-helloworld:${shortCommit}-${env.BUILD_ID}") - hello_image.push() + //hello_image.push() } } catch (err) { From f036f125c5dc6fd5274016c9edfa4798a4cfe2e5 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 11:50:33 +1200 Subject: [PATCH 26/82] fixing to scripted pipeline --- Jenkinsfile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d3a0ced..ad645e1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,7 +17,7 @@ node('k8s-slave') { sh 'node -v' sh 'npm install' sh 'npm test' - + junit('junit.xml') } stage('Build'){ @@ -32,10 +32,5 @@ node('k8s-slave') { currentBuild.result = "FAILURE" throw err } - post { - always { - junit('junit.xml') - } - } } \ No newline at end of file From f9844a2b769a1e4c6f28d5a514a639407fea33aa Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 12:51:16 +1200 Subject: [PATCH 27/82] Adding credentials to docker hub --- Jenkinsfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ad645e1..21167ef 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,10 +21,11 @@ node('k8s-slave') { } stage('Build'){ - //docker.withRegistry('https://registry-docker-registry.docker-registry.svc.cluster.local') - shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - def hello_image = docker.build("kubernetes-nodejs-helloworld:${shortCommit}-${env.BUILD_ID}") - //hello_image.push() + docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){ + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() + def hello_image = docker.build("kubernetes-nodejs-helloworld:${shortCommit}-${env.BUILD_ID}") + hello_image.push() + } } } catch (err) { From 6b6efd3477245b399df0648b52859ea5cd5ab2f3 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 13:05:04 +1200 Subject: [PATCH 28/82] adding user --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 21167ef..e3092d5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -23,7 +23,7 @@ node('k8s-slave') { stage('Build'){ docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){ shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - def hello_image = docker.build("kubernetes-nodejs-helloworld:${shortCommit}-${env.BUILD_ID}") + def hello_image = docker.build("tlitovsk/kubernetes-nodejs-helloworld:${shortCommit}-${env.BUILD_ID}") hello_image.push() } } From 1ba67027a53f88e63460c1ef33cb8223dfc714fc Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 13:15:25 +1200 Subject: [PATCH 29/82] Adding push on master only and testing kubectl --- Jenkinsfile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e3092d5..97376bb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,8 @@ node('k8s-slave') { currentBuild.result = "SUCCESS" try { + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() + stage('Checkout'){ checkout scm } @@ -22,11 +24,16 @@ node('k8s-slave') { stage('Build'){ docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){ - shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - def hello_image = docker.build("tlitovsk/kubernetes-nodejs-helloworld:${shortCommit}-${env.BUILD_ID}") - hello_image.push() + def hello_image = docker.build("tlitovsk/kubernetes-nodejs-helloworld:${shortCommit}") + if (env.BRANCH_NAME == 'master') { + hello_image.push() + } } } + stage('Deploy') + { + sh 'kubectl' + } } catch (err) { From f7ee753b9d82e9530f215b1ae24730fade74df02 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 13:25:00 +1200 Subject: [PATCH 30/82] lets try dyncamic yaml desc --- Jenkinsfile | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 97376bb..c8bab91 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,8 +1,48 @@ -node('k8s-slave') { +def label = "mypod-${UUID.randomUUID().toString()}" +podTemplate(label: label, yaml: """ +apiVersion: v1 +kind: Pod +metadata: + name: jenkins-slave-nodejs +spec: + containers: + - name: jnlp + image: tlitovsk/jenkins-jnlp:latest + imagePullPolicy: Always + env: + - name: DOCKER_HOST + value: tcp://localhost:2375 + env: + - name: DOCKERHUB_USERNAME + valueFrom: + secretKeyRef: + name: docker-hub-access + key: user + - name: DOCKERHUB_PASSWORD + valueFrom: + secretKeyRef: + name: docker-hub-access + key: password + - name: dind-daemon + image: docker:18-dind + resources: + requests: + cpu: 20m + memory: 512Mi + securityContext: + privileged: true + volumeMounts: + - name: docker-graph-storage + mountPath: /var/lib/docker + volumes: + - name: docker-graph-storage + emptyDir: {} +""" +) + +node(label) { currentBuild.result = "SUCCESS" try { - shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - stage('Checkout'){ checkout scm } @@ -24,6 +64,7 @@ node('k8s-slave') { stage('Build'){ docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){ + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() def hello_image = docker.build("tlitovsk/kubernetes-nodejs-helloworld:${shortCommit}") if (env.BRANCH_NAME == 'master') { hello_image.push() @@ -32,6 +73,7 @@ node('k8s-slave') { } stage('Deploy') { + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() sh 'kubectl' } } From aff2da9d4e1225efe7ed13c534817e29abf32b47 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 13:39:22 +1200 Subject: [PATCH 31/82] Connecting to right cloud --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c8bab91..9e8ec0a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ def label = "mypod-${UUID.randomUUID().toString()}" -podTemplate(label: label, yaml: """ +podTemplate(label: label,cloud : "example", yaml: """ apiVersion: v1 kind: Pod metadata: @@ -74,7 +74,7 @@ node(label) { stage('Deploy') { shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - sh 'kubectl' + sh 'kubectl get deployments' } } catch (err) { From b8b50d10a07b1a4e1036ad28590b82f27712cb90 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 13:45:21 +1200 Subject: [PATCH 32/82] space change and brackets --- Jenkinsfile | 79 +++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9e8ec0a..44031c6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ def label = "mypod-${UUID.randomUUID().toString()}" -podTemplate(label: label,cloud : "example", yaml: """ +podTemplate(label: label, cloud: "example", yaml: """ apiVersion: v1 kind: Pod metadata: @@ -39,48 +39,49 @@ spec: emptyDir: {} """ ) +{ + node(label) { + currentBuild.result = "SUCCESS" + try { + stage('Checkout'){ + checkout scm + } -node(label) { - currentBuild.result = "SUCCESS" - try { - stage('Checkout'){ - checkout scm - } + stage('Lint Dockerfiles') + { + sh 'dockerlint Dockerfile' + sh 'dockerlint TestContainer/Dockerfile' + } - stage('Lint Dockerfiles') - { - sh 'dockerlint Dockerfile' - sh 'dockerlint TestContainer/Dockerfile' - } + stage('Test'){ + env.NODE_ENV = "test" + print "Environment will be : ${env.NODE_ENV}" + sh 'node -v' + sh 'npm install' + sh 'npm test' + junit('junit.xml') + } - stage('Test'){ - env.NODE_ENV = "test" - print "Environment will be : ${env.NODE_ENV}" - sh 'node -v' - sh 'npm install' - sh 'npm test' - junit('junit.xml') - } - - stage('Build'){ - docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){ - shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - def hello_image = docker.build("tlitovsk/kubernetes-nodejs-helloworld:${shortCommit}") - if (env.BRANCH_NAME == 'master') { - hello_image.push() + stage('Build'){ + docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){ + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() + def hello_image = docker.build("tlitovsk/kubernetes-nodejs-helloworld:${shortCommit}") + if (env.BRANCH_NAME == 'master') { + hello_image.push() + } } - } - } - stage('Deploy') - { - shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - sh 'kubectl get deployments' - } - } - catch (err) { + } + stage('Deploy') + { + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() + sh 'kubectl get deployments' + } + } + catch (err) { - currentBuild.result = "FAILURE" - throw err - } + currentBuild.result = "FAILURE" + throw err + } + } } \ No newline at end of file From 8fbec76ebd9a1cf069e096a0490b133a35141647 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 14:25:17 +1200 Subject: [PATCH 33/82] Adding kubectl to test container --- TestContainer/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/TestContainer/Dockerfile b/TestContainer/Dockerfile index 1b5c225..b1503eb 100644 --- a/TestContainer/Dockerfile +++ b/TestContainer/Dockerfile @@ -2,13 +2,16 @@ FROM jenkins/jnlp-slave:latest ARG DEBIAN_FRONTEND=noninteractive USER root + RUN apt-get update && apt-get install --no-install-recommends -y curl dirmngr gnupg apt-transport-https ca-certificates RUN curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -\ && echo 'deb https://deb.nodesource.com/node_8.x stretch main' > /etc/apt/sources.list.d/nodesource.list\ && curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - \ && echo 'deb https://download.docker.com/linux/debian stretch stable' > /etc/apt/sources.list.d/docker.list \ + && curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - \ + && echo 'deb http://apt.kubernetes.io/ kubernetes-xenial main' > /etc/apt/sources.list.d/kubernetes.list \ && apt-get update\ - && apt-get install -y nodejs docker-ce && apt-get clean && rm -rf /var/lib/apt/lists/* + && apt-get install -y nodejs docker-ce kubectl && apt-get clean && rm -rf /var/lib/apt/lists/* RUN npm install -g dockerlint From 83a421ffcd6b2b4e680d0ba244cffac3cda3891f Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 14:28:48 +1200 Subject: [PATCH 34/82] specifing the namespace --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 44031c6..7c67a67 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -74,7 +74,7 @@ spec: stage('Deploy') { shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - sh 'kubectl get deployments' + sh 'kubectl get deployments --namespace=example-hello-world' } } catch (err) { From 831072408663fc32579fb647f72e595285166461 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 14:43:47 +1200 Subject: [PATCH 35/82] giving a different jenkins account --- Jenkinsfile | 60 ++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7c67a67..995da9e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ def label = "mypod-${UUID.randomUUID().toString()}" -podTemplate(label: label, cloud: "example", yaml: """ +podTemplate(label: label, serviceAccount: "jenkins", cloud: "example", yaml: """ apiVersion: v1 kind: Pod metadata: @@ -43,39 +43,39 @@ spec: node(label) { currentBuild.result = "SUCCESS" try { - stage('Checkout'){ - checkout scm - } + stage('Checkout'){ + checkout scm + } - stage('Lint Dockerfiles') - { - sh 'dockerlint Dockerfile' - sh 'dockerlint TestContainer/Dockerfile' - } + stage('Lint Dockerfiles') + { + sh 'dockerlint Dockerfile' + sh 'dockerlint TestContainer/Dockerfile' + } - stage('Test'){ - env.NODE_ENV = "test" - print "Environment will be : ${env.NODE_ENV}" - sh 'node -v' - sh 'npm install' - sh 'npm test' - junit('junit.xml') - } + stage('Test'){ + env.NODE_ENV = "test" + print "Environment will be : ${env.NODE_ENV}" + sh 'node -v' + sh 'npm install' + sh 'npm test' + junit('junit.xml') + } - stage('Build'){ - docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){ - shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - def hello_image = docker.build("tlitovsk/kubernetes-nodejs-helloworld:${shortCommit}") - if (env.BRANCH_NAME == 'master') { - hello_image.push() + stage('Build'){ + docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){ + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() + def hello_image = docker.build("tlitovsk/kubernetes-nodejs-helloworld:${shortCommit}") + if (env.BRANCH_NAME == 'master') { + hello_image.push() + } } - } - } - stage('Deploy') - { - shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - sh 'kubectl get deployments --namespace=example-hello-world' - } + } + stage('Deploy') + { + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() + sh 'kubectl get deployments --namespace=example-hello-world' + } } catch (err) { From 64f319d105d22c9166b8c1386f560b45f4984fa9 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 15:38:58 +1200 Subject: [PATCH 36/82] And updating deploy --- Jenkinsfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 995da9e..a268459 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -75,6 +75,9 @@ spec: { shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() sh 'kubectl get deployments --namespace=example-hello-world' + sh "cd deployment \ + && sed -i s/ver1/${shortCommit}/ hello-2.yaml \ + && kubectl apply -f hello-2.yaml" } } catch (err) { From e476d01edbabcaddfe474e7ab4253ca7e940801a Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 15:46:27 +1200 Subject: [PATCH 37/82] adding verify stage --- Jenkinsfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index a268459..b51d8c3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -78,6 +78,12 @@ spec: sh "cd deployment \ && sed -i s/ver1/${shortCommit}/ hello-2.yaml \ && kubectl apply -f hello-2.yaml" + sh 'kubectl rollout status deployment/hello-deployment' + + } + stage{'Verify'} + { + sh 'curl http://hello-world.example-hello-world.svc.cluster.local:8080' } } catch (err) { From 33772f6e38db4651b5522c5f1d7349f63688a3ad Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 15:48:07 +1200 Subject: [PATCH 38/82] Adding push for pull request for a second --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b51d8c3..cae7ee3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -66,9 +66,9 @@ spec: docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){ shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() def hello_image = docker.build("tlitovsk/kubernetes-nodejs-helloworld:${shortCommit}") - if (env.BRANCH_NAME == 'master') { + //if (env.BRANCH_NAME == 'master') { hello_image.push() - } + //} } } stage('Deploy') From f994cf240f4b0627b5ef7d2a75930d95b774c64b Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 15:55:13 +1200 Subject: [PATCH 39/82] typo fix verify --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index cae7ee3..6bd5c51 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -81,7 +81,7 @@ spec: sh 'kubectl rollout status deployment/hello-deployment' } - stage{'Verify'} + stage('Verify') { sh 'curl http://hello-world.example-hello-world.svc.cluster.local:8080' } From 4e99e92be602c82078fa1c46e8fbe08ff4a0f726 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 16:05:50 +1200 Subject: [PATCH 40/82] fixing namspace --- Jenkinsfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6bd5c51..cbbfa19 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,4 @@ +def namespace = "example-hello-world" def label = "mypod-${UUID.randomUUID().toString()}" podTemplate(label: label, serviceAccount: "jenkins", cloud: "example", yaml: """ apiVersion: v1 @@ -74,16 +75,16 @@ spec: stage('Deploy') { shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - sh 'kubectl get deployments --namespace=example-hello-world' + sh "kubectl get deployments --namespace=${namespace}" sh "cd deployment \ && sed -i s/ver1/${shortCommit}/ hello-2.yaml \ - && kubectl apply -f hello-2.yaml" - sh 'kubectl rollout status deployment/hello-deployment' + && kubectl apply -f hello-2.yaml --namespace=${namespace}" + sh "kubectl rollout status deployment/hello-deployment --namespace=${namespace}" } stage('Verify') { - sh 'curl http://hello-world.example-hello-world.svc.cluster.local:8080' + sh 'curl http://hello-service.example-hello-world.svc.cluster.local:8080' } } catch (err) { From 2ca1dd732e20e736d9673532993b6daf4c3084f3 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 16:12:45 +1200 Subject: [PATCH 41/82] rollout on master only --- Jenkinsfile | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cbbfa19..f6e156d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -67,24 +67,26 @@ spec: docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){ shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() def hello_image = docker.build("tlitovsk/kubernetes-nodejs-helloworld:${shortCommit}") - //if (env.BRANCH_NAME == 'master') { + if (env.BRANCH_NAME == 'master') { hello_image.push() - //} + } } } - stage('Deploy') - { - shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - sh "kubectl get deployments --namespace=${namespace}" - sh "cd deployment \ - && sed -i s/ver1/${shortCommit}/ hello-2.yaml \ - && kubectl apply -f hello-2.yaml --namespace=${namespace}" - sh "kubectl rollout status deployment/hello-deployment --namespace=${namespace}" - - } - stage('Verify') - { - sh 'curl http://hello-service.example-hello-world.svc.cluster.local:8080' + if (env.BRANCH_NAME == 'master') { + stage('Deploy') + { + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() + sh "kubectl get deployments --namespace=${namespace}" + sh "cd deployment \ + && sed -i s/ver1/${shortCommit}/ hello-2.yaml \ + && kubectl apply -f hello-2.yaml --namespace=${namespace}" + sh "kubectl rollout status deployment/hello-deployment --namespace=${namespace}" + + } + stage('Verify') + { + sh 'curl http://hello-service.example-hello-world.svc.cluster.local:8080' + } } } catch (err) { From b48bd45a8701c3727056ae53208340220ebbe5cb Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 16:16:09 +1200 Subject: [PATCH 42/82] update the result in proper place --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f6e156d..b1d3b09 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -42,7 +42,6 @@ spec: ) { node(label) { - currentBuild.result = "SUCCESS" try { stage('Checkout'){ checkout scm @@ -67,6 +66,7 @@ spec: docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){ shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() def hello_image = docker.build("tlitovsk/kubernetes-nodejs-helloworld:${shortCommit}") + currentBuild.result = "SUCCESS" if (env.BRANCH_NAME == 'master') { hello_image.push() } From c929fadfb4c1ba1c0bfee5dc5e25afaf716569c1 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 16:29:45 +1200 Subject: [PATCH 43/82] Gary change --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index bd30bdb..da9cedf 100644 --- a/app.js +++ b/app.js @@ -3,7 +3,7 @@ const express = require('express'); const app = express(); app.get('/', (req, res) => { - res.send('Hello World version 1\n'); + res.send('Hello World Gary\n'); }); module.exports = app; From 691849af70de9c2012f3ef1d2aaeded3379ec58e Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 1 Jun 2018 16:35:01 +1200 Subject: [PATCH 44/82] Fixing the name --- app.js | 2 +- app.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index da9cedf..f518461 100644 --- a/app.js +++ b/app.js @@ -3,7 +3,7 @@ const express = require('express'); const app = express(); app.get('/', (req, res) => { - res.send('Hello World Gary\n'); + res.send('Hello World Garry\n'); }); module.exports = app; diff --git a/app.test.js b/app.test.js index 87186b9..59db853 100644 --- a/app.test.js +++ b/app.test.js @@ -5,7 +5,7 @@ describe('Test the root path', () => { test('It should response the GET method', (done) => { request(app).get('/').then((response) => { expect(response.statusCode).toBe(200); - expect(response.text).toBe('Hello World version 1\n'); + expect(response.text).toBe('Hello World Garry\n'); done(); }); }); From 90645a0e2087b54532a2126a3da2d67132da06e5 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Tue, 5 Jun 2018 13:47:44 +1200 Subject: [PATCH 45/82] adding test results to git ignore --- junit.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/junit.xml b/junit.xml index 43292ba..d490ba9 100644 --- a/junit.xml +++ b/junit.xml @@ -1,6 +1,6 @@ - - - + + + \ No newline at end of file From e2e92ef7dc49a80728c9297fb64d4fe2c29a82c7 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 7 Jun 2018 17:25:07 +1200 Subject: [PATCH 46/82] updating build enviroment to avoid secrets in cluster --- Jenkinsfile | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b1d3b09..aaec6e5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,17 +13,6 @@ spec: env: - name: DOCKER_HOST value: tcp://localhost:2375 - env: - - name: DOCKERHUB_USERNAME - valueFrom: - secretKeyRef: - name: docker-hub-access - key: user - - name: DOCKERHUB_PASSWORD - valueFrom: - secretKeyRef: - name: docker-hub-access - key: password - name: dind-daemon image: docker:18-dind resources: From f5511064fc1272d23707dfe8d44a77be1cccb40b Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 7 Jun 2018 17:33:13 +1200 Subject: [PATCH 47/82] prepearing for demo --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index f518461..baf7481 100644 --- a/app.js +++ b/app.js @@ -3,7 +3,7 @@ const express = require('express'); const app = express(); app.get('/', (req, res) => { - res.send('Hello World Garry\n'); + res.send('Hello World\n'); }); module.exports = app; From afdf6cb040d1adebf52ed950a13d8683a19f4497 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 7 Jun 2018 17:37:24 +1200 Subject: [PATCH 48/82] fixing the test --- app.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.test.js b/app.test.js index 59db853..ef76ae1 100644 --- a/app.test.js +++ b/app.test.js @@ -5,7 +5,7 @@ describe('Test the root path', () => { test('It should response the GET method', (done) => { request(app).get('/').then((response) => { expect(response.statusCode).toBe(200); - expect(response.text).toBe('Hello World Garry\n'); + expect(response.text).toBe('Hello World\n'); done(); }); }); From 99d9f17fb8137af3d47bcbbdc75c9817b8598a5e Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 7 Jun 2018 18:47:01 +1200 Subject: [PATCH 49/82] Adding sonarq step --- Jenkinsfile | 8 +++++++- TestContainer/Dockerfile | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index aaec6e5..4bdca2c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -41,7 +41,13 @@ spec: sh 'dockerlint Dockerfile' sh 'dockerlint TestContainer/Dockerfile' } - + stage ('SonarQube analysis') + { + withSonarQubeEnv('QubeR') { + // requires SonarQube Scanner for Maven 3.2+ + sh 'sonarqube-scanner -Dsonar.sources=.' + } + } stage('Test'){ env.NODE_ENV = "test" print "Environment will be : ${env.NODE_ENV}" diff --git a/TestContainer/Dockerfile b/TestContainer/Dockerfile index b1503eb..a7da4f6 100644 --- a/TestContainer/Dockerfile +++ b/TestContainer/Dockerfile @@ -13,7 +13,7 @@ RUN curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && apt-get update\ && apt-get install -y nodejs docker-ce kubectl && apt-get clean && rm -rf /var/lib/apt/lists/* -RUN npm install -g dockerlint +RUN npm install -g dockerlint sonarqube-scanner USER jenkins From 727ec957525ce7f14ed323a0b557611adbf90fa3 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 7 Jun 2018 18:55:07 +1200 Subject: [PATCH 50/82] adding full path --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4bdca2c..1966b30 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,7 +45,7 @@ spec: { withSonarQubeEnv('QubeR') { // requires SonarQube Scanner for Maven 3.2+ - sh 'sonarqube-scanner -Dsonar.sources=.' + sh '/usr/lib/node_modules/sonarqube-scanner/dist/bin/sonar-scanner -Dsonar.sources=.' } } stage('Test'){ From bb99cd0e638ab2ca887f57064dc95308a1551390 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 7 Jun 2018 22:06:39 +1200 Subject: [PATCH 51/82] adding code coverage --- .gitignore | 1 + Jenkinsfile | 15 +++++++-------- junit.xml | 6 +++--- package.json | 3 +-- sonar-project.properties | 10 ++++++++++ 5 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 sonar-project.properties diff --git a/.gitignore b/.gitignore index d7a12b4..cab0ec4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /node_modules/* package-lock.json +coverage/* \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 1966b30..dea833f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -41,13 +41,6 @@ spec: sh 'dockerlint Dockerfile' sh 'dockerlint TestContainer/Dockerfile' } - stage ('SonarQube analysis') - { - withSonarQubeEnv('QubeR') { - // requires SonarQube Scanner for Maven 3.2+ - sh '/usr/lib/node_modules/sonarqube-scanner/dist/bin/sonar-scanner -Dsonar.sources=.' - } - } stage('Test'){ env.NODE_ENV = "test" print "Environment will be : ${env.NODE_ENV}" @@ -56,7 +49,13 @@ spec: sh 'npm test' junit('junit.xml') } - + stage ('SonarQube analysis') + { + withSonarQubeEnv('QubeR') { + // requires SonarQube Scanner for Maven 3.2+ + sh '/usr/lib/node_modules/sonarqube-scanner/dist/bin/sonar-scanner' + } + } stage('Build'){ docker.withRegistry('https://registry.hub.docker.com', 'dockerhub'){ shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() diff --git a/junit.xml b/junit.xml index d490ba9..b27f791 100644 --- a/junit.xml +++ b/junit.xml @@ -1,6 +1,6 @@ - - - + + + \ No newline at end of file diff --git a/package.json b/package.json index 2bf8f02..b24ad4d 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,7 @@ "scripts": { "start": "node ./server.js", "pretest": "eslint *.js", - "test": "jest --ci --testResultsProcessor=jest-junit", - "coverage": "jest --collectCoverageFrom=**.js --coverage src" + "test": "jest --ci --testResultsProcessor=jest-junit --coverage" }, "devDependencies": { "babel-cli": "^6.26.0", diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..175de48 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,10 @@ +# must be unique in a given SonarQube instance +sonar.projectKey=docker-debian-hello-world +# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. +sonar.projectName=k8s-hello-world +sonar.projectVersion=1.0 + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +# This property is optional if sonar.modules is set. +sonar.sources=. +sonar.javascript.lcov.reportPaths=./coverage \ No newline at end of file From 768479d35959f06b7c2bb62d8833fc3f24329539 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 7 Jun 2018 22:20:32 +1200 Subject: [PATCH 52/82] Moving src files to src --- Dockerfile | 2 +- junit.xml | 6 +++--- package.json | 6 +++--- sonar-project.properties | 4 ++-- app.js => src/app.js | 0 app.test.js => src/app.test.js | 0 server.js => src/server.js | 0 7 files changed, 9 insertions(+), 9 deletions(-) rename app.js => src/app.js (100%) rename app.test.js => src/app.test.js (100%) rename server.js => src/server.js (100%) diff --git a/Dockerfile b/Dockerfile index 55223bb..c36d8b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,4 @@ WORKDIR /web RUN npm install EXPOSE 8080 -ENTRYPOINT ["nodejs", "./server.js"] +ENTRYPOINT ["npm", "start"] diff --git a/junit.xml b/junit.xml index b27f791..28467f3 100644 --- a/junit.xml +++ b/junit.xml @@ -1,6 +1,6 @@ - - - + + + \ No newline at end of file diff --git a/package.json b/package.json index b24ad4d..47f8212 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,9 @@ "express": "4.16.1" }, "scripts": { - "start": "node ./server.js", - "pretest": "eslint *.js", - "test": "jest --ci --testResultsProcessor=jest-junit --coverage" + "start": "node ./src/server.js", + "pretest": "eslint /src/*.js", + "test": "jest /src --ci --testResultsProcessor=jest-junit --coverage" }, "devDependencies": { "babel-cli": "^6.26.0", diff --git a/sonar-project.properties b/sonar-project.properties index 175de48..009ecb9 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -6,5 +6,5 @@ sonar.projectVersion=1.0 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. # This property is optional if sonar.modules is set. -sonar.sources=. -sonar.javascript.lcov.reportPaths=./coverage \ No newline at end of file +sonar.sources=./src +sonar.javascript.lcov.reportPaths=./coverage/lcov.info \ No newline at end of file diff --git a/app.js b/src/app.js similarity index 100% rename from app.js rename to src/app.js diff --git a/app.test.js b/src/app.test.js similarity index 100% rename from app.test.js rename to src/app.test.js diff --git a/server.js b/src/server.js similarity index 100% rename from server.js rename to src/server.js From 1328676f9a664816972880c32b093a71c32967aa Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 7 Jun 2018 22:27:56 +1200 Subject: [PATCH 53/82] exclude tests --- sonar-project.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 009ecb9..87047dc 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -7,4 +7,5 @@ sonar.projectVersion=1.0 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. # This property is optional if sonar.modules is set. sonar.sources=./src -sonar.javascript.lcov.reportPaths=./coverage/lcov.info \ No newline at end of file +sonar.javascript.lcov.reportPaths=./coverage/lcov.info +sonar.test.exclusions=/src/*.test.js \ No newline at end of file From c6ae13663adadbf17a443fdb9c001b33de307f1e Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 7 Jun 2018 22:38:38 +1200 Subject: [PATCH 54/82] fixing test exlusion path --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 87047dc..3ec8dae 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -8,4 +8,4 @@ sonar.projectVersion=1.0 # This property is optional if sonar.modules is set. sonar.sources=./src sonar.javascript.lcov.reportPaths=./coverage/lcov.info -sonar.test.exclusions=/src/*.test.js \ No newline at end of file +sonar.test.exclusions=./src/*.test.js \ No newline at end of file From 34f7928d69e8792243c27b6671ac494eeef7d83f Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 7 Jun 2018 22:44:20 +1200 Subject: [PATCH 55/82] more exclusion --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 3ec8dae..622cf72 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -8,4 +8,4 @@ sonar.projectVersion=1.0 # This property is optional if sonar.modules is set. sonar.sources=./src sonar.javascript.lcov.reportPaths=./coverage/lcov.info -sonar.test.exclusions=./src/*.test.js \ No newline at end of file +sonar.exclusions=./src/*.test.js \ No newline at end of file From a17c9f2287c5051695c8e0b7e60de522f3a10811 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 7 Jun 2018 22:49:16 +1200 Subject: [PATCH 56/82] forxing the exclusion more --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 622cf72..c8b449f 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -8,4 +8,4 @@ sonar.projectVersion=1.0 # This property is optional if sonar.modules is set. sonar.sources=./src sonar.javascript.lcov.reportPaths=./coverage/lcov.info -sonar.exclusions=./src/*.test.js \ No newline at end of file +sonar.exclusions=./src/app.test.js \ No newline at end of file From 80bbaa4cf497ada176d487c526f0ea9c5f3b01c7 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Thu, 7 Jun 2018 23:06:14 +1200 Subject: [PATCH 57/82] one more attempt to exlude app.test --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index c8b449f..27ae72c 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -8,4 +8,4 @@ sonar.projectVersion=1.0 # This property is optional if sonar.modules is set. sonar.sources=./src sonar.javascript.lcov.reportPaths=./coverage/lcov.info -sonar.exclusions=./src/app.test.js \ No newline at end of file +sonar.exclusions=app.test.js \ No newline at end of file From 3c671b6e8fd83ea5d7036c0568b5244598fa1ce9 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 08:41:58 +1200 Subject: [PATCH 58/82] moving tests to seperate directory --- junit.xml | 6 +++--- package.json | 4 ++-- sonar-project.properties | 4 ++-- src/app.js | 6 +++++- {src => tests}/app.test.js | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) rename {src => tests}/app.test.js (75%) diff --git a/junit.xml b/junit.xml index 28467f3..285edc3 100644 --- a/junit.xml +++ b/junit.xml @@ -1,6 +1,6 @@ - - - + + + \ No newline at end of file diff --git a/package.json b/package.json index 47f8212..a990b06 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ }, "scripts": { "start": "node ./src/server.js", - "pretest": "eslint /src/*.js", - "test": "jest /src --ci --testResultsProcessor=jest-junit --coverage" + "pretest": "eslint /src/*.js && eslint /tests/*.js", + "test": "jest . --ci --testResultsProcessor=jest-junit --coverage" }, "devDependencies": { "babel-cli": "^6.26.0", diff --git a/sonar-project.properties b/sonar-project.properties index 27ae72c..8e1f0df 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -6,6 +6,6 @@ sonar.projectVersion=1.0 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. # This property is optional if sonar.modules is set. -sonar.sources=./src +sonar.sources=./src/** sonar.javascript.lcov.reportPaths=./coverage/lcov.info -sonar.exclusions=app.test.js \ No newline at end of file +sonar.test.exclusions=./tests/** \ No newline at end of file diff --git a/src/app.js b/src/app.js index baf7481..10d2fac 100644 --- a/src/app.js +++ b/src/app.js @@ -3,7 +3,11 @@ const express = require('express'); const app = express(); app.get('/', (req, res) => { - res.send('Hello World\n'); + res.send('Hello\n'); +}); + +app.get('/world', (req, res) => { + res.send('Hello world\n'); }); module.exports = app; diff --git a/src/app.test.js b/tests/app.test.js similarity index 75% rename from src/app.test.js rename to tests/app.test.js index ef76ae1..1794506 100644 --- a/src/app.test.js +++ b/tests/app.test.js @@ -1,11 +1,11 @@ const request = require('supertest'); -const app = require('./app.js'); +const app = require('./../src/app.js'); describe('Test the root path', () => { test('It should response the GET method', (done) => { request(app).get('/').then((response) => { expect(response.statusCode).toBe(200); - expect(response.text).toBe('Hello World\n'); + expect(response.text).toBe('Hello\n'); done(); }); }); From 4ec3b9064be16c64844494256238331f619a2ef3 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 08:51:50 +1200 Subject: [PATCH 59/82] dont exclude whats not included --- sonar-project.properties | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sonar-project.properties b/sonar-project.properties index 8e1f0df..009ecb9 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -6,6 +6,5 @@ sonar.projectVersion=1.0 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. # This property is optional if sonar.modules is set. -sonar.sources=./src/** -sonar.javascript.lcov.reportPaths=./coverage/lcov.info -sonar.test.exclusions=./tests/** \ No newline at end of file +sonar.sources=./src +sonar.javascript.lcov.reportPaths=./coverage/lcov.info \ No newline at end of file From 045058975a28381c47ff8c457ed002c0c9a19673 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 09:09:18 +1200 Subject: [PATCH 60/82] adding integration tests --- .gitignore | 3 ++- Jenkinsfile | 20 +++++++++++++++++--- deployment/hello-2.yaml | 8 +++++++- junit.xml | 6 ------ 4 files changed, 26 insertions(+), 11 deletions(-) delete mode 100644 junit.xml diff --git a/.gitignore b/.gitignore index cab0ec4..15f2ae1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /node_modules/* package-lock.json -coverage/* \ No newline at end of file +coverage/* +junit.xml \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index dea833f..c8618ce 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -61,11 +61,25 @@ spec: shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() def hello_image = docker.build("tlitovsk/kubernetes-nodejs-helloworld:${shortCommit}") currentBuild.result = "SUCCESS" - if (env.BRANCH_NAME == 'master') { - hello_image.push() - } + hello_image.push() } } + + stage('Integration tests'){ + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() + testNamespace = ${namespace}-${shortCommit} + sh "kubectl get deployments --namespace=${namespace}" + sh "cd deployment \ + && sed -i s/ver1/${shortCommit}/ hello-2.yaml \ + && kubectl delete ns ${testNamespace} || true \ + && kubectl create ns ${testNamespace}\ + && kubectl create -f hello-service.yaml --namespace=${testNamespace} + && kubectl create -f hello-2.yaml --namespace=${testNamespace}" + sh "kubectl rollout status deployment/hello-deployment --namespace=${testNamespace}" + sh 'curl http://hello-service.${testNamespace}.svc.cluster.local:8080' + + } + if (env.BRANCH_NAME == 'master') { stage('Deploy') { diff --git a/deployment/hello-2.yaml b/deployment/hello-2.yaml index 1a30b3c..cd9c280 100644 --- a/deployment/hello-2.yaml +++ b/deployment/hello-2.yaml @@ -17,4 +17,10 @@ spec: image: tlitovsk/kubernetes-nodejs-helloworld:ver1 imagePullPolicy: Always ports: - - containerPort: 8080 \ No newline at end of file + - containerPort: 8080 + livenessProbe: + httpGet: + path: / + port: 8080 + initialDelaySeconds: 3 + periodSeconds: 3 \ No newline at end of file diff --git a/junit.xml b/junit.xml deleted file mode 100644 index 285edc3..0000000 --- a/junit.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From a43be4a0e68ce6eefbdc744b169d79a5d385d673 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 09:10:49 +1200 Subject: [PATCH 61/82] Proper clean up --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index c8618ce..61668a2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -77,6 +77,7 @@ spec: && kubectl create -f hello-2.yaml --namespace=${testNamespace}" sh "kubectl rollout status deployment/hello-deployment --namespace=${testNamespace}" sh 'curl http://hello-service.${testNamespace}.svc.cluster.local:8080' + sh "kubectl delete ns ${testNamespace}" } From da3f9a0000ae28f0c8bb96ce776da5ea89c61cd9 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 09:15:11 +1200 Subject: [PATCH 62/82] fixing line break typo --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 61668a2..c126899 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -73,7 +73,7 @@ spec: && sed -i s/ver1/${shortCommit}/ hello-2.yaml \ && kubectl delete ns ${testNamespace} || true \ && kubectl create ns ${testNamespace}\ - && kubectl create -f hello-service.yaml --namespace=${testNamespace} + && kubectl create -f hello-service.yaml --namespace=${testNamespace}\ && kubectl create -f hello-2.yaml --namespace=${testNamespace}" sh "kubectl rollout status deployment/hello-deployment --namespace=${testNamespace}" sh 'curl http://hello-service.${testNamespace}.svc.cluster.local:8080' From c31abf336422da6c0b5b6e40e2dec72b6134ee57 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 09:22:07 +1200 Subject: [PATCH 63/82] fixng the groovy --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c126899..14eba45 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -67,7 +67,7 @@ spec: stage('Integration tests'){ shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - testNamespace = ${namespace}-${shortCommit} + testNamespace = "${namespace}-${shortCommit}" sh "kubectl get deployments --namespace=${namespace}" sh "cd deployment \ && sed -i s/ver1/${shortCommit}/ hello-2.yaml \ @@ -76,7 +76,7 @@ spec: && kubectl create -f hello-service.yaml --namespace=${testNamespace}\ && kubectl create -f hello-2.yaml --namespace=${testNamespace}" sh "kubectl rollout status deployment/hello-deployment --namespace=${testNamespace}" - sh 'curl http://hello-service.${testNamespace}.svc.cluster.local:8080' + sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080" sh "kubectl delete ns ${testNamespace}" } From 64357c6a8929fd94e5bdc73d035216472b73404d Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 09:44:31 +1200 Subject: [PATCH 64/82] Fixing service name --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 14eba45..6a658c8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -68,12 +68,12 @@ spec: stage('Integration tests'){ shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() testNamespace = "${namespace}-${shortCommit}" - sh "kubectl get deployments --namespace=${namespace}" + sh "kubectl get deployments --namespace=${testNamespace}" sh "cd deployment \ && sed -i s/ver1/${shortCommit}/ hello-2.yaml \ && kubectl delete ns ${testNamespace} || true \ && kubectl create ns ${testNamespace}\ - && kubectl create -f hello-service.yaml --namespace=${testNamespace}\ + && kubectl create -f hello-3-service.yaml --namespace=${testNamespace}\ && kubectl create -f hello-2.yaml --namespace=${testNamespace}" sh "kubectl rollout status deployment/hello-deployment --namespace=${testNamespace}" sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080" From 39e929fd44efd1b37c250d54b820a4252cfb0d3b Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 09:53:04 +1200 Subject: [PATCH 65/82] adding more error handling and namespace seperation --- Jenkinsfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6a658c8..063857f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -67,7 +67,7 @@ spec: stage('Integration tests'){ shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - testNamespace = "${namespace}-${shortCommit}" + testNamespace = "${namespace}-${shortCommit}-${BUILD_NUMBER}" sh "kubectl get deployments --namespace=${testNamespace}" sh "cd deployment \ && sed -i s/ver1/${shortCommit}/ hello-2.yaml \ @@ -99,8 +99,10 @@ spec: } } catch (err) { - currentBuild.result = "FAILURE" + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() + testNamespace = "${namespace}-${shortCommit}-${BUILD_NUMBER}" + sh 'kubectl delete ns ${testNamespace} || true' throw err } From f80dfa6cc8f58ad362d428ccde9107cc19e70c9f Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 10:08:57 +1200 Subject: [PATCH 66/82] Making failed test --- tests/app.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/app.test.js b/tests/app.test.js index 1794506..347eda6 100644 --- a/tests/app.test.js +++ b/tests/app.test.js @@ -10,3 +10,13 @@ describe('Test the root path', () => { }); }); }); + +describe('Test the world path', () => { + test('It should response the GET method', (done) => { + request(app).get('/world').then((response) => { + expect(response.statusCode).toBe(200); + expect(response.text).toBe('Hello world1\n'); + done(); + }); + }); +}); From 8f6b86fec80714b04acb1e2c801cfd0baca8d9f8 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 10:14:56 +1200 Subject: [PATCH 67/82] fixing tests and deployments --- Jenkinsfile | 46 ++++++++++++++++++++++++---------------------- tests/app.test.js | 2 +- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 063857f..17b55a0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -49,11 +49,13 @@ spec: sh 'npm test' junit('junit.xml') } - stage ('SonarQube analysis') - { - withSonarQubeEnv('QubeR') { - // requires SonarQube Scanner for Maven 3.2+ - sh '/usr/lib/node_modules/sonarqube-scanner/dist/bin/sonar-scanner' + if (env.BRANCH_NAME != 'master') { + stage ('SonarQube analysis') + { + withSonarQubeEnv('QubeR') { + // requires SonarQube Scanner for Maven 3.2+ + sh '/usr/lib/node_modules/sonarqube-scanner/dist/bin/sonar-scanner' + } } } stage('Build'){ @@ -64,24 +66,24 @@ spec: hello_image.push() } } - - stage('Integration tests'){ - shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() - testNamespace = "${namespace}-${shortCommit}-${BUILD_NUMBER}" - sh "kubectl get deployments --namespace=${testNamespace}" - sh "cd deployment \ - && sed -i s/ver1/${shortCommit}/ hello-2.yaml \ - && kubectl delete ns ${testNamespace} || true \ - && kubectl create ns ${testNamespace}\ - && kubectl create -f hello-3-service.yaml --namespace=${testNamespace}\ - && kubectl create -f hello-2.yaml --namespace=${testNamespace}" - sh "kubectl rollout status deployment/hello-deployment --namespace=${testNamespace}" - sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080" - sh "kubectl delete ns ${testNamespace}" - - } - if (env.BRANCH_NAME == 'master') { + stage('Integration tests'){ + shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() + testNamespace = "${namespace}-${shortCommit}-${BUILD_NUMBER}" + sh "kubectl get deployments --namespace=${testNamespace}" + sh "cd deployment \ + && sed -i s/ver1/${shortCommit}/ hello-2.yaml \ + && kubectl delete ns ${testNamespace} || true \ + && kubectl create ns ${testNamespace}\ + && kubectl create -f hello-3-service.yaml --namespace=${testNamespace}\ + && kubectl create -f hello-2.yaml --namespace=${testNamespace}" + sh "kubectl rollout status deployment/hello-deployment --namespace=${testNamespace}" + sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080" + sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080/world" + sh "kubectl delete ns ${testNamespace}" + + } + }else{ stage('Deploy') { shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() diff --git a/tests/app.test.js b/tests/app.test.js index 347eda6..422ad85 100644 --- a/tests/app.test.js +++ b/tests/app.test.js @@ -15,7 +15,7 @@ describe('Test the world path', () => { test('It should response the GET method', (done) => { request(app).get('/world').then((response) => { expect(response.statusCode).toBe(200); - expect(response.text).toBe('Hello world1\n'); + expect(response.text).toBe('Hello world\n'); done(); }); }); From 442364976f88f6798882d18dd146754c36140940 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 10:18:49 +1200 Subject: [PATCH 68/82] we test if not master --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 17b55a0..d861ea8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -66,7 +66,7 @@ spec: hello_image.push() } } - if (env.BRANCH_NAME == 'master') { + if (env.BRANCH_NAME != 'master') { stage('Integration tests'){ shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim() testNamespace = "${namespace}-${shortCommit}-${BUILD_NUMBER}" From 129cc0144732fc13a06fe9b3b2f0babeadf8da9c Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 10:18:49 +1200 Subject: [PATCH 69/82] we test if not master --- src/app.js | 4 ++++ tests/app.test.js | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/app.js b/src/app.js index 10d2fac..22380b6 100644 --- a/src/app.js +++ b/src/app.js @@ -10,5 +10,9 @@ app.get('/world', (req, res) => { res.send('Hello world\n'); }); +app.get('/vodafone', (req, res) => { + res.send('Hello Vodafone\n'); +}); + module.exports = app; diff --git a/tests/app.test.js b/tests/app.test.js index 422ad85..f6a7784 100644 --- a/tests/app.test.js +++ b/tests/app.test.js @@ -20,3 +20,14 @@ describe('Test the world path', () => { }); }); }); + +describe('Test the world path', () => { + test('It should response the GET method', (done) => { + request(app).get('/vodafone').then((response) => { + expect(response.statusCode).toBe(200); + expect(response.text).toBe('Hello Vodafone\n'); + done(); + }); + }); +}); + From 42cca33f5c4de17cae20c224e295f31f8c8db71a Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 10:39:48 +1200 Subject: [PATCH 70/82] waiting for tests --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index d861ea8..531ecb8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -77,6 +77,7 @@ spec: && kubectl create ns ${testNamespace}\ && kubectl create -f hello-3-service.yaml --namespace=${testNamespace}\ && kubectl create -f hello-2.yaml --namespace=${testNamespace}" + sh "sleep 3" sh "kubectl rollout status deployment/hello-deployment --namespace=${testNamespace}" sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080" sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080/world" From 3618404491177af36b655eed7dc7a286e883d642 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 11:10:17 +1200 Subject: [PATCH 71/82] prep for a demo --- Jenkinsfile | 1 + src/app.js | 6 +++--- tests/app.test.js | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 531ecb8..9f49211 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -81,6 +81,7 @@ spec: sh "kubectl rollout status deployment/hello-deployment --namespace=${testNamespace}" sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080" sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080/world" + //sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080/vodafone" // sh "kubectl delete ns ${testNamespace}" } diff --git a/src/app.js b/src/app.js index 22380b6..e704fac 100644 --- a/src/app.js +++ b/src/app.js @@ -10,9 +10,9 @@ app.get('/world', (req, res) => { res.send('Hello world\n'); }); -app.get('/vodafone', (req, res) => { - res.send('Hello Vodafone\n'); -}); +//app.get('/vodafone', (req, res) => { +// res.send('Hello Vodafone\n'); +//}); module.exports = app; diff --git a/tests/app.test.js b/tests/app.test.js index f6a7784..be5ea5f 100644 --- a/tests/app.test.js +++ b/tests/app.test.js @@ -21,7 +21,8 @@ describe('Test the world path', () => { }); }); -describe('Test the world path', () => { +/* +describe('Test the vodafone path', () => { test('It should response the GET method', (done) => { request(app).get('/vodafone').then((response) => { expect(response.statusCode).toBe(200); @@ -30,4 +31,4 @@ describe('Test the world path', () => { }); }); }); - +*/ From 2446e2a61ef82236865cbfa9af76a8fe50bc26e3 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 12:47:52 +1200 Subject: [PATCH 72/82] readme fixes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 16f77d8..5129b56 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ ## To build a container: docker build -t tlitovsk/kubernetes-nodejs-helloworld:ver1 . docker build -t tlitovsk/kubernetes-nodejs-helloworld:ver2 . -docker build -t tlitovsk/kubernetes-nodejs-helloworld:latest . ## Push it docker push tlitovsk/kubernetes-nodejs-helloworld:ver1 @@ -17,3 +16,4 @@ https://128.199.223.176/hello ## To build the test container docker build --rm -t tlitovsk/jenkins-jnlp:latest . + From f13b994af9103771e03243b05c5146c43873b48c Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Fri, 8 Jun 2018 16:30:20 +1200 Subject: [PATCH 73/82] Adding vodafone hello --- Jenkinsfile | 2 +- src/app.js | 6 +++--- tests/app.test.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9f49211..edfdb76 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -81,7 +81,7 @@ spec: sh "kubectl rollout status deployment/hello-deployment --namespace=${testNamespace}" sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080" sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080/world" - //sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080/vodafone" // + sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080/vodafone" // sh "kubectl delete ns ${testNamespace}" } diff --git a/src/app.js b/src/app.js index e704fac..22380b6 100644 --- a/src/app.js +++ b/src/app.js @@ -10,9 +10,9 @@ app.get('/world', (req, res) => { res.send('Hello world\n'); }); -//app.get('/vodafone', (req, res) => { -// res.send('Hello Vodafone\n'); -//}); +app.get('/vodafone', (req, res) => { + res.send('Hello Vodafone\n'); +}); module.exports = app; diff --git a/tests/app.test.js b/tests/app.test.js index be5ea5f..5fc6505 100644 --- a/tests/app.test.js +++ b/tests/app.test.js @@ -21,7 +21,7 @@ describe('Test the world path', () => { }); }); -/* + describe('Test the vodafone path', () => { test('It should response the GET method', (done) => { request(app).get('/vodafone').then((response) => { @@ -31,4 +31,4 @@ describe('Test the vodafone path', () => { }); }); }); -*/ + From eb8121becd2b34294f62af469a609644183fb3cd Mon Sep 17 00:00:00 2001 From: Tolik Litovsky Date: Mon, 11 Jun 2018 00:53:34 +1200 Subject: [PATCH 74/82] adding certs managments --- deployment/hello-4-ingress.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deployment/hello-4-ingress.yaml b/deployment/hello-4-ingress.yaml index 34312ac..8d36449 100644 --- a/deployment/hello-4-ingress.yaml +++ b/deployment/hello-4-ingress.yaml @@ -4,9 +4,11 @@ metadata: name: hello-ingress annotations: nginx.ingress.kubernetes.io/rewrite-target: / + certmanager.k8s.io/cluster-issuer: letsencrypt-prod spec: rules: - - http: + - host: prod.devtrails.co.nz + http: paths: - path: /hello backend: From a90fd7a4089a3697fe3b82e75c2a74ceb3dab549 Mon Sep 17 00:00:00 2001 From: Tolik Litovsky Date: Mon, 11 Jun 2018 08:32:19 +1200 Subject: [PATCH 75/82] let senc --- deployment/hello-4-ingress.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/deployment/hello-4-ingress.yaml b/deployment/hello-4-ingress.yaml index 8d36449..d37daf4 100644 --- a/deployment/hello-4-ingress.yaml +++ b/deployment/hello-4-ingress.yaml @@ -4,13 +4,16 @@ metadata: name: hello-ingress annotations: nginx.ingress.kubernetes.io/rewrite-target: / - certmanager.k8s.io/cluster-issuer: letsencrypt-prod spec: rules: - - host: prod.devtrails.co.nz + - host: test.devtrails.co.nz http: paths: - path: /hello backend: serviceName: hello-service - servicePort: 8080 \ No newline at end of file + servicePort: 8080 + tls: + - secretName: test-devtrails-crt-secret + hosts: + - test.devtrails.co.nz \ No newline at end of file From de55923afecfcab9373b3058c7989c8314858780 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 11 Jun 2018 11:25:02 +1200 Subject: [PATCH 76/82] using certs from the cluster --- deployment/hello-4-ingress-ssl.yaml | 19 +++++++++++++++++++ deployment/hello-4-ingress.yaml | 9 ++------- 2 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 deployment/hello-4-ingress-ssl.yaml diff --git a/deployment/hello-4-ingress-ssl.yaml b/deployment/hello-4-ingress-ssl.yaml new file mode 100644 index 0000000..d37daf4 --- /dev/null +++ b/deployment/hello-4-ingress-ssl.yaml @@ -0,0 +1,19 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: hello-ingress + annotations: + nginx.ingress.kubernetes.io/rewrite-target: / +spec: + rules: + - host: test.devtrails.co.nz + http: + paths: + - path: /hello + backend: + serviceName: hello-service + servicePort: 8080 + tls: + - secretName: test-devtrails-crt-secret + hosts: + - test.devtrails.co.nz \ No newline at end of file diff --git a/deployment/hello-4-ingress.yaml b/deployment/hello-4-ingress.yaml index d37daf4..34312ac 100644 --- a/deployment/hello-4-ingress.yaml +++ b/deployment/hello-4-ingress.yaml @@ -6,14 +6,9 @@ metadata: nginx.ingress.kubernetes.io/rewrite-target: / spec: rules: - - host: test.devtrails.co.nz - http: + - http: paths: - path: /hello backend: serviceName: hello-service - servicePort: 8080 - tls: - - secretName: test-devtrails-crt-secret - hosts: - - test.devtrails.co.nz \ No newline at end of file + servicePort: 8080 \ No newline at end of file From 044643fab6c4791374448fd7239c27b6a5b99af4 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 11 Jun 2018 13:50:01 +1200 Subject: [PATCH 77/82] testing the verification step --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index edfdb76..9bdedd6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -82,6 +82,7 @@ spec: sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080" sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080/world" sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080/vodafone" // + sh "curl http://hello-service.${namespace}.svc.cluster.local:8080" sh "kubectl delete ns ${testNamespace}" } @@ -98,7 +99,7 @@ spec: } stage('Verify') { - sh 'curl http://hello-service.example-hello-world.svc.cluster.local:8080' + sh "curl http://hello-service.${namespace}.svc.cluster.local:8080" } } } From 9d98536bd3da14008b722ffca044548482a66f9e Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 11 Jun 2018 13:58:10 +1200 Subject: [PATCH 78/82] testing real world connection --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9bdedd6..6d11e8c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -82,7 +82,6 @@ spec: sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080" sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080/world" sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080/vodafone" // - sh "curl http://hello-service.${namespace}.svc.cluster.local:8080" sh "kubectl delete ns ${testNamespace}" } @@ -99,7 +98,7 @@ spec: } stage('Verify') { - sh "curl http://hello-service.${namespace}.svc.cluster.local:8080" + sh "curl http://prod.devtrails.co.nz/hello" } } } From 1e2f2d6558f7d03401077bf8c23047734febe6f0 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Mon, 11 Jun 2018 14:37:56 +1200 Subject: [PATCH 79/82] switching to https --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6d11e8c..e9ae762 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -98,7 +98,7 @@ spec: } stage('Verify') { - sh "curl http://prod.devtrails.co.nz/hello" + sh "curl https://prod.devtrails.co.nz/hello" } } } From 5e0cfa8d18224e62555a59fbc1a7060c13800404 Mon Sep 17 00:00:00 2001 From: Tolik Litovsky Date: Tue, 12 Jun 2018 22:16:24 +1200 Subject: [PATCH 80/82] fixing the ingress web site --- deployment/hello-4-ingress-ssl.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deployment/hello-4-ingress-ssl.yaml b/deployment/hello-4-ingress-ssl.yaml index d37daf4..759a0c3 100644 --- a/deployment/hello-4-ingress-ssl.yaml +++ b/deployment/hello-4-ingress-ssl.yaml @@ -6,7 +6,7 @@ metadata: nginx.ingress.kubernetes.io/rewrite-target: / spec: rules: - - host: test.devtrails.co.nz + - host: prod.devtrails.co.nz http: paths: - path: /hello @@ -14,6 +14,6 @@ spec: serviceName: hello-service servicePort: 8080 tls: - - secretName: test-devtrails-crt-secret + - secretName: prod-devtrails-crt-secret hosts: - - test.devtrails.co.nz \ No newline at end of file + - prod.devtrails.co.nz \ No newline at end of file From 8fdfa2b7cc08c9671587ec6c0b8f160c1b5e4eb4 Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Wed, 13 Jun 2018 14:36:57 +1200 Subject: [PATCH 81/82] switching hosts --- deployment/hello-4-ingress-ssl.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deployment/hello-4-ingress-ssl.yaml b/deployment/hello-4-ingress-ssl.yaml index 759a0c3..d37daf4 100644 --- a/deployment/hello-4-ingress-ssl.yaml +++ b/deployment/hello-4-ingress-ssl.yaml @@ -6,7 +6,7 @@ metadata: nginx.ingress.kubernetes.io/rewrite-target: / spec: rules: - - host: prod.devtrails.co.nz + - host: test.devtrails.co.nz http: paths: - path: /hello @@ -14,6 +14,6 @@ spec: serviceName: hello-service servicePort: 8080 tls: - - secretName: prod-devtrails-crt-secret + - secretName: test-devtrails-crt-secret hosts: - - prod.devtrails.co.nz \ No newline at end of file + - test.devtrails.co.nz \ No newline at end of file From dd8bf3b869d655058b6c6c2de3f2df53c7668c1e Mon Sep 17 00:00:00 2001 From: Anatoly Litovsky Date: Wed, 13 Jun 2018 14:39:26 +1200 Subject: [PATCH 82/82] fixing verify --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index e9ae762..cfc4a27 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -98,7 +98,7 @@ spec: } stage('Verify') { - sh "curl https://prod.devtrails.co.nz/hello" + sh "curl https://test.devtrails.co.nz/hello" } } }