diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..46eee759 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,24 @@ +pipeline{ + agent { + label 'docker' + } + stages{ + stage("build stage"){ + steps{ + sh "mvn clean install" + } + } + stage("build test"){ + steps{ + sh "mvn test" + } + } + stage("sonarqube"){ + steps{ + withSonarQubeEnv(credentialsId: 'sonar') { + sh "mvn clean verify sonar:sonar" + } + } + } + } +} \ No newline at end of file diff --git a/Jenkinsfile1 b/Jenkinsfile1 new file mode 100644 index 00000000..51dd8e2d --- /dev/null +++ b/Jenkinsfile1 @@ -0,0 +1,51 @@ +pipeline{ + agent any + environment{ + registry = '399747338321.dkr.ecr.ap-south-1.amazonaws.com/onlinebookstoreappdeploy' + imagename = 'onlineapp' + } + stages{ + stage('Build mvn packages'){ + steps{ + sh 'mvn clean install' + + } + } + stage('test packages'){ + steps{ + sh 'mvn test' + } + } + stage('build docker image'){ + steps{ + sh 'docker build -t onlinebookstoreappdeploy:${BUILD_NUMBER} .' + } + } + stage('login docker'){ + steps{ + sh 'aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 399747338321.dkr.ecr.ap-south-1.amazonaws.com' + } + } + stage('tag image'){ + steps{ + sh 'docker tag onlinebookstoreappdeploy:${BUILD_NUMBER} 399747338321.dkr.ecr.ap-south-1.amazonaws.com/onlinebookstoreappdeploy:${BUILD_NUMBER}' + } + } + stage('Push image to registry'){ + steps{ + sh 'docker push 399747338321.dkr.ecr.ap-south-1.amazonaws.com/onlinebookstoreappdeploy:${BUILD_NUMBER}' + } + } + stage('stop pervious container'){ + steps{ + sh 'docker ps -f name=${imagename} -q | xargs --no-run-if-empty docker container stop' + sh 'docker container ls -a -fname=${imagename} -q | xargs -r docker container rm' + } + } + stage('Image,run as container'){ + steps{ + sh 'docker run -itd --name ${imagename} -p 8083:8080 399747338321.dkr.ecr.ap-south-1.amazonaws.com/onlinebookstoreappdeploy:${BUILD_NUMBER}' + } + } + } +} \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 00000000..5c22fc65 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,22 @@ +# Maven +# Build your Java project and run tests with Apache Maven. +# Add steps that analyze code, save build artifacts, deploy, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/java + +trigger: +- master + +pool: + vmImage: ubuntu-latest + +steps: +- task: Maven@3 + inputs: + mavenPomFile: 'pom.xml' + mavenOptions: '-Xmx3072m' + javaHomeOption: 'JDKVersion' + jdkVersionOption: '1.11' + jdkArchitectureOption: 'x64' + publishJUnitResults: true + testResultsFiles: '**/surefire-reports/TEST-*.xml' + goals: 'package' diff --git a/dockerfile b/dockerfile new file mode 100644 index 00000000..5385450b --- /dev/null +++ b/dockerfile @@ -0,0 +1,7 @@ +FROM tomcat + +COPY target/shopping-cart-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/ + +EXPOSE 8083 + +CMD ["catalina.sh", "run"] \ No newline at end of file diff --git a/src/application.properties b/src/application.properties index 339768c9..55ec953e 100644 --- a/src/application.properties +++ b/src/application.properties @@ -1,6 +1,6 @@ # Database Credentials db.driverName = com.mysql.cj.jdbc.Driver -db.connectionString = jdbc:mysql://localhost:3306/shopping-cart +db.connectionString = jdbc:mysql://mysql:3306/shopping-cart db.username = root db.password = root diff --git a/token.txt b/token.txt new file mode 100644 index 00000000..ba59066f --- /dev/null +++ b/token.txt @@ -0,0 +1 @@ +sqp_0de1412e055ed2aa7ea236e9eec04fec9cbeacd4 \ No newline at end of file