Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
bbe4e2d
Moving it from docker to k8s example
May 18, 2018
bb17dd3
From Pod to Ingress
May 21, 2018
c9cc1f7
More readme for the demo
May 22, 2018
fccf189
adding pull policy and switch to versioned containers
May 27, 2018
9b4d4c4
Adding jenkins file
May 28, 2018
cddace4
removing extension on jenkins file
May 28, 2018
589e82e
fixing the node tempate
May 28, 2018
83952c6
Now lets make some node js testing
May 28, 2018
3f4b89b
Some quick fixes
May 28, 2018
cf8a71b
Fixing more eslint errors
May 28, 2018
e7199d7
Remove the build container stage will be done by the rancher ci
May 28, 2018
5f16ae1
Some unit testing
May 28, 2018
3fbf3a4
Readme and file clenaup
May 30, 2018
695b07a
Merge pull request #2 from tlitovsk/organizeReadme
tlitovsk May 30, 2018
8d807aa
Merge branch 'master' into nodejsTesting
tlitovsk May 30, 2018
13e8c98
Linting dockerfiles
May 31, 2018
37b4a6c
Refactoring the code to enable unit testing, adding linting
May 31, 2018
35aade0
Readme formating update
May 31, 2018
5ac750d
Fixing user argument statment
May 31, 2018
80fdb68
Merge pull request #1 from tlitovsk/nodejsTesting
tlitovsk May 31, 2018
b359cd5
Reorganizing the charts
May 31, 2018
030c56e
Building the image
May 31, 2018
be4cfd2
Adding junit results
May 31, 2018
acffae2
Adding docker into the test container
May 31, 2018
acf830b
Cosmetic image name change
May 31, 2018
2d8ec78
fix post command location
May 31, 2018
3215f62
fixing the catch location
May 31, 2018
34646d5
Comment out docker push for now
May 31, 2018
f036f12
fixing to scripted pipeline
May 31, 2018
f9844a2
Adding credentials to docker hub
Jun 1, 2018
6b6efd3
adding user
Jun 1, 2018
1ba6702
Adding push on master only and testing kubectl
Jun 1, 2018
f7ee753
lets try dyncamic yaml desc
Jun 1, 2018
aff2da9
Connecting to right cloud
Jun 1, 2018
b8b50d1
space change and brackets
Jun 1, 2018
8fbec76
Adding kubectl to test container
Jun 1, 2018
83a421f
specifing the namespace
Jun 1, 2018
8310724
giving a different jenkins account
Jun 1, 2018
64f319d
And updating deploy
Jun 1, 2018
e476d01
adding verify stage
Jun 1, 2018
33772f6
Adding push for pull request for a second
Jun 1, 2018
f994cf2
typo fix verify
Jun 1, 2018
4e99e92
fixing namspace
Jun 1, 2018
2ca1dd7
rollout on master only
Jun 1, 2018
b48bd45
update the result in proper place
Jun 1, 2018
c929fad
Gary change
Jun 1, 2018
691849a
Fixing the name
Jun 1, 2018
90645a0
adding test results to git ignore
Jun 5, 2018
e2e92ef
updating build enviroment to avoid secrets in cluster
Jun 7, 2018
f551106
prepearing for demo
Jun 7, 2018
afdf6cb
fixing the test
Jun 7, 2018
99d9f17
Adding sonarq step
Jun 7, 2018
727ec95
adding full path
Jun 7, 2018
bb99cd0
adding code coverage
Jun 7, 2018
768479d
Moving src files to src
Jun 7, 2018
1328676
exclude tests
Jun 7, 2018
c6ae136
fixing test exlusion path
Jun 7, 2018
34f7928
more exclusion
Jun 7, 2018
a17c9f2
forxing the exclusion more
Jun 7, 2018
80bbaa4
one more attempt to exlude app.test
Jun 7, 2018
3c671b6
moving tests to seperate directory
Jun 7, 2018
4ec3b90
dont exclude whats not included
Jun 7, 2018
0450589
adding integration tests
Jun 7, 2018
a43be4a
Proper clean up
Jun 7, 2018
da3f9a0
fixing line break typo
Jun 7, 2018
c31abf3
fixng the groovy
Jun 7, 2018
64357c6
Fixing service name
Jun 7, 2018
39e929f
adding more error handling and namespace seperation
Jun 7, 2018
f80dfa6
Making failed test
Jun 7, 2018
8f6b86f
fixing tests and deployments
Jun 7, 2018
4423649
we test if not master
Jun 7, 2018
129cc01
we test if not master
Jun 7, 2018
42cca33
waiting for tests
Jun 7, 2018
3618404
prep for a demo
Jun 7, 2018
2446e2a
readme fixes
Jun 8, 2018
f13b994
Adding vodafone hello
Jun 8, 2018
eb8121b
adding certs managments
tlitovsk Jun 10, 2018
a90fd7a
let senc
tlitovsk Jun 10, 2018
de55923
using certs from the cluster
Jun 10, 2018
044643f
testing the verification step
Jun 11, 2018
9d98536
testing real world connection
Jun 11, 2018
1e2f2d6
switching to https
Jun 11, 2018
5e0cfa8
fixing the ingress web site
tlitovsk Jun 12, 2018
8fdfa2b
switching hosts
Jun 13, 2018
dd8bf3b
fixing verify
Jun 13, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
"extends": "airbnb-base",
"plugins":["jasmine"],
"env": {
"jasmine": true,
"jest":true
}
};
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/node_modules/*
package-lock.json
coverage/*
junit.xml
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ WORKDIR /web
RUN npm install

EXPOSE 8080
ENTRYPOINT ["nodejs", "./index.js"]
ENTRYPOINT ["npm", "start"]
114 changes: 114 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
def namespace = "example-hello-world"
def label = "mypod-${UUID.randomUUID().toString()}"
podTemplate(label: label, serviceAccount: "jenkins", cloud: "example", 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
- 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) {
try {
stage('Checkout'){
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'
junit('junit.xml')
}
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'){
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"
hello_image.push()
}
}
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 "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"
sh "curl http://hello-service.${testNamespace}.svc.cluster.local:8080/vodafone" //
sh "kubectl delete ns ${testNamespace}"

}
}else{
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 https://test.devtrails.co.nz/hello"
}
}
}
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
}

}
}
22 changes: 0 additions & 22 deletions Makefile

This file was deleted.

33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# Docker node.js example app
# Kubernetes node.js example app

To build a container:
```
$ make build
```
## To build a container:
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/
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
docker build --rm -t tlitovsk/jenkins-jnlp:latest .

Following command will start Docker image in background
```
$ make run
```

you can test it with:
```
$ make test
```
or simply run:
```
curl -v localhost:43567
```
21 changes: 21 additions & 0 deletions TestContainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 kubectl && apt-get clean && rm -rf /var/lib/apt/lists/*

RUN npm install -g dockerlint sonarqube-scanner

USER jenkins

ENTRYPOINT ["jenkins-slave"]
#docker build --rm -t tlitovsk/jenkins-jnlp:latest .
18 changes: 18 additions & 0 deletions deployment/hello-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-deployment
spec:
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: tlitovsk/kubernetes-nodejs-helloworld:ver1
imagePullPolicy: Always

26 changes: 26 additions & 0 deletions deployment/hello-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-deployment
spec:
replicas: 3
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: tlitovsk/kubernetes-nodejs-helloworld:ver1
imagePullPolicy: Always
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 3
periodSeconds: 3
11 changes: 11 additions & 0 deletions deployment/hello-3-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kind: Service
apiVersion: v1
metadata:
name: hello-service
spec:
selector:
app: hello-world
ports:
- protocol: TCP
port: 8080
targetPort: 8080
19 changes: 19 additions & 0 deletions deployment/hello-4-ingress-ssl.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions deployment/hello-4-ingress.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 0 additions & 14 deletions index.js

This file was deleted.

Loading