diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..94dda78f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +# Ignore specific files or directories when building the Docker image + +# Exclude the following files and directories +.git +.idea +.vscode +node_modules + +# Exclude all files and directories inside the target directory +# ! allows including specific files or directories even if they are excluded by a pattern +target/* +!target/WebApp.war diff --git a/Dockerfile b/Dockerfile index ceb6b0ab..ca6d49fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,4 +2,5 @@ FROM tomcat WORKDIR webapps COPY target/WebApp.war . RUN rm -rf ROOT && mv WebApp.war ROOT.war -ENTRYPOINT ["sh", "/usr/local/tomcat/bin/startup.sh"] +RUN /usr/local/tomcat/bin/startup.sh +ENTRYPOINT [ "sleep", "3600"] diff --git a/Jenkinsfile b/Jenkinsfile index 45561c81..8e137800 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,83 +1,90 @@ -def getDockerTag(){ +def getDockerTag() { def tag = sh script: 'git rev-parse --short HEAD', returnStdout: true return tag - } +} -pipeline{ +pipeline { agent any - environment{ + environment { Docker_tag = getDockerTag() docker_pws = credentials('docker-hub-password') } - stages{ - stage("Sonar scan"){ + stages { + stage("Sonar scan") { agent { docker { image 'maven' args '-v /root/.m2:/root/.m2' } } - steps{ - script{ - sh "echo executing sonar scan" - // sh "sleep 90" + steps { + script { + sh "echo executing sonar scan" + // sh "sleep 90" } } } - stage('build the application'){ + stage('build the application') { agent { docker { image 'maven' args '-v /root/.m2:/root/.m2' } } - steps{ - script{ - sh "mvn clean install" + steps { + script { + sh "mvn clean package" } } } + stage('Debug') { + steps { + sh 'ls -al ' + sh 'cd src/ ' + sh 'ls -al ' + } + } - stage('docker build'){ - steps{ - script{ + stage('docker build') { + steps { + script { sh """ - docker build . -t deekshithsn/java-app-hbc:$Docker_tag + pwd + cp -r ../workspace@2/target . + docker build . -t deekshithsn/java-app-hbc:\$Docker_tag """ } } } - - stage('docker login & push'){ - steps{ - script{ + stage('docker login & push') { + steps { + script { sh """ - docker login -u deekshithsn -p $docker_pws - docker push deekshithsn/java-app-hbc:$Docker_tag + docker login -u deekshithsn -p \$docker_pws + docker push deekshithsn/java-app-hbc:\$Docker_tag """ addBadge(icon: 'save.gif', text: 'docker repo', link: 'https://hub.docker.com/repository/docker/deekshithsn/java-app-hbc') - currentBuild.description = "deekshithsn/java-app-hbc:$Docker_tag" + currentBuild.description = "deekshithsn/java-app-hbc:\$Docker_tag" } } } - stage('deploy the application'){ - steps{ - script{ + stage('deploy the application') { + steps { + script { sh """ - docker rm $( docker stop $( docker ps -aq)) - docker run -d -p 9000:8080 deekshithsn/java-app-hbc:$Docker_tag + docker rm \$( docker stop \$( docker ps -aq)) + docker run -d -p 9000:8080 deekshithsn/java-app-hbc:\$Docker_tag """ } } } - } post { - always{ + always { cleanWs() } } diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index f1c1845b..0fe81bc7 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -31,7 +31,7 @@ - Devops-training + DevOps Simple APP- HBC Demo