Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 37 additions & 0 deletions Deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: my-app
name: nodejs-app
spec:
replicas: 4
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: node-app
image: public.ecr.aws/y0j0v8z3/test-ecr:feature
ports:
- containerPort: 80

---

apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
type: NodePort
ports:
- port: 3000
targetPort: 3000
nodePort: 32600
protocol: TCP
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:16
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 8080
CMD ["npm","start"]
55 changes: 55 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
pipeline {

agent any

stages {

stage('Clone repository') {
steps {
script{
checkout scm
}
}
}
stage('Build') {
steps {
sh 'pwd'
sh 'ls -la'
sh 'npm install'
sh 'npm run'
sh 'ls -la'
}

}

stage('Docker Image Build') {
steps {
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'
}
}
}

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"

}

}
}
}

}
}
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.