Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3076eb7
Merge pull request #3 from DeekshithSN/devops
DeekshithSN Oct 20, 2021
62bff1b
added ci workflow
DeekshithSN Nov 5, 2021
c56fbcb
Update Dockerfile
DeekshithSN Nov 5, 2021
73e2d3c
Update ci.yml
DeekshithSN Nov 5, 2021
1b10753
Update Dockerfile
DeekshithSN Nov 5, 2021
f3c1472
Create sonar-project.properties
DeekshithSN Nov 5, 2021
59dd6e2
Create kube.yaml
DeekshithSN Nov 5, 2021
c2a0753
Update ci.yml
DeekshithSN Nov 5, 2021
71774b1
Update ci.yml
DeekshithSN Nov 5, 2021
8437a1f
Update kube.yaml
DeekshithSN Nov 5, 2021
a88a003
Update ci.yml
DeekshithSN Nov 5, 2021
e865b4d
Update kube.yaml
DeekshithSN Nov 5, 2021
8471ed3
Merge pull request #7 from DeekshithSN/feature/pr-test
DeekshithSN Nov 5, 2021
70f1cab
Delete ci.yml
DeekshithSN Nov 5, 2021
797b13f
Create ci.yml
DeekshithSN Nov 5, 2021
ed03cba
Delete .github/workflows directory
DeekshithSN Nov 5, 2021
1899f13
Create ci.yml
DeekshithSN Nov 10, 2021
a347937
Update ci.yml
DeekshithSN Nov 10, 2021
8ee5a1c
Update ci.yml
DeekshithSN Nov 10, 2021
c00b73e
Update ci.yml
DeekshithSN Nov 10, 2021
b4918f2
Create cicd.yaml
DeekshithSN Nov 11, 2021
47a7623
Delete cicd.yaml
DeekshithSN Nov 11, 2021
bb61be5
Create cicd.yml
DeekshithSN Nov 11, 2021
d8a7eb8
Update cicd.yml
DeekshithSN Nov 11, 2021
f538b9e
Update cicd.yml
DeekshithSN Nov 11, 2021
f82bb4c
Update cicd.yml
DeekshithSN Nov 11, 2021
5e96dd1
Update cicd.yml
DeekshithSN Nov 11, 2021
f3a0b91
Update cicd.yml
DeekshithSN Nov 11, 2021
80811c3
Update index.html
DeekshithSN Nov 11, 2021
f8c6a85
Merge pull request #9 from DeekshithSN/ui-page-change
DeekshithSN Nov 11, 2021
0abfbd8
Create JenkinsfileFilter
DeekshithSN Jan 9, 2022
b90adda
Update JenkinsfileFilter
DeekshithSN Jan 9, 2022
1116da7
Update JenkinsfileFilter
DeekshithSN Jan 9, 2022
54b2dac
Update JenkinsfileFilter
DeekshithSN Jan 9, 2022
90b584d
Update JenkinsfileFilter
DeekshithSN Jan 9, 2022
fbc2102
Create JenkinsfileSharedLibrary
DeekshithSN Jan 9, 2022
790abff
Update JenkinsfileSharedLibrary
DeekshithSN Jan 9, 2022
24540ab
Update JenkinsfileSharedLibrary
DeekshithSN Jan 9, 2022
182c34b
Update JenkinsfileFilter
DeekshithSN Jan 9, 2022
7e06c4f
Update JenkinsfileSharedLibrary
DeekshithSN Jan 9, 2022
c23240b
Update build.gradle
DeekshithSN Feb 21, 2022
a73124d
Create Jenkinsfile_demo
DeekshithSN Feb 21, 2022
0e48b55
Update Jenkinsfile_demo
DeekshithSN Feb 21, 2022
e138499
Update Jenkinsfile_demo
DeekshithSN Feb 21, 2022
b1ed917
Update index.html
DeekshithSN Feb 21, 2022
603a877
Update Jenkinsfile_demo
DeekshithSN Feb 22, 2022
8c617f8
Update Jenkinsfile_demo
DeekshithSN Feb 22, 2022
f584c8f
Update Jenkinsfile_demo
DeekshithSN Feb 22, 2022
07ffff3
Update Jenkinsfile_demo
DeekshithSN Feb 22, 2022
fc5eea6
Update Jenkinsfile_demo
DeekshithSN Feb 23, 2022
1c901c6
Update Jenkinsfile_demo
DeekshithSN Feb 23, 2022
393651f
Update Jenkinsfile_demo
DeekshithSN Feb 23, 2022
aeb8d97
Update Jenkinsfile_demo
DeekshithSN Feb 23, 2022
f0527aa
Create healthcheck.sh
DeekshithSN Feb 23, 2022
ba8bdbf
Update Jenkinsfile_demo
DeekshithSN Feb 23, 2022
51960f2
Update Jenkinsfile_demo
DeekshithSN May 20, 2022
5f98c0a
Update Jenkinsfile_demo
DeekshithSN May 20, 2022
fccc7e8
Update Jenkinsfile_demo
DeekshithSN May 20, 2022
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
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Java CI with Gradle

on:
pull_request:
branches: [ main ]

env:
DATREE_TOKEN: ${{ secrets.DATREE_TOKEN }}

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
- name: SonarQube Quality Gate check
uses: sonarsource/sonarqube-quality-gate-action@master
# Force to fail step after specific time
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Install Datree
run: curl https://get.datree.io | /bin/bash

- name: Run Datree's policy check
run: datree test kube.yaml


84 changes: 84 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Java CICD with Gradle

on:
push:
branches: [ main ]

env:
DATREE_TOKEN: ${{ secrets.DATREE_TOKEN }}
KUBECONFIG: /home/alerts_deekshith/kubeconfig/config_now

jobs:
build:

runs-on: self-hosted

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
- name: SonarQube Quality Gate check
uses: sonarsource/sonarqube-quality-gate-action@master
# Force to fail step after specific time
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Install Datree
run: curl https://get.datree.io | /bin/bash

- name: Run Datree's policy check
run: datree test kube.yaml

- name: Login to Nexus registy
uses: docker/login-action@v1
with:
registry: 34.125.31.157:8083
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: docker build & docker push
run: |
docker build -t 34.125.31.157:8083/javaapp:${{ github.run_number }} .
docker push 34.125.31.157:8083/javaapp:${{ github.run_number }}
docker rmi 34.125.31.157:8083/javaapp:${{ github.run_number }}

- name: deploying manifest file on k8s cluster
run: |
sed -i "s;imagename;34.125.31.157:8083/javaapp:${{ github.run_number }};g" kube.yaml
kubectl apply -f kube.yaml
sleep 30
kubectl get po

- name: verification
run: |
sleep 60
kubectl run curl --image=curlimages/curl -i --rm --restart=Never -- curl myapp:8080

- name: Send email
if: always()
uses: dawidd6/action-send-mail@v2
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.EMAIL_USERNAME }}
password: ${{ secrets.EMAIL_PASSWORD }}
subject: ${{ github.job }} job of ${{ github.repository }} has ${{ job.status }}
# email body as text
body: ${{ github.job }} job in worflow ${{ github.workflow }} of ${{ github.repository }} has ${{ job.status }}
# comma-separated string, send email to
to: deekshith.snsep@gmail.com
# from email name
from: deekshith.snsep@gmail.com
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# this is multi stage
FROM openjdk:11 as base
WORKDIR /app
COPY . .
Expand All @@ -7,4 +8,4 @@ RUN ./gradlew build
FROM tomcat:9
WORKDIR webapps
COPY --from=base /app/build/libs/sampleWeb-0.0.1-SNAPSHOT.war .
RUN rm -rf ROOT && mv sampleWeb-0.0.1-SNAPSHOT.war ROOT.war
RUN rm -rf ROOT && mv sampleWeb-0.0.1-SNAPSHOT.war ROOT.war
23 changes: 23 additions & 0 deletions JenkinsfileFilter
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pipeline {
agent {
docker {
image 'openjdk:11'
}
}

stages {
stage('Building') {
steps {
sh 'chmod +x gradlew'
sh "./gradlew build | tee output.log"
}
}
stage('Monitoring the logs') {
steps {
script {
sh '! grep "Task" output.log'
}
}
}
}
}
26 changes: 26 additions & 0 deletions JenkinsfileSharedLibrary
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env groovy

@Library('shared-library@master') _ //master or whatever branch


pipeline {
agent {
docker {
image 'openjdk:11'
}
}

stages {
stage('Building') {
steps {
sh 'chmod +x gradlew'
sh "./gradlew build "
}
}
stage ('Check logs') {
steps {
filterLogs ('Task', 15)
}
}
}
}
96 changes: 96 additions & 0 deletions Jenkinsfile_demo
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
pipeline{
agent any
environment{
VERSION = "${env.BUILD_ID}"
}
stages{
stage("sonar qube analysis"){
agent{
docker {
image 'openjdk:11'
}
}
steps{
script{
withSonarQubeEnv(credentialsId: 'sonar-token') {
sh '''
chmod +x gradlew
./gradlew sonarqube
'''
}

timeout(5) {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}

stage("building docker image and pushing it to nexus"){
steps{
script{

withCredentials([string(credentialsId: 'nexus_pass', variable: 'docker_pass')]) {
sh '''

docker build -t 35.188.44.251:8083/springapp:${VERSION} .
docker login -u admin -p $docker_pass 35.188.44.251:8083
docker push 35.188.44.251:8083/springapp:${VERSION}
docker rmi 35.188.44.251:8083/springapp:${VERSION}
docker image prune -f
'''
}
}
}
}


stage('manual approval'){
steps{
script{
timeout(10) {
mail bcc: '', body: "<br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> Go to build url and approve the deployment request <br> URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "${currentBuild.result} CI: Project name -> ${env.JOB_NAME}", to: "issamraz1993@gmail.com";
input(id: "Deploy Gate", message: "Deploy ${params.project_name}?", ok: 'Deploy')
}
}
}
}



stage('Deploying application on k8s cluster') {
steps {
script{
withCredentials([kubeconfigFile(credentialsId: 'kubernetes-config', variable: 'KUBECONFIG')]) {
dir('kubernetes/') {

sh 'helm upgrade --install --set image.repository="35.188.44.251:8083/springapp" --set image.tag="${VERSION}" myjavaapp myapp/ '
}
}
}
}
}


stage('verifying app deployment'){
steps{
script{
withCredentials([kubeconfigFile(credentialsId: 'kubernetes-config', variable: 'KUBECONFIG')]) {
sh '''

chmod +x healthcheck.sh
./healthcheck.sh
'''

}
}
}
}


}

}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test {

sonarqube {
properties {
property 'sonar.host.url', 'http://34.125.75.197:9000'
property 'sonar.host.url', 'http://34.125.201.58:9000'
property 'sonar.login', '******'
}
}
10 changes: 10 additions & 0 deletions healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
echo "executing health check it might take a while"
sleep 120
kubectl run curl --image=curlimages/curl -i --rm --restart=Never -- curl myjavaapp-myapp:8080

if [ $? -eq 0 ]
then
echo "The Deployment is success...Application Health is Good"
else
helm rollback myjavaapp
fi
81 changes: 81 additions & 0 deletions kube.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
apiVersion: v1
kind: Service
metadata:
name: myapp
labels:
helm.sh/chart: myapp-0.2.0
app.kubernetes.io/name: myapp
app.kubernetes.io/instance: myapp
app.kubernetes.io/version: "1.16.0"
app.kubernetes.io/managed-by: Helm
spec:
type: NodePort
ports:
- port: 8080
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: myapp
app.kubernetes.io/instance: myapp
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
labels:
helm.sh/chart: myapp-0.2.0
app.kubernetes.io/name: myapp
app.kubernetes.io/instance: myapp
app.kubernetes.io/version: "1.16.0"
app.kubernetes.io/managed-by: Helm
spec:
replicas: 2
selector:
matchLabels:
app.kubernetes.io/name: myapp
app.kubernetes.io/instance: myapp
template:
metadata:
labels:
app.kubernetes.io/name: myapp
app.kubernetes.io/instance: myapp
spec:
imagePullSecrets:
- name: registry-secret
containers:
- name: myapp
image: imagename
command: ["/bin/sh"]
args: ["-c","sh /usr/local/tomcat/bin/startup.sh;while true; do echo hello; sleep 10;done"]
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 8080
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: 60
periodSeconds: 5
successThreshold: 1
failureThreshold: 3
timeoutSeconds: 10
readinessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: 60
periodSeconds: 5
successThreshold: 1
failureThreshold: 3
timeoutSeconds: 10
resources:
requests:
memory: 0.25Gi
cpu: 0.5
limits:
memory: 0.25Gi
cpu: 0.5
3 changes: 3 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sonar.projectKey=CICD_Java_gradle_application
sonar.java.binaries=.
sonar.exclusions=build/**
Loading