Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating Jenkins and Docker File #161

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
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
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

FROM openjdk:11 AS builder

WORKDIR /onlinebookstore

COPY . /onlinebookstore/

RUN apt-get update && apt-get install -y maven

RUN mvn package # Build the JAR file using Maven (adjust for your build tool)

# Stage 2: Tomcat image with WAR file (final stage)
FROM tomcat:latest

# Copy the WAR file from the builder stage
COPY --from=builder /onlinebookstore/target/onlinebookstore.war /usr/local/tomcat/webapps/onlinebookstore.war

EXPOSE 8080

ENTRYPOINT ["catalina.sh", "run"]

98 changes: 89 additions & 9 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,91 @@
pipeline {
agent any
stages {
stage("git_checkout") {
steps {
echo "cloning repository"
echo "repo cloned successfully"
}
}
pipeline {
agent any

tools{
maven "maven"
jdk "jdk"
}
environment{
SCANNER_HOME= tool 'sonar-scanner'
}
stages {
stage('Git Checkout') {
steps {
git changelog: false, poll: false, url: 'https://github.com/17J/onlinebookstore.git'
}
}
stage('Trivy Repo Scan') {
steps {
sh 'trivy repo --format table -o repo-report.html https://github.com/17J/onlinebookstore.git'
}
}
stage('Compile') {
steps {
sh 'mvn compile'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
}
stage('OWASP Dependency') {
steps {
dependencyCheck additionalArguments: '--scan ./ ', odcInstallation: 'DP'
dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
}
}
stage('Sonarqube Scan') {
steps {
withSonarQubeEnv('sonar') {

sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=onlinebookstore \
-Dsonar.java.binaries=.\
-Dsonar.projectKey=onlinebookstore '''

}
}
}
stage('Quality Gate') {
steps {
script{
waitForQualityGate abortPipeline: false, credentialsId: 'sonar'
}
}
}
stage('Build') {
steps {
sh 'mvn package'
}
}
stage('Dokcer Push and Tag') {
steps {
script{
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh 'docker build -t onlinebooks .'
sh 'docker tag onlinebooks 17rj/onlinebookmart'
}
}
}
}
stage('Image Scan') {
steps {
sh 'trivy image --format table -o image-report.html 17rj/onlinebookmart'
}
}
stage('Push Image') {
steps {
script{
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh 'docker push 17rj/onlinebookmart'
}
}
}
}
stage('Deploy Tomcat') {
steps {
sh "cp /var/lib/jenkins/workspace/tomcat/target/onlinebookstore.war /opt/apache-tomcat-9.0.65/webapps/ "
}
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ db.host=jdbc:mysql://localhost
db.port=3306
db.name=onlinebookstore
db.username=root
db.password=root
db.password=secret_password