From 0869d03d30c90fdb78750105f12256891a76170e Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 20:50:06 +0530 Subject: [PATCH 01/23] Create Dockerfile --- Dockerfile | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fa4f92e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM node:16 +WORKDIR /usr/src/app +COPY package*.json./ +RUN npm install +COPY . . +EXPOSE 8080 +CMD ["node","index.js"] From a02e4aeaf9065ac314c0427e162e313d9a78a1c3 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 21:07:53 +0530 Subject: [PATCH 02/23] Create Jenkinsfile --- Jenkinsfile | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..e024df6 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,25 @@ +pipeline { + + agent any + + stages { + + stage('Clone repository') { + steps { + script{ + checkout scm + } + } + } + stage('Build') { + steps { + sh 'pwd' + sh 'ls -la' + sh 'npm install' + sh 'node test' + } + + } + + } +} From 4570a54b94f2b461eb28c032f4898360ce7e2e52 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 21:16:41 +0530 Subject: [PATCH 03/23] Update Dockerfile --- Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index fa4f92e..956a2d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ FROM node:16 -WORKDIR /usr/src/app -COPY package*.json./ -RUN npm install +WORKDIR /app COPY . . +RUN npm install EXPOSE 8080 -CMD ["node","index.js"] +CMD ["npm","start"] From c67a16803c1d59438fb4469bf49460138500bb8b Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 21:20:17 +0530 Subject: [PATCH 04/23] Update Jenkinsfile --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index e024df6..3363110 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,7 +16,6 @@ pipeline { sh 'pwd' sh 'ls -la' sh 'npm install' - sh 'node test' } } From 0c00e1df80e7a99a6bfd6c776921cdf9d5377cc1 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 21:21:22 +0530 Subject: [PATCH 05/23] Update Jenkinsfile --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 3363110..522c15d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,6 +16,8 @@ pipeline { sh 'pwd' sh 'ls -la' sh 'npm install' + sh 'pwd' + sh 'ls -la' } } From 8d93fa69108d74d0d3b17d6924abddbf4fcb68fd Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 21:28:38 +0530 Subject: [PATCH 06/23] Update Jenkinsfile --- Jenkinsfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 522c15d..d27a3e7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,11 +16,15 @@ pipeline { sh 'pwd' sh 'ls -la' sh 'npm install' - sh 'pwd' - sh 'ls -la' } } + + stage('Docker Image Build') { + steps { + sh 'docker build -t test-ecr .' + } + } } } From a9a159bd794b16d782d4c922a6642b8161aad8cc Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 21:40:10 +0530 Subject: [PATCH 07/23] Update Jenkinsfile --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index d27a3e7..8b76a35 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,6 +16,8 @@ pipeline { sh 'pwd' sh 'ls -la' sh 'npm install' + sh 'npm build' + sh 'ls -la' } } From a79270e53680d4d260f3d77b3e072d49aeb9b718 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 21:45:03 +0530 Subject: [PATCH 08/23] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8b76a35..f87fd21 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { sh 'pwd' sh 'ls -la' sh 'npm install' - sh 'npm build' + sh 'npm run' sh 'ls -la' } From 5d166431529e87cc645d9b4d8dbd2d40f42b1108 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 21:58:40 +0530 Subject: [PATCH 09/23] Update Jenkinsfile --- Jenkinsfile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f87fd21..626a52d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { sh 'pwd' sh 'ls -la' sh 'npm install' - sh 'npm run' + sh 'npm build' sh 'ls -la' } @@ -27,6 +27,16 @@ pipeline { sh 'docker build -t test-ecr .' } } + + stage('Push Docker Image to ECR') { + steps { + withAWS(credentials: 'aws-credentials', region: 'ap-south-1') { + sh 'aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/y0j0v8z3' + sh 'docker tag test-ecr:latest public.ecr.aws/y0j0v8z3/test-ecr:feature' + sh 'docker push public.ecr.aws/y0j0v8z3/test-ecr:feature' + } + } + } } } From 9581db126bbdadc783e0f5b628f956c42f8e94ba Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 21:59:49 +0530 Subject: [PATCH 10/23] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 626a52d..851c914 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { sh 'pwd' sh 'ls -la' sh 'npm install' - sh 'npm build' + sh 'npm run' sh 'ls -la' } From 722615967c2e6e889b0bc637c8c0dcdab573b135 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 22:23:43 +0530 Subject: [PATCH 11/23] Create Deployment.yaml --- Deployment.yaml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Deployment.yaml diff --git a/Deployment.yaml b/Deployment.yaml new file mode 100644 index 0000000..02f39b4 --- /dev/null +++ b/Deployment.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: node-app +spec: + selector: + matchLabels: + app: test-n + replicas: 2 + template: + metadata: + labels: + app: test-n + spec: + containers: + - name: my-imag + image: public.ecr.aws/y0j0v8z3/test-ecr:feature + ports: + - containerPort: 80 +--- + +apiVersion: v1 +kind: Service +metadata: + name: Service +spec: + selector: + app: test-n + type: NodePort + ports: + - port: 80 + targetPort: 8080 + nodePort: 30036 From 24650adde7f78fe00ba520978952f9633c9bb7cd Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 22:24:48 +0530 Subject: [PATCH 12/23] Update Jenkinsfile --- Jenkinsfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 851c914..83fb537 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -37,6 +37,19 @@ pipeline { } } } + + stage('Integrate Jenkins with EKS Cluster and Deploy App') { + steps { + withKubeConfig(caCertificate: '', clusterName: '', contextName: '', credentialsId: 'K8S', namespace: '', restrictKubeConfigAccess: false, serverUrl: '') { + script { + sh 'ls -la' + sh "kubectl apply -f Deployment.yaml" + + } + + } + } + } } } From 48f6a7b19a4dedf20b1eb348e525617f15fd6033 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 22:28:49 +0530 Subject: [PATCH 13/23] Update Deployment.yaml --- Deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Deployment.yaml b/Deployment.yaml index 02f39b4..acdb57a 100644 --- a/Deployment.yaml +++ b/Deployment.yaml @@ -25,7 +25,7 @@ metadata: name: Service spec: selector: - app: test-n + app: test-n type: NodePort ports: - port: 80 From 3347778eb8e9b22321fecb9ecb7f309e7168766e Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 22:29:58 +0530 Subject: [PATCH 14/23] Update Deployment.yaml --- Deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Deployment.yaml b/Deployment.yaml index acdb57a..832a595 100644 --- a/Deployment.yaml +++ b/Deployment.yaml @@ -25,7 +25,7 @@ metadata: name: Service spec: selector: - app: test-n + app: test-n type: NodePort ports: - port: 80 From 9ae2f2f4c4a10b6146ae035d9330204e1c6b2f20 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 22:34:58 +0530 Subject: [PATCH 15/23] Update Deployment.yaml --- Deployment.yaml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Deployment.yaml b/Deployment.yaml index 832a595..1532ac2 100644 --- a/Deployment.yaml +++ b/Deployment.yaml @@ -1,22 +1,25 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: node-app + labels: + app: my-app + name: nodejs-app spec: + replicas: 4 selector: matchLabels: - app: test-n - replicas: 2 + app: my-app template: metadata: labels: - app: test-n + app: my-app spec: containers: - - name: my-imag + - name: node-app image: public.ecr.aws/y0j0v8z3/test-ecr:feature ports: - containerPort: 80 + --- apiVersion: v1 @@ -25,7 +28,7 @@ metadata: name: Service spec: selector: - app: test-n + app: my-app type: NodePort ports: - port: 80 From 3bff4f843746801c8f72428f40ad889858405736 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 22:38:05 +0530 Subject: [PATCH 16/23] Update Deployment.yaml --- Deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Deployment.yaml b/Deployment.yaml index 1532ac2..28aa2d9 100644 --- a/Deployment.yaml +++ b/Deployment.yaml @@ -25,7 +25,7 @@ spec: apiVersion: v1 kind: Service metadata: - name: Service + name: my-service spec: selector: app: my-app From 968beaa93b918bee379306fbe7078c78bd12c426 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 22:53:19 +0530 Subject: [PATCH 17/23] Update Deployment.yaml --- Deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Deployment.yaml b/Deployment.yaml index 28aa2d9..cab973b 100644 --- a/Deployment.yaml +++ b/Deployment.yaml @@ -32,5 +32,5 @@ spec: type: NodePort ports: - port: 80 - targetPort: 8080 + targetPort: 80 nodePort: 30036 From a980bc538e44914650f8a6677e1b476ca2c99a93 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 23:06:48 +0530 Subject: [PATCH 18/23] Update Deployment.yaml --- Deployment.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Deployment.yaml b/Deployment.yaml index cab973b..276399b 100644 --- a/Deployment.yaml +++ b/Deployment.yaml @@ -33,4 +33,5 @@ spec: ports: - port: 80 targetPort: 80 - nodePort: 30036 + nodePort: 32140 + protocol: TCP From f9304a1ab8e79e0724b2fe5ca75b468ec462af1c Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 23:40:51 +0530 Subject: [PATCH 19/23] Update Deployment.yaml --- Deployment.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Deployment.yaml b/Deployment.yaml index 276399b..5315072 100644 --- a/Deployment.yaml +++ b/Deployment.yaml @@ -31,7 +31,7 @@ spec: app: my-app type: NodePort ports: - - port: 80 - targetPort: 80 + - port: 3000 + targetPort: 3000 nodePort: 32140 protocol: TCP From 78d6291ae15c90145b3f8883be11a8f273eeb656 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 23:42:07 +0530 Subject: [PATCH 20/23] Update Deployment.yaml --- Deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Deployment.yaml b/Deployment.yaml index 5315072..8d8bf09 100644 --- a/Deployment.yaml +++ b/Deployment.yaml @@ -33,5 +33,5 @@ spec: ports: - port: 3000 targetPort: 3000 - nodePort: 32140 + nodePort: 32600 protocol: TCP From 63784959eccb82f8066ee747e60dfdc569f7855c Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 23:58:07 +0530 Subject: [PATCH 21/23] Create step-by-step-CICD --- step-by-step-CICD | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 step-by-step-CICD diff --git a/step-by-step-CICD b/step-by-step-CICD new file mode 100644 index 0000000..03d9484 --- /dev/null +++ b/step-by-step-CICD @@ -0,0 +1,17 @@ +Launch a virtual machine of any linux flavour and install jenkins, docker, AWS CLI and nodejs + +Create a registry in AWS ECR and create IAM user with required permission to carry out ECR activities. + +Create EKS cluster using AWS CLI along with creation of IAM role with cloudformation, IAM & EC2 permissions. + +Create AWS access key and secret keys from IAM user + +Access jenkins through port 8080 on browser and download AWS:Pipeline, ECR, docker pipeline, EKS, cloudbees plugins + +Store AWS credentials in jenkins which are required to login to ECR + +Create Dockerfile (As shown in repo) and Jenkinsfile with necessary steps and stages + +Create K8S manifest file for Deployment and services and choose type as Nodeport (With appropriate port of an application) + +Now, access this application with Node IP:NodePort on browser. From 8c96f80451b6bee252811b2721955ad2df92a908 Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 23:59:23 +0530 Subject: [PATCH 22/23] Update README.md --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 22e0844..1c31826 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,24 @@ # SampleExpressApp Used for Devops interview + +STEP BY STEP CICD + + +Launch a virtual machine of any linux flavour and install jenkins, docker, AWS CLI and nodejs + +Create a registry in AWS ECR and create IAM user with required permission to carry out ECR activities. + +Create EKS cluster using AWS CLI along with creation of IAM role with cloudformation, IAM & EC2 permissions. + +Create AWS access key and secret keys from IAM user + +Access jenkins through port 8080 on browser and download AWS:Pipeline, ECR, docker pipeline, EKS, cloudbees plugins + +Store AWS credentials in jenkins which are required to login to ECR + +Create Dockerfile (As shown in repo) and Jenkinsfile with necessary steps and stages + +Create K8S manifest file for Deployment and services and choose type as Nodeport (With appropriate port of an application) + +Now, access this application with Node IP:NodePort on browser. From e81cf073543b8699b69aa0fa20674d02f4e8d82a Mon Sep 17 00:00:00 2001 From: Arun_Das <114015825+aru1235@users.noreply.github.com> Date: Thu, 16 Mar 2023 23:59:51 +0530 Subject: [PATCH 23/23] Delete step-by-step-CICD --- step-by-step-CICD | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 step-by-step-CICD diff --git a/step-by-step-CICD b/step-by-step-CICD deleted file mode 100644 index 03d9484..0000000 --- a/step-by-step-CICD +++ /dev/null @@ -1,17 +0,0 @@ -Launch a virtual machine of any linux flavour and install jenkins, docker, AWS CLI and nodejs - -Create a registry in AWS ECR and create IAM user with required permission to carry out ECR activities. - -Create EKS cluster using AWS CLI along with creation of IAM role with cloudformation, IAM & EC2 permissions. - -Create AWS access key and secret keys from IAM user - -Access jenkins through port 8080 on browser and download AWS:Pipeline, ECR, docker pipeline, EKS, cloudbees plugins - -Store AWS credentials in jenkins which are required to login to ECR - -Create Dockerfile (As shown in repo) and Jenkinsfile with necessary steps and stages - -Create K8S manifest file for Deployment and services and choose type as Nodeport (With appropriate port of an application) - -Now, access this application with Node IP:NodePort on browser.