forked from jaiswaladi246/3-Tier-DevSecOps-Mega-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile_CICD
More file actions
132 lines (116 loc) · 4.6 KB
/
Copy pathJenkinsfile_CICD
File metadata and controls
132 lines (116 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
pipeline {
agent any
tools {
nodejs 'nodejs23'
}
environment {
SCANNER_HOME = tool 'sonar-scanner'
}
stages {
stage('Git Checkout') {
steps {
git branch: 'main', url: 'https://github.com/jaiswaladi246/3-Tier-DevSecOps-Mega-Project.git'
}
}
stage('Frontend Compilation') {
steps {
dir('client') {
sh 'find . -name "*.js" -exec node --check {} +'
}
}
}
stage('Backend Compilation') {
steps {
dir('api') {
sh 'find . -name "*.js" -exec node --check {} +'
}
}
}
stage('GitLeaks Scan') {
steps {
sh 'gitleaks detect --source ./client --exit-code 1'
sh 'gitleaks detect --source ./api --exit-code 1'
}
}
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('sonar') {
sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=NodeJS-Project \
-Dsonar.projectKey=NodeJS-Project '''
}
}
}
stage('Quality Gate Check') {
steps {
timeout(time: 1, unit: 'HOURS') {
waitForQualityGate abortPipeline: false, credentialsId: 'sonar-token'
}
}
}
stage('Trivy FS Scan') {
steps {
sh 'trivy fs --format table -o fs-report.html .'
}
}
stage('Build-Tag & Push Backend Docker Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred') {
dir('api') {
sh 'docker build -t adijaiswal/backend:latest .'
sh 'trivy image --format table -o backend-image-report.html adijaiswal/backend:latest '
sh 'docker push adijaiswal/backend:latest'
}
}
}
}
}
stage('Build-Tag & Push Frontend Docker Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred') {
dir('client') {
sh 'docker build -t adijaiswal/frontend:latest .'
sh 'trivy image --format table -o frontend-image-report.html adijaiswal/frontend:latest '
sh 'docker push adijaiswal/frontend:latest'
}
}
}
}
}
stage('Manual Approval for Production') {
steps {
timeout(time: 1, unit: 'HOURS') {
input message: 'Approve deployment to PRODUCTION?', ok: 'Deploy'
}
}
}
stage('Deployment To Prod') {
steps {
script {
withKubeConfig(caCertificate: '', clusterName: 'devopsshack-cluster', contextName: '', credentialsId: 'k8-prod-token', namespace: 'prod', restrictKubeConfigAccess: false, serverUrl: 'https://AFC6FCFF5360B30D5E8950396E38A8C4.gr7.ap-south-1.eks.amazonaws.com') {
sh 'kubectl apply -f k8s-prod/sc.yaml'
sleep 20
sh 'kubectl apply -f k8s-prod/mysql.yaml -n prod'
sh 'kubectl apply -f k8s-prod/backend.yaml -n prod'
sh 'kubectl apply -f k8s-prod/frontend.yaml -n prod'
sh 'kubectl apply -f k8s-prod/ci.yaml'
sh 'kubectl apply -f k8s-prod/ingress.yaml -n prod'
sleep 30
}
}
}
}
stage('Verify Deployment To Prod') {
steps {
script {
withKubeConfig(caCertificate: '', clusterName: 'devopsshack-cluster', contextName: '', credentialsId: 'k8-prod-token', namespace: 'prod', restrictKubeConfigAccess: false, serverUrl: 'https://AFC6FCFF5360B30D5E8950396E38A8C4.gr7.ap-south-1.eks.amazonaws.com') {
sh 'kubectl get pods -n prod'
sleep 20
sh 'kubectl get ingress -n prod'
}
}
}
}
}
}