From eb2a07dabd4b3f8ca988cbe1cec9bb2aed282d13 Mon Sep 17 00:00:00 2001 From: loveresolution Date: Tue, 29 Oct 2019 19:54:26 +0800 Subject: [PATCH 1/6] update jenkinsfile --- Jenkinsfile-online | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 67c8a7f2..4664ace5 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -14,8 +14,8 @@ pipeline { GITHUB_CREDENTIAL_ID = 'github-id' KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' REGISTRY = 'docker.io' - DOCKERHUB_NAMESPACE = 'docker_username' - GITHUB_ACCOUNT = 'kubesphere' + DOCKERHUB_NAMESPACE = 'lovekernel' + GITHUB_ACCOUNT = 'loveresolution' APP_NAME = 'devops-java-sample' SONAR_CREDENTIAL_ID= 'sonar-token' } From d5fe82037d7599636fbdea71f13fc4fe4683bf91 Mon Sep 17 00:00:00 2001 From: loveresolution Date: Wed, 30 Oct 2019 18:50:39 +0800 Subject: [PATCH 2/6] add jenkinsfile add --- Jenkinsfile | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..4664ace5 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,119 @@ +pipeline { + agent { + node { + label 'maven' + } + } + + parameters { + string(name:'TAG_NAME',defaultValue: '',description:'') + } + + environment { + DOCKER_CREDENTIAL_ID = 'dockerhub-id' + GITHUB_CREDENTIAL_ID = 'github-id' + KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' + REGISTRY = 'docker.io' + DOCKERHUB_NAMESPACE = 'lovekernel' + GITHUB_ACCOUNT = 'loveresolution' + APP_NAME = 'devops-java-sample' + SONAR_CREDENTIAL_ID= 'sonar-token' + } + + stages { + stage ('checkout scm') { + steps { + checkout(scm) + } + } + + stage ('unit test') { + steps { + container ('maven') { + sh 'mvn clean -o -gs `pwd`/configuration/settings.xml test' + } + } + } + + stage('sonarqube analysis') { + steps { + container ('maven') { + withCredentials([string(credentialsId: "$SONAR_CREDENTIAL_ID", variable: 'SONAR_TOKEN')]) { + withSonarQubeEnv('sonar') { + sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" + } + } + timeout(time: 1, unit: 'HOURS') { + waitForQualityGate abortPipeline: true + } + } + } + } + + stage ('build & push') { + steps { + container ('maven') { + sh 'mvn -o -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package' + sh 'docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' + withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$DOCKER_CREDENTIAL_ID" ,)]) { + sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin' + sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' + } + } + } + } + + stage('push latest'){ + when{ + branch 'master' + } + steps{ + container ('maven') { + sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest ' + sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest ' + } + } + } + + stage('deploy to dev') { + when{ + branch 'master' + } + steps { + input(id: 'deploy-to-dev', message: 'deploy to dev?') + kubernetesDeploy(configs: 'deploy/dev-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") + } + } + stage('push with tag'){ + when{ + expression{ + return params.TAG_NAME =~ /v.*/ + } + } + steps { + container ('maven') { + input(id: 'release-image-with-tag', message: 'release image with tag?') + withCredentials([usernamePassword(credentialsId: "$GITHUB_CREDENTIAL_ID", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) { + sh 'git config --global user.email "kubesphere@yunify.com" ' + sh 'git config --global user.name "kubesphere" ' + sh 'git tag -a $TAG_NAME -m "$TAG_NAME" ' + sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@github.com/$GITHUB_ACCOUNT/devops-java-sample.git --tags --ipv4' + } + sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME ' + sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME ' + } + } + } + stage('deploy to production') { + when{ + expression{ + return params.TAG_NAME =~ /v.*/ + } + } + steps { + input(id: 'deploy-to-production', message: 'deploy to production?') + kubernetesDeploy(configs: 'deploy/prod-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") + } + } + } +} From e85a65ef21fcd2f478b603d2c755654c40d91736 Mon Sep 17 00:00:00 2001 From: loveresolution Date: Thu, 31 Oct 2019 14:46:45 +0800 Subject: [PATCH 3/6] update --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4664ace5..1cd29452 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -94,8 +94,8 @@ pipeline { container ('maven') { input(id: 'release-image-with-tag', message: 'release image with tag?') withCredentials([usernamePassword(credentialsId: "$GITHUB_CREDENTIAL_ID", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) { - sh 'git config --global user.email "kubesphere@yunify.com" ' - sh 'git config --global user.name "kubesphere" ' + sh 'git config --global user.email "zhfeijian@gmail.com" ' + sh 'git config --global user.name "loveresolution" ' sh 'git tag -a $TAG_NAME -m "$TAG_NAME" ' sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@github.com/$GITHUB_ACCOUNT/devops-java-sample.git --tags --ipv4' } From 9725e4185cd8d187928dd2effbfd905a5515556a Mon Sep 17 00:00:00 2001 From: loveresolution Date: Thu, 31 Oct 2019 15:12:03 +0800 Subject: [PATCH 4/6] update update --- Jenkinsfile-online | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 4664ace5..9750f629 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -94,8 +94,8 @@ pipeline { container ('maven') { input(id: 'release-image-with-tag', message: 'release image with tag?') withCredentials([usernamePassword(credentialsId: "$GITHUB_CREDENTIAL_ID", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) { - sh 'git config --global user.email "kubesphere@yunify.com" ' - sh 'git config --global user.name "kubesphere" ' + sh 'git config --global user.email "zhfeijian@126.com" ' + sh 'git config --global user.name "loveresolution" ' sh 'git tag -a $TAG_NAME -m "$TAG_NAME" ' sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@github.com/$GITHUB_ACCOUNT/devops-java-sample.git --tags --ipv4' } From 4b39a3066250082dfd91a6cf51f81857a50c49aa Mon Sep 17 00:00:00 2001 From: loveresolution Date: Thu, 31 Oct 2019 18:18:01 +0800 Subject: [PATCH 5/6] update cpu update cpu --- deploy/dev/devops-sample.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/dev/devops-sample.yaml b/deploy/dev/devops-sample.yaml index 9d8e18f7..043b2574 100644 --- a/deploy/dev/devops-sample.yaml +++ b/deploy/dev/devops-sample.yaml @@ -44,7 +44,7 @@ spec: resources: limits: cpu: 200m - memory: 500Mi + memory: 1000Mi requests: cpu: 100m memory: 100Mi @@ -52,4 +52,4 @@ spec: terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always - terminationGracePeriodSeconds: 30 \ No newline at end of file + terminationGracePeriodSeconds: 30 From 272c321060fcd00ca5f569554e1918f6f3d62eb0 Mon Sep 17 00:00:00 2001 From: loveresolution Date: Thu, 31 Oct 2019 18:18:29 +0800 Subject: [PATCH 6/6] update cpu update cpu --- deploy/prod/devops-sample.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/prod/devops-sample.yaml b/deploy/prod/devops-sample.yaml index 1058cb41..ed7654ad 100644 --- a/deploy/prod/devops-sample.yaml +++ b/deploy/prod/devops-sample.yaml @@ -49,7 +49,7 @@ spec: resources: limits: cpu: 200m - memory: 500Mi + memory: 1000Mi requests: cpu: 100m memory: 100Mi @@ -57,4 +57,4 @@ spec: terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always - terminationGracePeriodSeconds: 30 \ No newline at end of file + terminationGracePeriodSeconds: 30