From ff13d5933eeab0e0429f52014e0c6f38fd322767 Mon Sep 17 00:00:00 2001 From: dario-rodriguez Date: Wed, 17 Jul 2019 11:38:21 +0200 Subject: [PATCH] Bugfix/fix version number (#263) * Updated the version number in java project and also in the deployment Jenkinsfiles * Changed distribution management * Updated Jenkinsfile --- .travis.yml | 2 +- java/mtsj/api/pom.xml | 2 +- java/mtsj/batch/pom.xml | 2 +- java/mtsj/core/pom.xml | 6 +- java/mtsj/pom.xml | 10 +- java/mtsj/server/pom.xml | 2 +- jenkins/angular/cicd/Jenkinsfile | 282 ++++++++++++------------- jenkins/angular/deployment/Jenkinsfile | 15 +- jenkins/deployment/Jenkinsfile | 140 ++++++------ jenkins/java/deployment/Jenkinsfile | 167 ++++++++------- reverse-proxy/angular/Dockerfile | 7 +- reverse-proxy/java/Dockerfile | 2 +- 12 files changed, 323 insertions(+), 314 deletions(-) diff --git a/.travis.yml b/.travis.yml index fca7f8fa0..b6c2adb4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,7 @@ jobs: cd ../${REPO_CONSOLIDATE} if [ ! -d ${REPO_DEST} ]; then git submodule add https://${GH_REPO_DEST}; else return 0; fi; git submodule init - git submodule update + git submodule update --recursive --remote cd ${REPO_DEST} git checkout master git pull diff --git a/java/mtsj/api/pom.xml b/java/mtsj/api/pom.xml index c247e693e..46b95399f 100644 --- a/java/mtsj/api/pom.xml +++ b/java/mtsj/api/pom.xml @@ -6,7 +6,7 @@ com.devonfw.java.mtsj mtsj - 3.2.0-SNAPSHOT + 3.1.0 mtsj-api jar diff --git a/java/mtsj/batch/pom.xml b/java/mtsj/batch/pom.xml index 05c31d627..045bb50e7 100644 --- a/java/mtsj/batch/pom.xml +++ b/java/mtsj/batch/pom.xml @@ -5,7 +5,7 @@ com.devonfw.java.mtsj mtsj - 3.2.0-SNAPSHOT + 3.1.0 mtsj-batch jar diff --git a/java/mtsj/core/pom.xml b/java/mtsj/core/pom.xml index d75555cfe..7fc7f4893 100644 --- a/java/mtsj/core/pom.xml +++ b/java/mtsj/core/pom.xml @@ -1,11 +1,11 @@  - 4.0.0 com.devonfw.java.mtsj mtsj - 3.2.0-SNAPSHOT + 3.1.0 mtsj-core jar @@ -150,7 +150,7 @@ ${mts.database.artifactId} ${mts.database.version} - + com.sap.cloud.db.jdbc ngdbc 2.3.48 diff --git a/java/mtsj/pom.xml b/java/mtsj/pom.xml index af9ae7d1c..bfdeb4962 100644 --- a/java/mtsj/pom.xml +++ b/java/mtsj/pom.xml @@ -1,11 +1,11 @@ - 4.0.0 mtsj com.devonfw.java.mtsj - 3.2.0-SNAPSHOT + 3.1.0 pom ${project.artifactId} Application based on the Devonfw framework for Java (devon4j). @@ -153,8 +153,8 @@ 2.22.0 ${devon.test.excluded.groups} - 0 - true + 0 + true @@ -223,7 +223,7 @@ pl-nexus PL Releases - http://nexus3-core:8081/nexus/content/repositories/maven-releases/ + http://nexus3-core:8081/nexus3/repository/maven-releases/ pl-nexus diff --git a/java/mtsj/server/pom.xml b/java/mtsj/server/pom.xml index 52deaedd5..635f9be93 100644 --- a/java/mtsj/server/pom.xml +++ b/java/mtsj/server/pom.xml @@ -5,7 +5,7 @@ com.devonfw.java.mtsj mtsj - 3.2.0-SNAPSHOT + 3.1.0 mtsj-server war diff --git a/jenkins/angular/cicd/Jenkinsfile b/jenkins/angular/cicd/Jenkinsfile index 0f174073d..217b84975 100644 --- a/jenkins/angular/cicd/Jenkinsfile +++ b/jenkins/angular/cicd/Jenkinsfile @@ -1,141 +1,141 @@ -pipeline{ - agent any - - options { - buildDiscarder(logRotator(artifactDaysToKeepStr: '1', artifactNumToKeepStr: '1', daysToKeepStr: '5', numToKeepStr: '50')) - // Disable concurrent builds. It will wait until the pipeline finish before start a new one - disableConcurrentBuilds() - } - - tools { - nodejs "NodeJS 10.14.0" - } - - environment { - // Script for build the application. Defined at package.json - buildScript = 'build --configuration=docker' - // Script for lint the application. Defined at package.json - lintScript = 'lint' - // Script for test the application. Defined at package.json - testScript = 'test:ci' - // Angular directory - angularDir = 'angular' - // SRC folder. It will be angularDir/srcDir - srcDir = 'src' - // Name of the custom tool for chrome stable - chrome = 'Chrome-stable' - - // sonarQube - // Name of the sonarQube tool - sonarTool = 'SonarQube' - // Name of the sonarQube environment - sonarEnv = "SonarQube" - - // Nexus - // Artifact groupId - groupId = 'com.devonfw.mythaistar' - // Nexus repository ID - repositoryId = 'pl-nexus' - // Nexus internal URL - repositoryUrl = 'http://nexus3-core:8081/nexus3/repository/maven-snapshots' - // Maven global settings configuration ID - globalSettingsId = 'MavenSettings' - // Maven tool id - mavenInstallation = 'Maven3' - } - - stages { - stage ('Loading Custom Tools') { - steps { - tool chrome - } - } - - stage ('Fresh Dependency Installation') { - steps { - dir(angularDir){ - sh "yarn" - } - } - } - - stage ('Code Linting') { - steps { - dir(angularDir) { - sh """yarn ${lintScript}""" - } - } - } - - stage ('Execute Angular tests') { - steps { - dir(angularDir) { - sh """yarn ${testScript}""" - } - } - } - - stage ('SonarQube code analysis') { - steps { - script { - dir(angularDir) { - def scannerHome = tool sonarTool - def props = readJSON file: 'package.json' - withSonarQubeEnv(sonarEnv) { - sh """ - ${scannerHome}/bin/sonar-scanner \ - -Dsonar.projectKey=${props.name} \ - -Dsonar.projectName=${props.name} \ - -Dsonar.projectVersion=${props.version} \ - -Dsonar.sources=${srcDir} - """ - } - timeout(time: 1, unit: 'HOURS') { - def qg = waitForQualityGate() - if (qg.status != 'OK') { - error "Pipeline aborted due to quality gate failure: ${qg.status}" - } - } - } - } - } - } - - stage ('Build Application') { - steps { - dir(angularDir) { - sh """yarn ${buildScript}""" - } - } - } - - stage ('Deliver application into Nexus') { - steps { - script { - dir(angularDir) { - def props = readJSON file: 'package.json' - zip dir: 'dist/', zipFile: """${props.name}.zip""" - withMaven(globalMavenSettingsConfig: globalSettingsId, maven: mavenInstallation) { - sh """ - mvn deploy:deploy-file \ - -DgroupId=${groupId} \ - -DartifactId=${props.name} \ - -Dversion=${props.version}-SNAPSHOT \ - -Dpackaging=zip \ - -Dfile=${props.name}.zip \ - -DrepositoryId=${repositoryId} \ - -Durl=${repositoryUrl} - """ - } - } - } - } - } - } - - post { - always { - cleanWs() - } - } -} +pipeline{ + agent any + + options { + buildDiscarder(logRotator(artifactDaysToKeepStr: '1', artifactNumToKeepStr: '1', daysToKeepStr: '5', numToKeepStr: '50')) + // Disable concurrent builds. It will wait until the pipeline finish before start a new one + disableConcurrentBuilds() + } + + tools { + nodejs "NodeJS 10.14.0" + } + + environment { + // Script for build the application. Defined at package.json + buildScript = 'build --configuration=docker' + // Script for lint the application. Defined at package.json + lintScript = 'lint' + // Script for test the application. Defined at package.json + testScript = 'test:ci' + // Angular directory + angularDir = 'angular' + // SRC folder. It will be angularDir/srcDir + srcDir = 'src' + // Name of the custom tool for chrome stable + chrome = 'Chrome-stable' + + // sonarQube + // Name of the sonarQube tool + sonarTool = 'SonarQube' + // Name of the sonarQube environment + sonarEnv = "SonarQube" + + // Nexus + // Artifact groupId + groupId = 'com.devonfw.mythaistar' + // Nexus repository ID + repositoryId = 'pl-nexus' + // Nexus internal URL + repositoryUrl = 'http://nexus3-core:8081/nexus3/repository/maven-releases' + // Maven global settings configuration ID + globalSettingsId = 'MavenSettings' + // Maven tool id + mavenInstallation = 'Maven3' + } + + stages { + stage ('Loading Custom Tools') { + steps { + tool chrome + } + } + + stage ('Fresh Dependency Installation') { + steps { + dir(angularDir){ + sh "yarn" + } + } + } + + stage ('Code Linting') { + steps { + dir(angularDir) { + sh """yarn ${lintScript}""" + } + } + } + + stage ('Execute Angular tests') { + steps { + dir(angularDir) { + sh """yarn ${testScript}""" + } + } + } + + stage ('SonarQube code analysis') { + steps { + script { + dir(angularDir) { + def scannerHome = tool sonarTool + def props = readJSON file: 'package.json' + withSonarQubeEnv(sonarEnv) { + sh """ + ${scannerHome}/bin/sonar-scanner \ + -Dsonar.projectKey=${props.name} \ + -Dsonar.projectName=${props.name} \ + -Dsonar.projectVersion=${props.version} \ + -Dsonar.sources=${srcDir} + """ + } + timeout(time: 1, unit: 'HOURS') { + def qg = waitForQualityGate() + if (qg.status != 'OK') { + error "Pipeline aborted due to quality gate failure: ${qg.status}" + } + } + } + } + } + } + + stage ('Build Application') { + steps { + dir(angularDir) { + sh """yarn ${buildScript}""" + } + } + } + + stage ('Deliver application into Nexus') { + steps { + script { + dir(angularDir) { + def props = readJSON file: 'package.json' + zip dir: 'dist/', zipFile: """${props.name}.zip""" + withMaven(globalMavenSettingsConfig: globalSettingsId, maven: mavenInstallation) { + sh """ + mvn deploy:deploy-file \ + -DgroupId=${groupId} \ + -DartifactId=${props.name} \ + -Dversion=${props.version} \ + -Dpackaging=zip \ + -Dfile=${props.name}.zip \ + -DrepositoryId=${repositoryId} \ + -Durl=${repositoryUrl} + """ + } + } + } + } + } + } + + post { + always { + cleanWs() + } + } +} diff --git a/jenkins/angular/deployment/Jenkinsfile b/jenkins/angular/deployment/Jenkinsfile index 5bdf11ff2..bbcc08526 100644 --- a/jenkins/angular/deployment/Jenkinsfile +++ b/jenkins/angular/deployment/Jenkinsfile @@ -22,9 +22,9 @@ pipeline{ credentials(name: 'sshAgentCredentials', defaultValue: 'CHANGE-ME', description: 'ssh credentials', credentialType: 'com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey') string(name: 'nexusApiUrl', defaultValue: "http://nexus3-core:8081/nexus3", description: 'nexus url') credentials(name: 'nexusCredentialsId', defaultValue: "nexus-technical-api", description: 'nexus credentials', credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl') - string(name: 'repository', defaultValue: 'maven-snapshots', description: 'maven repository') + string(name: 'repository', defaultValue: 'maven-releases', description: 'maven repository') - string(name: 'VERSION', defaultValue: '1.12.3-SNAPSHOT', description: 'Version number') + string(name: 'VERSION', defaultValue: '3.1.0', description: 'Version number') string(name: 'EXTERNAL_SERVER_IP', defaultValue: 'CHANGE-ME', description: 'Server IP') string(name: 'APPLICATION_DIR', defaultValue: '/root/mythaistar/reverse-proxy/', description: 'My Thai Star application directory') } @@ -46,11 +46,12 @@ pipeline{ def num = -1 def url = '' props.items.each { - def n = (it.downloadUrl =~ /.*-(\d*)\.zip/)[0][1].toInteger() - if (n > num) { - num = n - url = it.downloadUrl - } + // def n = (it.downloadUrl =~ /.*-(\d*)\.zip/)[0][1].toInteger() + // if (n > num) { + // num = n + // url = it.downloadUrl + // } + url = it.downloadUrl } // Download the snapshot diff --git a/jenkins/deployment/Jenkinsfile b/jenkins/deployment/Jenkinsfile index 6c4555aba..dfb0efefc 100644 --- a/jenkins/deployment/Jenkinsfile +++ b/jenkins/deployment/Jenkinsfile @@ -1,71 +1,71 @@ -pipeline{ - agent any - - options { - buildDiscarder(logRotator(artifactDaysToKeepStr: '1', artifactNumToKeepStr: '1', daysToKeepStr: '5', numToKeepStr: '50')) - // Disable concurrent builds. It will wait until the pipeline finish before start a new one - disableConcurrentBuilds() - } - - environment { - // Java Deploy Pipeline name - javaDeployPipeline = 'MyThaiStar_SERVER_DEPLOY' - // Angular Deploy Pipeline name - angularDeployPipeline = 'MyThaiStar_FRONTEND_DEPLOY' - } - - parameters { - credentials(name: 'sshAgentCredentials', defaultValue: 'CHANGE-ME', description: 'ssh credentials', credentialType: 'com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey') - string(name: 'nexusApiUrl', defaultValue: "http://nexus3-core:8081/nexus3", description: 'nexus url') - credentials(name: 'nexusCredentialsId', defaultValue: "nexus-technical-api", description: 'nexus credentials', credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl') - string(name: 'repository', defaultValue: 'maven-snapshots', description: 'maven repository') - - string(name: 'JAVA_VERSION', defaultValue: '1.12.3-SNAPSHOT', description: 'Java Version number') - string(name: 'ANGULAR_VERSION', defaultValue: '1.12.3-SNAPSHOT', description: 'Angular Version number') - string(name: 'EXTERNAL_SERVER_IP', defaultValue: 'CHANGE-ME', description: 'Server IP') - string(name: 'APPLICATION_DIR', defaultValue: '/root/mythaistar/reverse-proxy/', description: 'My Thai Star application directory') - - } - - - stages { - stage ('Copy files to remote server') { - steps { - sshagent (credentials: [sshAgentCredentials]) { - sh """ - ssh -o StrictHostKeyChecking=no root@${params.EXTERNAL_SERVER_IP} mkdir -p ${params.APPLICATION_DIR} - scp -o StrictHostKeyChecking=no -r reverse-proxy/* root@${params.EXTERNAL_SERVER_IP}:${params.APPLICATION_DIR} - """ - } - } - } - - stage ('Deploy java application') { - steps { - build job: javaDeployPipeline, parameters: [ - credentials(name: 'sshAgentCredentials',value: sshAgentCredentials), - string(name: 'nexusApiUrl',value: nexusApiUrl), - credentials(name: 'nexusCredentialsId',value: nexusCredentialsId), - string(name: 'repository',value: repository), - string(name: 'VERSION', value: params.JAVA_VERSION), - string(name: 'EXTERNAL_SERVER_IP', value: params.EXTERNAL_SERVER_IP), - string(name: 'APPLICATION_DIR', value: params.APPLICATION_DIR) - ] - } - } - - stage ('Deploy angular application') { - steps { - build job: angularDeployPipeline, parameters: [ - credentials(name: 'sshAgentCredentials',value: sshAgentCredentials), - string(name: 'nexusApiUrl',value: nexusApiUrl), - credentials(name: 'nexusCredentialsId',value: nexusCredentialsId), - string(name: 'repository',value: repository), - string(name: 'VERSION', value: params.ANGULAR_VERSION), - string(name: 'EXTERNAL_SERVER_IP', value: params.EXTERNAL_SERVER_IP), - string(name: 'APPLICATION_DIR', value: params.APPLICATION_DIR) - ] - } - } - } +pipeline{ + agent any + + options { + buildDiscarder(logRotator(artifactDaysToKeepStr: '1', artifactNumToKeepStr: '1', daysToKeepStr: '5', numToKeepStr: '50')) + // Disable concurrent builds. It will wait until the pipeline finish before start a new one + disableConcurrentBuilds() + } + + environment { + // Java Deploy Pipeline name + javaDeployPipeline = 'MyThaiStar_SERVER_DEPLOY' + // Angular Deploy Pipeline name + angularDeployPipeline = 'MyThaiStar_FRONTEND_DEPLOY' + } + + parameters { + credentials(name: 'sshAgentCredentials', defaultValue: 'CHANGE-ME', description: 'ssh credentials', credentialType: 'com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey') + string(name: 'nexusApiUrl', defaultValue: "http://nexus3-core:8081/nexus3", description: 'nexus url') + credentials(name: 'nexusCredentialsId', defaultValue: "nexus-technical-api", description: 'nexus credentials', credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl') + string(name: 'repository', defaultValue: 'maven-releases', description: 'maven repository') + + string(name: 'JAVA_VERSION', defaultValue: '3.1.0', description: 'Java Version number') + string(name: 'ANGULAR_VERSION', defaultValue: '3.1.0', description: 'Angular Version number') + string(name: 'EXTERNAL_SERVER_IP', defaultValue: 'CHANGE-ME', description: 'Server IP') + string(name: 'APPLICATION_DIR', defaultValue: '/root/mythaistar/reverse-proxy/', description: 'My Thai Star application directory') + + } + + + stages { + stage ('Copy files to remote server') { + steps { + sshagent (credentials: [sshAgentCredentials]) { + sh """ + ssh -o StrictHostKeyChecking=no root@${params.EXTERNAL_SERVER_IP} mkdir -p ${params.APPLICATION_DIR} + scp -o StrictHostKeyChecking=no -r reverse-proxy/* root@${params.EXTERNAL_SERVER_IP}:${params.APPLICATION_DIR} + """ + } + } + } + + stage ('Deploy java application') { + steps { + build job: javaDeployPipeline, parameters: [ + credentials(name: 'sshAgentCredentials',value: sshAgentCredentials), + string(name: 'nexusApiUrl',value: nexusApiUrl), + credentials(name: 'nexusCredentialsId',value: nexusCredentialsId), + string(name: 'repository',value: repository), + string(name: 'VERSION', value: params.JAVA_VERSION), + string(name: 'EXTERNAL_SERVER_IP', value: params.EXTERNAL_SERVER_IP), + string(name: 'APPLICATION_DIR', value: params.APPLICATION_DIR) + ] + } + } + + stage ('Deploy angular application') { + steps { + build job: angularDeployPipeline, parameters: [ + credentials(name: 'sshAgentCredentials',value: sshAgentCredentials), + string(name: 'nexusApiUrl',value: nexusApiUrl), + credentials(name: 'nexusCredentialsId',value: nexusCredentialsId), + string(name: 'repository',value: repository), + string(name: 'VERSION', value: params.ANGULAR_VERSION), + string(name: 'EXTERNAL_SERVER_IP', value: params.EXTERNAL_SERVER_IP), + string(name: 'APPLICATION_DIR', value: params.APPLICATION_DIR) + ] + } + } + } } \ No newline at end of file diff --git a/jenkins/java/deployment/Jenkinsfile b/jenkins/java/deployment/Jenkinsfile index 42a7614c7..e7e857e74 100644 --- a/jenkins/java/deployment/Jenkinsfile +++ b/jenkins/java/deployment/Jenkinsfile @@ -1,80 +1,87 @@ -pipeline{ - agent any - - options { - buildDiscarder(logRotator(artifactDaysToKeepStr: '1', artifactNumToKeepStr: '1', daysToKeepStr: '5', numToKeepStr: '50')) - // Disable concurrent builds. It will wait until the pipeline finish before start a new one - disableConcurrentBuilds() - } - - environment { - // Maven artifact classifier - classifier = 'bootified' - // Repository format - format = 'maven2' - // Artifact group - group = 'com.devonfw.java.mtsj' - // Application name - name = 'mtsj-server' - // Artifact extension - extension = 'war' - } - - parameters { - credentials(name: 'sshAgentCredentials', defaultValue: 'CHANGE-ME', description: 'ssh credentials', credentialType: 'com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey') - string(name: 'nexusApiUrl', defaultValue: "http://nexus3-core:8081/nexus3", description: 'nexus url') - credentials(name: 'nexusCredentialsId', defaultValue: "nexus-technical-api", description: 'nexus credentials', credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl') - string(name: 'repository', defaultValue: 'maven-snapshots', description: 'maven repository') - string(name: 'VERSION', defaultValue: '1.12.3-SNAPSHOT', description: 'Version number') - string(name: 'EXTERNAL_SERVER_IP', defaultValue: 'CHANGE-ME', description: 'Server IP') - string(name: 'APPLICATION_DIR', defaultValue: '/root/mythaistar/reverse-proxy/', description: 'My Thai Star application directory') - } - - stages { - stage ('Download artifact from Nexus') { - steps { - script { - // Download artifact from nexus3 using the nexus3 beta api - // Search the list of artifacts - def response = httpRequest authentication: nexusCredentialsId, consoleLogResponseBody: true, ignoreSslErrors: true, responseHandle: 'NONE', url: """${nexusApiUrl}/service/rest/beta/search/assets?repository=${repository}&format=${format}&group=${group}&name=${name}&maven.groupId=${group}&maven.artifactId=${name}&maven.baseVersion=${params.VERSION}&maven.classifier=${classifier}&maven.extension=${extension}""" - def props = readJSON text: response.content - - // Get the last snapshot download url - def num = -1 - def url = '' - props.items.each { - def n = (it.downloadUrl =~ /.*-(\d*)-bootified\.war/)[0][1] - println n - if (n > num) { - num = n - url = it.downloadUrl - } - } - - // Download the snapshot - httpRequest authentication: nexusCredentialsId, ignoreSslErrors: true, outputFile: 'mythaistar.war', responseHandle: 'NONE', url: url - } - } - } - - stage('Deployment') { - steps { - sshagent (credentials: [sshAgentCredentials]) { - sh """ - # Copy resulting ".war" file from workspace to deployment server - scp -o StrictHostKeyChecking=no mythaistar.war root@${params.EXTERNAL_SERVER_IP}:${params.APPLICATION_DIR}java/mythaistar.war - - # Launch application in Docker container - ssh -o StrictHostKeyChecking=no root@${params.EXTERNAL_SERVER_IP} docker-compose -f ${params.APPLICATION_DIR}docker-compose.yml up -d --build java - """ - } - } - } - } - - post { - always { - cleanWs() - } - } -} +pipeline{ + agent any + + options { + buildDiscarder(logRotator(artifactDaysToKeepStr: '1', artifactNumToKeepStr: '1', daysToKeepStr: '5', numToKeepStr: '50')) + // Disable concurrent builds. It will wait until the pipeline finish before start a new one + disableConcurrentBuilds() + } + + environment { + // Maven artifact classifier + classifier = 'bootified' + // Repository format + format = 'maven2' + // Artifact group + group = 'com.devonfw.java.mtsj' + // Application name + name = 'mtsj-server' + // Artifact extension + extension = 'war' + } + + parameters { + credentials(name: 'sshAgentCredentials', defaultValue: 'CHANGE-ME', description: 'ssh credentials', credentialType: 'com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey') + string(name: 'nexusApiUrl', defaultValue: "http://nexus3-core:8081/nexus3", description: 'nexus url') + credentials(name: 'nexusCredentialsId', defaultValue: "nexus-technical-api", description: 'nexus credentials', credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl') + string(name: 'repository', defaultValue: 'maven-releases', description: 'maven repository') + string(name: 'VERSION', defaultValue: '3.1.0', description: 'Version number') + string(name: 'EXTERNAL_SERVER_IP', defaultValue: 'CHANGE-ME', description: 'Server IP') + string(name: 'APPLICATION_DIR', defaultValue: '/root/mythaistar/reverse-proxy/', description: 'My Thai Star application directory') + } + + stages { + stage ('Download artifact from Nexus') { + steps { + script { + // Download artifact from nexus3 using the nexus3 beta api + // Search the list of artifacts + def response = '' + try { + response = httpRequest authentication: nexusCredentialsId, consoleLogResponseBody: true, ignoreSslErrors: true, responseHandle: 'NONE', url: """${nexusApiUrl}/service/rest/v1/search/assets?repository=${repository}&format=${format}&group=${group}&name=${name}&maven.groupId=${group}&maven.artifactId=${name}&maven.baseVersion=${params.VERSION}&maven.classifier=${classifier}&maven.extension=${extension}""" + }catch (e) { + response = httpRequest authentication: nexusCredentialsId, consoleLogResponseBody: true, ignoreSslErrors: true, responseHandle: 'NONE', url: """${nexusApiUrl}/service/rest/beta/search/assets?repository=${repository}&format=${format}&group=${group}&name=${name}&maven.groupId=${group}&maven.artifactId=${name}&maven.baseVersion=${params.VERSION}&maven.classifier=${classifier}&maven.extension=${extension}""" + } + def props = readJSON text: response.content + + // Get the last snapshot download url + def num = -1 + def url = '' + props.items.each { + // def n = (it.downloadUrl =~ /.*-(\d*)-bootified\.war/)[0][1] + // println n + // if (n > num) { + // num = n + // url = it.downloadUrl + // } + url = it.downloadUrl + } + + + // Download the snapshot + httpRequest authentication: nexusCredentialsId, ignoreSslErrors: true, outputFile: 'mythaistar.war', responseHandle: 'NONE', url: url + } + } + } + + stage('Deployment') { + steps { + sshagent (credentials: [sshAgentCredentials]) { + sh """ + # Copy resulting ".war" file from workspace to deployment server + scp -o StrictHostKeyChecking=no mythaistar.war root@${params.EXTERNAL_SERVER_IP}:${params.APPLICATION_DIR}java/mythaistar.war + + # Launch application in Docker container + ssh -o StrictHostKeyChecking=no root@${params.EXTERNAL_SERVER_IP} docker-compose -f ${params.APPLICATION_DIR}docker-compose.yml up -d --build java + """ + } + } + } + } + + post { + always { + cleanWs() + } + } +} diff --git a/reverse-proxy/angular/Dockerfile b/reverse-proxy/angular/Dockerfile index 40d5612cb..aba8889bd 100644 --- a/reverse-proxy/angular/Dockerfile +++ b/reverse-proxy/angular/Dockerfile @@ -3,9 +3,10 @@ FROM nginx:latest RUN apt-get update \ && apt-get install -y --no-install-recommends \ curl \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* \ + && mkdir /var/www COPY nginx.conf /etc/nginx/nginx.conf -COPY ./dist/ /var/www/ +COPY ./dist/* /var/www COPY docker-external-config.json /var/www/docker-external-config.json -HEALTHCHECK --interval=60s --timeout=30s --start-period=1s --retries=3 CMD curl --fail http://localhost/health || exit 1 \ No newline at end of file +HEALTHCHECK --interval=60s --timeout=30s --retries=3 CMD curl --fail http://localhost/health || exit 1 \ No newline at end of file diff --git a/reverse-proxy/java/Dockerfile b/reverse-proxy/java/Dockerfile index ec90dc556..7e9b8f96b 100644 --- a/reverse-proxy/java/Dockerfile +++ b/reverse-proxy/java/Dockerfile @@ -1,6 +1,6 @@ FROM java:8 WORKDIR /app COPY ./mythaistar.war /app/ -HEALTHCHECK --interval=10s --timeout=5s --start-period=20s --retries=3 CMD curl --fail http://localhost:8081/mythaistar/services/rest/dishmanagement/v1/category/0/ || exit 1 +HEALTHCHECK --interval=60s --timeout=30s --retries=3 CMD curl --fail http://localhost:8081/mythaistar/services/rest/dishmanagement/v1/category/0/ || exit 1 ENTRYPOINT ["java","-jar","/app/mythaistar.war"] EXPOSE 8081 \ No newline at end of file