├── .gitignore ├── Dockerfile ├── Dockerrun.aws.json ├── Jenkinsfile ├── ansible ├── dev.inventory └── docker-deploy.yml ├── buildspec.yml ├── changeTag.sh ├── deploy.sh ├── hari.txt ├── helm └── node-app │ ├── .helmignore │ ├── Chart.yaml │ ├── templates │ ├── NOTES.txt │ ├── _helpers.tpl │ ├── deployment.yaml │ ├── ingress.yaml │ ├── service.yaml │ └── tests │ │ └── test-connection.yaml │ └── values.yaml ├── jenkins-config.sh ├── jenkins-docker-ansible ├── jenkinsfile-6pm-dec-2019 ├── package.json ├── pods.yml ├── server.js ├── services.yml ├── skills.txt └── weekend-oct-jenkins-pipeline-1 /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.tgz 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:16 2 | 3 | 4 | 5 | # Create app directory 6 | WORKDIR /usr/src/app 7 | 8 | # Install app dependencies 9 | # A wildcard is used to ensure both package.json AND package-lock.json are copied 10 | # where available (npm@5+) 11 | COPY package*.json ./ 12 | 13 | RUN npm install 14 | # If you are building your code for production 15 | # RUN npm install --only=production 16 | 17 | # Bundle app source 18 | COPY . . 19 | 20 | EXPOSE 8080 21 | CMD [ "npm", "start" ] 22 | 23 | # This is dummy change for git demo 24 | -------------------------------------------------------------------------------- /Dockerrun.aws.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSEBDockerrunVersion": "1", 3 | "Image": { 4 | "Name": "kammana/nodeapp:v1", 5 | "Update": "true" 6 | }, 7 | "Ports": [ 8 | { 9 | "ContainerPort": "8080" 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | environment{ 4 | DOCKER_TAG = getDockerTag() 5 | NEXUS_URL = "172.31.34.232:8080" 6 | IMAGE_URL_WITH_TAG = "${NEXUS_URL}/node-app:${DOCKER_TAG}" 7 | } 8 | stages{ 9 | stage('Build Docker Image'){ 10 | steps{ 11 | sh "docker build . -t ${IMAGE_URL_WITH_TAG}" 12 | } 13 | } 14 | stage('Nexus Push'){ 15 | steps{ 16 | withCredentials([string(credentialsId: 'nexus-pwd', variable: 'nexusPwd')]) { 17 | sh "docker login -u admin -p ${nexusPwd} ${NEXUS_URL}" 18 | sh "docker push ${IMAGE_URL_WITH_TAG}" 19 | } 20 | } 21 | } 22 | stage('Docker Deploy Dev'){ 23 | steps{ 24 | sshagent(['tomcat-dev']) { 25 | withCredentials([string(credentialsId: 'nexus-pwd', variable: 'nexusPwd')]) { 26 | sh "ssh ec2-user@172.31.0.38 docker login -u admin -p ${nexusPwd} ${NEXUS_URL}" 27 | } 28 | // Remove existing container, if container name does not exists still proceed with the build 29 | sh script: "ssh ec2-user@172.31.0.38 docker rm -f nodeapp", returnStatus: true 30 | 31 | sh "ssh ec2-user@172.31.0.38 docker run -d -p 8080:8080 --name nodeapp ${IMAGE_URL_WITH_TAG}" 32 | } 33 | } 34 | } 35 | } 36 | } 37 | 38 | def getDockerTag(){ 39 | def tag = sh script: 'git rev-parse HEAD', returnStdout: true 40 | return tag 41 | } 42 | -------------------------------------------------------------------------------- /ansible/dev.inventory: -------------------------------------------------------------------------------- 1 | 172.31.12.137 ansible_user=ec2-user ansible_connection=ssh 2 | -------------------------------------------------------------------------------- /ansible/docker-deploy.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - hosts: 172.31.12.137 4 | become: True 5 | tasks: 6 | - name: install pip 7 | yum: 8 | name: python-pip 9 | state: present 10 | - name: install docker 11 | yum: 12 | name: docker 13 | state: present 14 | - name: start docker service 15 | service: 16 | name: docker 17 | state: started 18 | enabled: true 19 | - name: install required packages 20 | pip: 21 | name: docker-py 22 | state: present 23 | - name: Create container 24 | docker_container: 25 | name: nodeapp 26 | image: kammana/node-app:{{tag}} 27 | published_ports: ["8080:8080"] 28 | -------------------------------------------------------------------------------- /buildspec.yml: -------------------------------------------------------------------------------- 1 | version: 0.2 2 | 3 | 4 | phases: 5 | pre_build: 6 | commands: 7 | - echo Logging in to Amazon ECR... 8 | - aws --version 9 | - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email) 10 | - REPOSITORY_URI=077708451457.dkr.ecr.ap-south-1.amazonaws.com/node-app 11 | - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) 12 | - IMAGE_TAG=build-$(echo $CODEBUILD_BUILD_ID | awk -F":" '{print $2}') 13 | build: 14 | commands: 15 | - echo Build started on `date` 16 | - echo Building the Docker image... 17 | - docker build -t $REPOSITORY_URI:latest . 18 | - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG 19 | post_build: 20 | commands: 21 | - echo Build completed on `date` 22 | - echo Pushing the Docker images... 23 | - docker push $REPOSITORY_URI:latest 24 | - docker push $REPOSITORY_URI:$IMAGE_TAG 25 | - echo Writing image definitions file... 26 | - printf '[{"name":"nodeapp","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json 27 | - cat imagedefinitions.json 28 | artifacts: 29 | files: imagedefinitions.json 30 | -------------------------------------------------------------------------------- /changeTag.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sed "s/tagVersion/$1/g" pods.yml > node-app-pod.yml 3 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This is to demo 4 | 5 | node_app=`docker ps -a | grep nodeapp | awk '{print $NF}'` 6 | if [ $node_app=='nodeapp' ]; then 7 | echo "nodeapp is running, lets delete" 8 | docker rm -f nodeapp 9 | fi 10 | 11 | images=`docker images | grep kammana/nodejenkins | awk '{print $3}'` 12 | docker rmi $images 13 | docker run -d -p 8080:8080 --name nodeapp $1 14 | -------------------------------------------------------------------------------- /hari.txt: -------------------------------------------------------------------------------- 1 | Hari lives in banglore 2 | Hari works at banglore 3 | Hari works on DevOps 4 | Hari is using Docker in his project 5 | It is likely to rain today 6 | Learning git diff command 7 | Learning git tags 8 | Learning branching strategies 9 | some chage 10 | Demo of git conflict 11 | This change is done by developer 2 12 | -------------------------------------------------------------------------------- /helm/node-app/.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | # Common VCS dirs 6 | .git/ 7 | .gitignore 8 | .bzr/ 9 | .bzrignore 10 | .hg/ 11 | .hgignore 12 | .svn/ 13 | # Common backup files 14 | *.swp 15 | *.bak 16 | *.tmp 17 | *~ 18 | # Various IDEs 19 | .project 20 | .idea/ 21 | *.tmproj 22 | .vscode/ 23 | -------------------------------------------------------------------------------- /helm/node-app/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | appVersion: "1.0" 3 | description: A Helm chart for Kubernetes 4 | name: node-app 5 | version: 0.1.1 6 | -------------------------------------------------------------------------------- /helm/node-app/templates/NOTES.txt: -------------------------------------------------------------------------------- 1 | 1. Get the application URL by running these commands: 2 | {{- if .Values.ingress.enabled }} 3 | {{- range $host := .Values.ingress.hosts }} 4 | {{- range .paths }} 5 | http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }} 6 | {{- end }} 7 | {{- end }} 8 | {{- else if contains "NodePort" .Values.service.type }} 9 | export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "node-app.fullname" . }}) 10 | export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") 11 | echo http://$NODE_IP:$NODE_PORT 12 | {{- else if contains "LoadBalancer" .Values.service.type }} 13 | NOTE: It may take a few minutes for the LoadBalancer IP to be available. 14 | You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "node-app.fullname" . }}' 15 | export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "node-app.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') 16 | echo http://$SERVICE_IP:{{ .Values.service.port }} 17 | {{- else if contains "ClusterIP" .Values.service.type }} 18 | export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "node-app.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") 19 | echo "Visit http://127.0.0.1:8080 to use your application" 20 | kubectl port-forward $POD_NAME 8080:80 21 | {{- end }} 22 | -------------------------------------------------------------------------------- /helm/node-app/templates/_helpers.tpl: -------------------------------------------------------------------------------- 1 | {{/* vim: set filetype=mustache: */}} 2 | {{/* 3 | Expand the name of the chart. 4 | */}} 5 | {{- define "node-app.name" -}} 6 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} 7 | {{- end -}} 8 | 9 | {{/* 10 | Create a default fully qualified app name. 11 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 12 | If release name contains chart name it will be used as a full name. 13 | */}} 14 | {{- define "node-app.fullname" -}} 15 | {{- if .Values.fullnameOverride -}} 16 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} 17 | {{- else -}} 18 | {{- $name := default .Chart.Name .Values.nameOverride -}} 19 | {{- if contains $name .Release.Name -}} 20 | {{- .Release.Name | trunc 63 | trimSuffix "-" -}} 21 | {{- else -}} 22 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} 23 | {{- end -}} 24 | {{- end -}} 25 | {{- end -}} 26 | 27 | {{/* 28 | Create chart name and version as used by the chart label. 29 | */}} 30 | {{- define "node-app.chart" -}} 31 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} 32 | {{- end -}} 33 | -------------------------------------------------------------------------------- /helm/node-app/templates/deployment.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apps/v1 3 | kind: Deployment 4 | metadata: 5 | name: {{ include "node-app.fullname" . }} 6 | labels: 7 | app.kubernetes.io/name: {{ include "node-app.name" . }} 8 | helm.sh/chart: {{ include "node-app.chart" . }} 9 | app.kubernetes.io/instance: {{ .Release.Name }} 10 | app.kubernetes.io/managed-by: {{ .Release.Service }} 11 | spec: 12 | replicas: {{ .Values.replicaCount }} 13 | selector: 14 | matchLabels: 15 | app.kubernetes.io/name: {{ include "node-app.name" . }} 16 | app.kubernetes.io/instance: {{ .Release.Name }} 17 | template: 18 | metadata: 19 | labels: 20 | app.kubernetes.io/name: {{ include "node-app.name" . }} 21 | app.kubernetes.io/instance: {{ .Release.Name }} 22 | spec: 23 | containers: 24 | - name: {{ .Chart.Name }} 25 | image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" 26 | imagePullPolicy: {{ .Values.image.pullPolicy }} 27 | ports: 28 | - name: http 29 | containerPort: 8080 30 | protocol: TCP 31 | livenessProbe: 32 | httpGet: 33 | path: / 34 | port: http 35 | readinessProbe: 36 | httpGet: 37 | path: / 38 | port: http 39 | resources: 40 | {{- toYaml .Values.resources | nindent 12 }} 41 | {{- with .Values.nodeSelector }} 42 | nodeSelector: 43 | {{- toYaml . | nindent 8 }} 44 | {{- end }} 45 | {{- with .Values.affinity }} 46 | affinity: 47 | {{- toYaml . | nindent 8 }} 48 | {{- end }} 49 | {{- with .Values.tolerations }} 50 | tolerations: 51 | {{- toYaml . | nindent 8 }} 52 | {{- end }} 53 | -------------------------------------------------------------------------------- /helm/node-app/templates/ingress.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.ingress.enabled -}} 2 | {{- $fullName := include "node-app.fullname" . -}} 3 | apiVersion: extensions/v1beta1 4 | kind: Ingress 5 | metadata: 6 | name: {{ $fullName }} 7 | labels: 8 | app.kubernetes.io/name: {{ include "node-app.name" . }} 9 | helm.sh/chart: {{ include "node-app.chart" . }} 10 | app.kubernetes.io/instance: {{ .Release.Name }} 11 | app.kubernetes.io/managed-by: {{ .Release.Service }} 12 | {{- with .Values.ingress.annotations }} 13 | annotations: 14 | {{- toYaml . | nindent 4 }} 15 | {{- end }} 16 | spec: 17 | {{- if .Values.ingress.tls }} 18 | tls: 19 | {{- range .Values.ingress.tls }} 20 | - hosts: 21 | {{- range .hosts }} 22 | - {{ . | quote }} 23 | {{- end }} 24 | secretName: {{ .secretName }} 25 | {{- end }} 26 | {{- end }} 27 | rules: 28 | {{- range .Values.ingress.hosts }} 29 | - host: {{ .host | quote }} 30 | http: 31 | paths: 32 | {{- range .paths }} 33 | - path: {{ . }} 34 | backend: 35 | serviceName: {{ $fullName }} 36 | servicePort: http 37 | {{- end }} 38 | {{- end }} 39 | {{- end }} 40 | -------------------------------------------------------------------------------- /helm/node-app/templates/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: {{ include "node-app.fullname" . }} 5 | labels: 6 | app.kubernetes.io/name: {{ include "node-app.name" . }} 7 | helm.sh/chart: {{ include "node-app.chart" . }} 8 | app.kubernetes.io/instance: {{ .Release.Name }} 9 | app.kubernetes.io/managed-by: {{ .Release.Service }} 10 | spec: 11 | type: {{ .Values.service.type }} 12 | ports: 13 | - port: {{ .Values.service.port }} 14 | targetPort: http 15 | protocol: TCP 16 | name: http 17 | selector: 18 | app.kubernetes.io/name: {{ include "node-app.name" . }} 19 | app.kubernetes.io/instance: {{ .Release.Name }} 20 | -------------------------------------------------------------------------------- /helm/node-app/templates/tests/test-connection.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: "{{ include "node-app.fullname" . }}-test-connection" 5 | labels: 6 | app.kubernetes.io/name: {{ include "node-app.name" . }} 7 | helm.sh/chart: {{ include "node-app.chart" . }} 8 | app.kubernetes.io/instance: {{ .Release.Name }} 9 | app.kubernetes.io/managed-by: {{ .Release.Service }} 10 | annotations: 11 | "helm.sh/hook": test-success 12 | spec: 13 | containers: 14 | - name: wget 15 | image: busybox 16 | command: ['wget'] 17 | args: ['{{ include "node-app.fullname" . }}:{{ .Values.service.port }}'] 18 | restartPolicy: Never 19 | -------------------------------------------------------------------------------- /helm/node-app/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for node-app. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | image: 8 | repository: kammana/appone 9 | tag: v1 10 | pullPolicy: IfNotPresent 11 | 12 | nameOverride: "" 13 | fullnameOverride: "" 14 | 15 | service: 16 | type: LoadBalancer 17 | port: 80 18 | 19 | ingress: 20 | enabled: false 21 | annotations: {} 22 | # kubernetes.io/ingress.class: nginx 23 | # kubernetes.io/tls-acme: "true" 24 | hosts: 25 | - host: chart-example.local 26 | paths: [] 27 | 28 | tls: [] 29 | # - secretName: chart-example-tls 30 | # hosts: 31 | # - chart-example.local 32 | 33 | resources: {} 34 | # We usually recommend not to specify default resources and to leave this as a conscious 35 | # choice for the user. This also increases chances charts run on environments with little 36 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 37 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 38 | # limits: 39 | # cpu: 100m 40 | # memory: 128Mi 41 | # requests: 42 | # cpu: 100m 43 | # memory: 128Mi 44 | 45 | nodeSelector: {} 46 | 47 | tolerations: [] 48 | 49 | affinity: {} 50 | -------------------------------------------------------------------------------- /jenkins-config.sh: -------------------------------------------------------------------------------- 1 | app_tag=`git ls-remote https://github.com/javahometech/node-app HEAD | awk '{print $1}'` 2 | 3 | docker_app="kammana/nodejenkins:$app_tag" 4 | docker build -t $docker_app . 5 | 6 | docker login -u kammana -p yourpassword 7 | 8 | docker push $docker_app 9 | 10 | scp -i /var/lib/jenkins/dev.pem deploy.sh ec2-user@172.31.43.90:/tmp 11 | 12 | ssh -i /var/lib/jenkins/dev.pem ec2-user@172.31.43.90 chmod +x /tmp/deploy.sh 13 | 14 | ssh -i /var/lib/jenkins/dev.pem ec2-user@172.31.43.90 /tmp/deploy.sh $docker_app 15 | -------------------------------------------------------------------------------- /jenkins-docker-ansible: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | environment{ 4 | DOCKER_TAG = getDockerTag() 5 | } 6 | stages{ 7 | stage('Build Docker Image'){ 8 | steps{ 9 | sh "docker build . -t kammana/node-app:${DOCKER_TAG} " 10 | } 11 | } 12 | stage('DockerHub Push'){ 13 | steps{ 14 | withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerHubPwd')]) { 15 | sh "docker login -u kammana -p ${dockerHubPwd}" 16 | sh "docker push kammana/node-app:${DOCKER_TAG}" 17 | } 18 | } 19 | } 20 | stage('Deploy to Dev server'){ 21 | steps{ 22 | ansiblePlaybook extras: "-e tag=${env.DOCKER_TAG}", 23 | credentialsId: 'slave-one', 24 | playbook: 'ansible/docker-deploy.yml', 25 | inventory: 'ansible/dev.inventory' 26 | } 27 | } 28 | } 29 | } 30 | 31 | def getDockerTag(){ 32 | def tag = sh script: 'git rev-parse HEAD', returnStdout: true 33 | return tag 34 | } 35 | -------------------------------------------------------------------------------- /jenkinsfile-6pm-dec-2019: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | environment{ 4 | DOCKER_TAG = getDockerTag() 5 | } 6 | stages{ 7 | stage('Build Docker Image'){ 8 | steps{ 9 | sh "docker build . -t kammana/nodeapp:${DOCKER_TAG} " 10 | } 11 | } 12 | stage('DockerHub Push'){ 13 | steps{ 14 | withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerHubPwd')]) { 15 | sh "docker login -u kammana -p ${dockerHubPwd}" 16 | sh "docker push kammana/nodeapp:${DOCKER_TAG}" 17 | } 18 | } 19 | } 20 | stage('Deploy to DevServer'){ 21 | steps{ 22 | sshagent (credentials: ['dev-server']) { 23 | script{ 24 | sh returnStatus: true, script: 'ssh ec2-user@172.31.4.187 docker rm -f nodeapp' 25 | def runCmd = "docker run -d -p 8080:8080 --name=nodeapp kammana/nodeapp:${DOCKER_TAG}" 26 | sh "ssh -o StrictHostKeyChecking=no ec2-user@172.31.4.187 ${runCmd}" 27 | } 28 | } 29 | } 30 | } 31 | } 32 | } 33 | 34 | def getDockerTag(){ 35 | def tag = sh script: 'git rev-parse HEAD', returnStdout: true 36 | return tag 37 | } 38 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docker_web_app", 3 | "version": "1.0.0", 4 | "description": "Node.js on Docker", 5 | "author": "First Last ", 6 | "main": "server.js", 7 | "scripts": { 8 | "start": "node server.js" 9 | }, 10 | "dependencies": { 11 | "express": "^4.16.1" 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /pods.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: nodeapp 5 | labels: 6 | app: nodeapp 7 | spec: 8 | containers: 9 | - name: nodeapp 10 | image: kammana/nodeapp:v1 11 | ports: 12 | - containerPort: 8080 13 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const express = require('express'); 4 | 5 | // Constants 6 | const PORT = 8080; 7 | const HOST = '0.0.0.0'; 8 | 9 | // App 10 | const app = express(); 11 | app.get('/', (req, res) => { 12 | res.send('

Java Home App - version-10!!

\n'); 13 | }); 14 | 15 | app.listen(PORT, HOST); 16 | console.log(`Running on http://${HOST}:${PORT}`); 17 | -------------------------------------------------------------------------------- /services.yml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: nodeapp 5 | spec: 6 | selector: 7 | app: nodeapp 8 | ports: 9 | - protocol: TCP 10 | port: 80 11 | targetPort: 8080 12 | type: LoadBalancer 13 | -------------------------------------------------------------------------------- /skills.txt: -------------------------------------------------------------------------------- 1 | Hari works on aws, devops and java -------------------------------------------------------------------------------- /weekend-oct-jenkins-pipeline-1: -------------------------------------------------------------------------------- 1 | node{ 2 | def dockerTag = getLatestCommitId() 3 | def devIp = '172.31.6.150' 4 | stage("SCM Checkout"){ 5 | git credentialsId: 'git-hub', 6 | url: 'https://github.com/javahometech/node-app', 7 | branch: 'master' 8 | } 9 | stage('Docker - Build & Push'){ 10 | sh script: "docker build . -t kammana/node-app:${dockerTag} " 11 | 12 | withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerHubPwd')]) { 13 | sh script: "docker login -u kammana -p ${dockerHubPwd}" 14 | } 15 | 16 | sh script: "docker push kammana/node-app:${dockerTag}" 17 | } 18 | 19 | stage('Dev Deploy'){ 20 | sh returnStatus: true, script: "ssh ec2-user@${devIp} docker rm -f nodeapp" 21 | sh returnStatus: true, script: 'ssh ec2-user@${devIp} docker rmi $(docker images | grep kammana/node-app | awk \'{print $3}\')' 22 | sh "ssh ec2-user@${devIp} docker run -d -p 8080:8080 --name=nodeapp kammana/node-app:${dockerTag}" 23 | } 24 | } 25 | 26 | def getLatestCommitId(){ 27 | def commitId = sh returnStdout: true, script: 'git rev-parse HEAD' 28 | return commitId 29 | } 30 | --------------------------------------------------------------------------------