Skip to content
134 changes: 107 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
<p align="center">Home Page</p>
</div>

# **Youtube Video for step by step Demonstration!**
[![Video Tutorial](https://img.youtube.com/vi/g8X5AoqCJHc/0.jpg)](https://youtu.be/g8X5AoqCJHc)


## Susbcribe:
[https://www.youtube.com/@cloudchamp?
](https://www.youtube.com/@cloudchamp?sub_confirmation=1)

# Deploy Netflix Clone on Cloud using Jenkins - DevSecOps Project!

### **Phase 1: Initial Setup and Deployment**
Expand All @@ -37,7 +29,7 @@
- Clone your application's code repository onto the EC2 instance:

```bash
git clone https://github.com/N4si/DevSecOps-Project.git
git clone https://github.com/Akshiv20/DevSecOps-Project.git
```


Expand Down Expand Up @@ -106,7 +98,7 @@ docker build --build-arg TMDB_V3_API_KEY=<your-api-key> -t netflix .
sudo apt-get install trivy
```

to scan image using trivy
to scan an image using trivy
```
trivy image <imageid>
```
Expand Down Expand Up @@ -204,14 +196,14 @@ pipeline {
}
stage('Checkout from Git') {
steps {
git branch: 'main', url: 'https://github.com/N4si/DevSecOps-Project.git'
git branch: 'main', url: 'https://github.com/Akshiv20/DevSecOps-Project.git'
}
}
stage("Sonarqube Analysis") {
steps {
withSonarQubeEnv('sonar-server') {
sh '''$SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Netflix \
-Dsonar.projectKey=Netflix'''
-Dsonar.projectKey=Netflix-beta'''
}
}
}
Expand Down Expand Up @@ -294,14 +286,14 @@ pipeline{
}
stage('Checkout from Git'){
steps{
git branch: 'main', url: 'https://github.com/N4si/DevSecOps-Project.git'
git branch: 'main', url: 'https://github.com/Akshiv20/DevSecOps-Project.git'
}
}
stage("Sonarqube Analysis "){
steps{
withSonarQubeEnv('sonar-server') {
sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Netflix \
-Dsonar.projectKey=Netflix '''
-Dsonar.projectKey=Netflix-beta '''
}
}
}
Expand Down Expand Up @@ -333,34 +325,32 @@ pipeline{
script{
withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){
sh "docker build --build-arg TMDB_V3_API_KEY=<yourapikey> -t netflix ."
sh "docker tag netflix nasi101/netflix:latest "
sh "docker push nasi101/netflix:latest "
sh "docker tag netflix akshiv/netflix:latest"
sh "docker push akshiv/netflix:latest"
}
}
}
}
stage("TRIVY"){
steps{
sh "trivy image nasi101/netflix:latest > trivyimage.txt"
sh "trivy image akshiv/netflix:latest > trivyimage.txt"
}
}
stage('Deploy to container'){
steps{
sh 'docker run -d --name netflix -p 8081:80 nasi101/netflix:latest'
sh 'docker run -d -p 8081:80 akshiv/netflix:latest'
}
}
}
}


If you get docker login failed errorr
```
*** If you get docker login failed error

sudo su
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins

sudo usermod -aG docker jenkins

```
sudo systemctl restart jenkins

**Phase 4: Monitoring**

Expand Down Expand Up @@ -397,7 +387,7 @@ sudo systemctl restart jenkins
Create a systemd unit configuration file for Prometheus:

```bash
sudo nano /etc/systemd/system/prometheus.service
sudo vi /etc/systemd/system/prometheus.service
```

Add the following content to the `prometheus.service` file:
Expand Down Expand Up @@ -476,7 +466,7 @@ sudo systemctl restart jenkins
Create a systemd unit configuration file for Node Exporter:

```bash
sudo nano /etc/systemd/system/node_exporter.service
sudo vi /etc/systemd/system/node_exporter.service
```

Add the following content to the `node_exporter.service` file:
Expand Down Expand Up @@ -681,6 +671,96 @@ That's it! You've successfully installed and set up Grafana to work with Prometh

1. **Implement Notification Services:**
- Set up email notifications in Jenkins or other notification mechanisms.

```groovy

pipeline{
agent any
tools{
jdk 'jdk17'
nodejs 'node16'
}
environment {
SCANNER_HOME=tool 'sonar-scanner'
}
stages {
stage('clean workspace'){
steps{
cleanWs()
}
}
stage('Checkout from Git'){
steps{
git branch: 'main', url: 'https://github.com/Akshiv20/DevSecOps-Project.git'
}
}
stage("Sonarqube Analysis "){
steps{
withSonarQubeEnv('sonar-server') {
sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Netflix \
-Dsonar.projectKey=Netflix-beta '''
}
}
}
stage("quality gate"){
steps {
script {
waitForQualityGate abortPipeline: false, credentialsId: 'Sonar-token'
}
}
}
stage('Install Dependencies') {
steps {
sh "npm install"
}
}
stage('OWASP FS SCAN') {
steps {
dependencyCheck additionalArguments: '--scan ./ --disableYarnAudit --disableNodeAudit', odcInstallation: 'DP-Check'
dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
}
}
stage('TRIVY FS SCAN') {
steps {
sh "trivy fs . > trivyfs.txt"
}
}
stage("Docker Build & Push"){
steps{
script{
withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){
sh "docker build --build-arg TMDB_V3_API_KEY=<yourapikey> -t netflix ."
sh "docker tag netflix akshiv/netflix:latest"
sh "docker push akshiv/netflix:latest"
}
}
}
}
stage("TRIVY"){
steps{
sh "trivy image akshiv/netflix:latest > trivyimage.txt"
}
}
stage('Deploy to container'){
steps{
sh 'docker run -d -p 8081:80 akshiv/netflix:latest'
}
}
}
}

post {
always {
emailext attachLog: true,
subject: "'${currentBuild.result}'",
body: "Project: ${env.JOB_NAME}<br/>" +
"Build Number: ${env.BUILD_NUMBER}<br/>" +
"URL: ${env.BUILD_URL}<br/>",
to: 'abc@gmail.com',
attachmentsPattern: 'trivyfs.txt,trivyimage.txt'
}
}
```

# Phase 6: Kubernetes

Expand Down Expand Up @@ -755,4 +835,4 @@ To deploy an application with ArgoCD, you can follow these steps, which I'll out
**Phase 7: Cleanup**

1. **Cleanup AWS EC2 Instances:**
- Terminate AWS EC2 instances that are no longer needed.
- Terminate AWS EC2 instances that are no longer needed.