Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker container implement to deploy with docker swarm cluster and kubernetes #36

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b969a0b
Dockerized node-todo
uzzal2k5 Sep 21, 2018
a713a34
Dockerized node-todo
uzzal2k5 Sep 21, 2018
a947625
node-todo deploy with docker-compose
uzzal2k5 Sep 21, 2018
fd6d548
node-todo deploy with docker-compose
uzzal2k5 Sep 21, 2018
6edd817
YML update
uzzal2k5 Sep 22, 2018
ab065da
mongodb
uzzal2k5 Sep 22, 2018
0e70b72
mongodb
uzzal2k5 Sep 22, 2018
bc503e7
K8s configuration
uzzal2k5 Sep 22, 2018
ffa60e0
K8s configuration
uzzal2k5 Sep 22, 2018
e569379
Update k8s config
uzzal2k5 Sep 22, 2018
cff99c8
Jenkinsfile Written for CI/CD
uzzal2k5 Sep 22, 2018
4f0f718
Deploying with replication controller
uzzal2k5 Sep 22, 2018
3cf3435
update node-todo app Replication
uzzal2k5 Sep 23, 2018
3122805
dockerIgnore
uzzal2k5 Sep 23, 2018
fe7f57d
Jenkinsfile & Doccerment Write
uzzal2k5 Sep 23, 2018
4f075eb
Update Doccerment Write
uzzal2k5 Sep 23, 2018
8fe28e9
Update Jenkinsfile
uzzal2k5 Oct 5, 2018
348c1e4
Update Jenkinsfile
uzzal2k5 Oct 5, 2018
fb94f90
Update Jenkinsfile
uzzal2k5 Oct 5, 2018
1c8bec3
Update Jenkinsfile
uzzal2k5 Oct 5, 2018
369a5d3
Update Jenkinsfile
uzzal2k5 Oct 5, 2018
81513cb
Update Jenkinsfile
uzzal2k5 Oct 5, 2018
d22922d
Update Jenkinsfile
uzzal2k5 Jun 30, 2020
f82d104
Update Jenkinsfile
uzzal2k5 Jun 30, 2020
bb6531f
Integrate Synk
uzzalbjit May 21, 2023
4d7eed1
Jenkinsfile
uzzalbjit May 21, 2023
52ab680
Jenkins
uzzalbjit May 22, 2023
3368571
Jenkins
uzzalbjit May 22, 2023
449c4c2
Jenkins
uzzalbjit May 22, 2023
64dbf50
Jenkins
uzzalbjit May 22, 2023
5d47119
Dockerfile
uzzalbjit May 22, 2023
d7cec1c
Dockerfile
uzzalbjit May 22, 2023
41e1d2a
Dockerfile
uzzalbjit May 22, 2023
533a0de
Dockerfile
uzzalbjit May 22, 2023
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
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Dockerfile
.gitignore
.dockerignore
.git
README.md
README_es.md
mongodb
mongodb/*
docker-compose.yml
license
aws-k8s-replication.yml
k8s-node-todo.yml
Jenkinsfile
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ results

npm-debug.log
node_modules
mongodb
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:alpine
MAINTAINER uzzal, [email protected]
WORKDIR /node-todo
COPY . .
RUN npm install

# CONFIG STANDARD ERROR LOG
RUN ln -sf /dev/stdout /var/log/access.log \
&& ln -sf /dev/stderr /var/log/error.log

# SET HEALTH CHECK
HEALTHCHECK --interval=5s \
--timeout=5s \
CMD curl -f http://127.0.0.1:8000 || exit 1

RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/main' >> /etc/apk/repositories
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/community' >> /etc/apk/repositories
RUN apk update
#RUN apk add mongodb=3.4.4-r0
#RUN mongo --version
EXPOSE 8080


ENTRYPOINT ["node", "server.js"]
134 changes: 134 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!groovy
import groovy.json.JsonSlurperClassic
def DOCKER_BUILD_SERVER = "unix:///var/run/docker.sock"
def DOCKER_IMAGE_REPOSITORY = "uzzal2k5"
def GIT_REPOSITORY_NAME = "https://github.com/uzzal2k5/node-todo.git"
def version, revision
def BRANCH = 'master'


//Version & Release Specified Here
def getVersion(def projectJson){
def slurper = new JsonSlurperClassic()
project = slurper.parseText(projectJson)
slurper = null
return project.version.split('-')[0]
}


// REPOSITORY CLONE FROM GIT
def CloneFromGit( REPOSITORY_NAME,BRANCH ){
def version, revision
try {
git(branch: "${BRANCH}",
changelog: true,
credentialsId: 'github_credentials',
poll: true,
url: "${REPOSITORY_NAME }"
)
}
catch (Exception e) {
println 'Some Exception happened here '
throw e

}
finally {
revision = version + "-" + sprintf("%04d", env.BUILD_NUMBER.toInteger())
println "Start building revision $revision"

}
return this
}


// DOCKER IMAGE BUILD & PUSH TO REGISTRY
// def DockerImageBuild( DOCKER_BUILD_SERVER, IMAGE_REPOSITORY, IMAGE_NAME ){
//
// // DOCKER IMAGE BUILD
// withDockerServer([uri: "${DOCKER_BUILD_SERVER}"]) {
// stage('IMAGE BUILD'){
// todoImages = docker.build("${IMAGE_REPOSITORY}/${IMAGE_NAME}")
// }

//
// //PUSH TO REGISTRY
// stage('PUSH IMAGE'){
// withDockerRegistry(credentialsId: 'dockerhub_credentials', url: '') {
// todoImages.push("${env.BUILD_NUMBER}")
// todoImages.push("latest")
// }
//
// }
//
// }
// return this
// }
// def ScanWithSynk(){
// snykSecurity(
// organisation: 'uzzal2k5',
// projectName: 'uzzal2k5/node-todo',
// severity: 'medium',
// snykInstallation: 'snyk-latest',
// snykTokenId: 'synk_api_token',
// targetFile: '/Users/uzzal/.jenkins/workspace/synk-project/Dockerfile',
// failOnIssues: false
// )
//
// return this
// }

// BUILD NODE
pipeline {
environment {
IMAGE_NAME = "node-todo"
todoImages = ''
IMAGE_REPOSITORY = "uzzal2k5"
}

agent any
stages {

stage('GIT CLONE') {
steps {
CloneFromGit(GIT_REPOSITORY_NAME, BRANCH)
}
}
stage('IMAGE BUILD'){
steps {
script {
todoImages = docker.build("${IMAGE_REPOSITORY}/${IMAGE_NAME}")
}
}
}
stage('SCAN'){
steps{
script{
snykSecurity(
organisation: 'uzzal2k5',
projectName: 'uzzal2k5/node-todo',
severity: 'medium',
snykInstallation: 'snyk-latest',
snykTokenId: 'synk_api_token',
failOnIssues: false
)
def variable = sh(
script: 'snyk container test uzzal2k5/node-todo:latest --severity-threshold=medium',
returnStatus: true
)
echo "Error Code = ${variable}"
if (variable !=0){
echo "Alert for Vulnerability Found"
}
}
}
}


}

// DockerImageBuild(DOCKER_BUILD_SERVER,DOCKER_IMAGE_REPOSITORY, IMAGE_NAME)



//NODE END
}
76 changes: 76 additions & 0 deletions aws-k8s-replication.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
apiVersion: v1
kind: Service
metadata:
name: todo-service
labels:
name: todo-service
app: nodeapp
spec:
selector:
name: node-todo
app: todoapp
ports:
- port: 80
name: node-port
targetPort: 8080
protocol: TCP
type: LoadBalancer

---
apiVersion: v1
kind: ReplicationController
metadata:
name: todo-replicas
labels:
name: node-todo
app: todoapp
spec:
replicas: 2
template:
metadata:
name: todo-pod
labels:
name: node-todo
app: todoapp
spec:
containers:
- name: todo-container
image: index.docker.io/uzzal2k5/node-todo:latest
env:
- name: MONGODB_HOST
value: mongodb
ports:
- containerPort: 8080
#imagePullPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: mongodb
labels:
name: mongodb
app: database
spec:
selector:
name: mongodb
app: database
ports:
- port: 27017
name: db-port
targetPort: 27017

---
apiVersion: v1
kind: Pod
metadata:
name: mongodb
labels:
name: mongodb
app: database
spec:
containers:
- name: mongodb
image: mongo:4.0.2
ports:
- containerPort: 27017
4 changes: 2 additions & 2 deletions config/database.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
remoteUrl : 'mongodb://node:[email protected]:27017/uwO3mypu',
remoteUrl : 'mongodb://mongodb:27017/test',
localUrl: 'mongodb://localhost/meanstacktutorials'
};
};
31 changes: 31 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '2.0'
services:
# mongoDB
mongodb:
image: mongo:4.0.2
hostname: mongodb
container_name: mongodb
#environment:
# MONGO_INITDB_ROOT_USERNAME: "uzzal"
# MONGO_INITDB_ROOT_PASSWORD: "password"
ports:
- "27017:27017"
restart: always

# node-todo App
node-todo:
build: .
container_name: todo-container
hostname: node-todo
ports:
- 80:8080/tcp
tty: true
links:
- mongodb
depends_on:
- mongodb
restart: always




Loading