From 852787b880e5c8863ccfe8219c21c90506b1686c Mon Sep 17 00:00:00 2001 From: runzexia Date: Thu, 11 Apr 2019 14:26:17 +0800 Subject: [PATCH 01/14] Update HelloWorldController.java --- src/main/java/io/kubesphere/devops/HelloWorldController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/kubesphere/devops/HelloWorldController.java b/src/main/java/io/kubesphere/devops/HelloWorldController.java index 9534dc9d..ef01c4b9 100644 --- a/src/main/java/io/kubesphere/devops/HelloWorldController.java +++ b/src/main/java/io/kubesphere/devops/HelloWorldController.java @@ -14,6 +14,6 @@ public class HelloWorldController { @RequestMapping("/") public String sayHello() { - return "Hello,World!"; + return "Hello,KubeSphere!"; } -} \ No newline at end of file +} From 070b9551a8c1a1c433d2f31aece12766d07a1b5b Mon Sep 17 00:00:00 2001 From: runzexia Date: Thu, 11 Apr 2019 15:41:08 +0800 Subject: [PATCH 02/14] Update Jenkinsfile-online --- Jenkinsfile-online | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 1b49cae4..5ef87239 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -38,8 +38,10 @@ pipeline { stage('sonarqube analysis') { steps { container ('maven') { - withSonarQubeEnv('sonar') { - sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN_ID" + withCredentials([string(credentialsId: "$SONAR_TOKEN_ID", variable: 'SONAR_TOKEN')]) { + withSonarQubeEnv('sonar') { + sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=ks-devops -Dsonar.sources=. -Dsonar.login=$SONAR_TOKEN" + } } timeout(time: 1, unit: 'HOURS') { waitForQualityGate abortPipeline: true From 6a3969c3b351b1515e1c5a267aaf25670239300f Mon Sep 17 00:00:00 2001 From: runzexia Date: Thu, 11 Apr 2019 15:43:48 +0800 Subject: [PATCH 03/14] Update HelloWorldController.java --- src/main/java/io/kubesphere/devops/HelloWorldController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/kubesphere/devops/HelloWorldController.java b/src/main/java/io/kubesphere/devops/HelloWorldController.java index ef01c4b9..ade8c5bf 100644 --- a/src/main/java/io/kubesphere/devops/HelloWorldController.java +++ b/src/main/java/io/kubesphere/devops/HelloWorldController.java @@ -14,6 +14,6 @@ public class HelloWorldController { @RequestMapping("/") public String sayHello() { - return "Hello,KubeSphere!"; + return "Hello,World!"; } } From 47f792d508a31b64f3d9e3c0f52678e6654ccde9 Mon Sep 17 00:00:00 2001 From: runzexia Date: Thu, 11 Apr 2019 15:45:34 +0800 Subject: [PATCH 04/14] Update Jenkinsfile-online --- Jenkinsfile-online | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 5ef87239..9730603d 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -40,7 +40,7 @@ pipeline { container ('maven') { withCredentials([string(credentialsId: "$SONAR_TOKEN_ID", variable: 'SONAR_TOKEN')]) { withSonarQubeEnv('sonar') { - sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=ks-devops -Dsonar.sources=. -Dsonar.login=$SONAR_TOKEN" + sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN_ID" } } timeout(time: 1, unit: 'HOURS') { From 9994ee452216515f6bd066d92bb16e505091f168 Mon Sep 17 00:00:00 2001 From: runzexia Date: Thu, 11 Apr 2019 15:46:28 +0800 Subject: [PATCH 05/14] Update Jenkinsfile --- Jenkinsfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7a3501bb..f74a02c9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -38,8 +38,10 @@ pipeline { stage('sonarqube analysis') { steps { container ('maven') { - withSonarQubeEnv('sonar') { - sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN_ID" + withCredentials([string(credentialsId: "$SONAR_TOKEN_ID", variable: 'SONAR_TOKEN')]) { + withSonarQubeEnv('sonar') { + sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN_ID" + } } timeout(time: 1, unit: 'HOURS') { waitForQualityGate abortPipeline: true From be6f9b0984068fb1a71289710311dabc464ddccd Mon Sep 17 00:00:00 2001 From: runzexia Date: Thu, 11 Apr 2019 15:50:02 +0800 Subject: [PATCH 06/14] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f74a02c9..08b28d0d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -40,7 +40,7 @@ pipeline { container ('maven') { withCredentials([string(credentialsId: "$SONAR_TOKEN_ID", variable: 'SONAR_TOKEN')]) { withSonarQubeEnv('sonar') { - sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN_ID" + sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" } } timeout(time: 1, unit: 'HOURS') { From 1364736464d7b6a99f6888a7f66f2376a50c97c6 Mon Sep 17 00:00:00 2001 From: runzexia Date: Thu, 11 Apr 2019 15:50:19 +0800 Subject: [PATCH 07/14] Update Jenkinsfile-online --- Jenkinsfile-online | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 9730603d..61878d3d 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -40,7 +40,7 @@ pipeline { container ('maven') { withCredentials([string(credentialsId: "$SONAR_TOKEN_ID", variable: 'SONAR_TOKEN')]) { withSonarQubeEnv('sonar') { - sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN_ID" + sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" } } timeout(time: 1, unit: 'HOURS') { From e971a70b1592b5cc750c6d67b2f60ba540cb2a35 Mon Sep 17 00:00:00 2001 From: runzexia Date: Thu, 11 Apr 2019 16:04:31 +0800 Subject: [PATCH 08/14] Update Jenkinsfile --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 08b28d0d..e108176e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,7 +17,7 @@ pipeline { NAMESPACE = 'library' GITLAB_ACCOUNT = 'admin1' APP_NAME = 'devops-sample-s2i' - SONAR_TOKEN_ID= 'sonar-token' + SONAR_CREDENTIAL_ID= 'sonar-token' } stages { @@ -38,7 +38,7 @@ pipeline { stage('sonarqube analysis') { steps { container ('maven') { - withCredentials([string(credentialsId: "$SONAR_TOKEN_ID", variable: 'SONAR_TOKEN')]) { + 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" } From 4fe318c3e28cf411c5ad586056ed7864b02973de Mon Sep 17 00:00:00 2001 From: runzexia Date: Thu, 11 Apr 2019 16:05:11 +0800 Subject: [PATCH 09/14] Update Jenkinsfile-online --- Jenkinsfile-online | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 61878d3d..d13d093a 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -17,7 +17,7 @@ pipeline { NAMESPACE = 'docker_username' GITHUB_ACCOUNT = 'kubesphere' APP_NAME = 'devops-sample-s2i' - SONAR_TOKEN_ID= 'sonar-token' + SONAR_CREDENTIAL_ID= 'sonar-token' } stages { @@ -38,7 +38,7 @@ pipeline { stage('sonarqube analysis') { steps { container ('maven') { - withCredentials([string(credentialsId: "$SONAR_TOKEN_ID", variable: 'SONAR_TOKEN')]) { + 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" } From 9562ecb11fe8c37c8e5ab9741c28d29049bed6a3 Mon Sep 17 00:00:00 2001 From: soulseen Date: Fri, 12 Apr 2019 13:53:18 +0800 Subject: [PATCH 10/14] add readiness & modify NAMESPACE --- Jenkinsfile | 4 +- Jenkinsfile-online | 28 +++--- deploy/Jenkinsfile | 117 ++++++++++++++++++++++++++ deploy/Jenkinsfile-online | 117 ++++++++++++++++++++++++++ deploy/dev-ol/devops-sample-svc.yaml | 21 +++++ deploy/dev-ol/devops-sample.yaml | 52 ++++++++++++ deploy/dev/devops-sample.yaml | 4 + deploy/prod-ol/devops-sample-svc.yaml | 21 +++++ deploy/prod-ol/devops-sample.yaml | 57 +++++++++++++ deploy/prod/devops-sample.yaml | 4 + 10 files changed, 409 insertions(+), 16 deletions(-) create mode 100644 deploy/Jenkinsfile create mode 100644 deploy/Jenkinsfile-online create mode 100644 deploy/dev-ol/devops-sample-svc.yaml create mode 100644 deploy/dev-ol/devops-sample.yaml create mode 100644 deploy/prod-ol/devops-sample-svc.yaml create mode 100644 deploy/prod-ol/devops-sample.yaml diff --git a/Jenkinsfile b/Jenkinsfile index e108176e..9084439f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,7 +17,7 @@ pipeline { NAMESPACE = 'library' GITLAB_ACCOUNT = 'admin1' APP_NAME = 'devops-sample-s2i' - SONAR_CREDENTIAL_ID= 'sonar-token' + SONAR_TOKEN_ID= 'sonar-token' } stages { @@ -40,7 +40,7 @@ pipeline { 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" + sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" } } timeout(time: 1, unit: 'HOURS') { diff --git a/Jenkinsfile-online b/Jenkinsfile-online index d13d093a..d5272ab3 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -14,10 +14,10 @@ pipeline { GITHUB_CREDENTIAL_ID = 'github-id' KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' REDISTRY = 'docker.io' - NAMESPACE = 'docker_username' + DOCKERHUB_NAMESPACE = 'docker_username' GITHUB_ACCOUNT = 'kubesphere' APP_NAME = 'devops-sample-s2i' - SONAR_CREDENTIAL_ID= 'sonar-token' + SONAR_TOKEN_ID= 'sonar-token' } stages { @@ -38,10 +38,10 @@ pipeline { 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" - } +- 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 @@ -54,10 +54,10 @@ pipeline { steps { container ('maven') { sh 'mvn -o -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package' - sh 'docker build -f Dockerfile-online -t $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' + sh 'docker build -f Dockerfile-online -t $REDISTRY/$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 $REDISTRY -u "$DOCKER_USERNAME" --password-stdin' - sh 'docker push $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' + sh 'docker push $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' } } } @@ -69,8 +69,8 @@ pipeline { } steps{ container ('maven') { - sh 'docker tag $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$NAMESPACE/$APP_NAME:latest ' - sh 'docker push $REDISTRY/$NAMESPACE/$APP_NAME:latest ' + sh 'docker tag $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest ' + sh 'docker push $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest ' } } } @@ -81,7 +81,7 @@ pipeline { } steps { input(id: 'deploy-to-dev', message: 'deploy to dev?') - kubernetesDeploy(configs: 'deploy/dev/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") + kubernetesDeploy(configs: 'deploy/dev-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") } } stage('push with tag'){ @@ -99,8 +99,8 @@ pipeline { sh 'git tag -a $TAG_NAME -m "$TAG_NAME" ' sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@github.com/$GITHUB_ACCOUNT/devops-sample-s2i.git --tags' } - sh 'docker tag $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$NAMESPACE/$APP_NAME:$TAG_NAME ' - sh 'docker push $REDISTRY/$NAMESPACE/$APP_NAME:$TAG_NAME ' + sh 'docker tag $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME ' + sh 'docker push $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME ' } } } @@ -112,7 +112,7 @@ pipeline { } steps { input(id: 'deploy-to-production', message: 'deploy to production?') - kubernetesDeploy(configs: 'deploy/prod/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") + kubernetesDeploy(configs: 'deploy/prod-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") } } } diff --git a/deploy/Jenkinsfile b/deploy/Jenkinsfile new file mode 100644 index 00000000..7a3501bb --- /dev/null +++ b/deploy/Jenkinsfile @@ -0,0 +1,117 @@ +pipeline { + agent { + node { + label 'maven' + } + } + + parameters { + string(name:'TAG_NAME',defaultValue: '',description:'') + } + + environment { + HARBOR_CREDENTIAL_ID = 'harbor-id' + GITLAB_CREDENTIAL_ID = 'gitlab-id' + KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' + REDISTRY = 'harbor.devops.kubesphere.local:30280' + NAMESPACE = 'library' + GITLAB_ACCOUNT = 'admin1' + APP_NAME = 'devops-sample-s2i' + SONAR_TOKEN_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') { + withSonarQubeEnv('sonar') { + sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN_ID" + } + 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 -t $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' + withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$HARBOR_CREDENTIAL_ID" ,)]) { + sh 'echo "$DOCKER_PASSWORD" | docker login $REDISTRY -u "$DOCKER_USERNAME" --password-stdin' + sh 'docker push $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' + } + } + } + } + + stage('push latest'){ + when{ + branch 'master' + } + steps{ + container ('maven') { + sh 'docker tag $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$NAMESPACE/$APP_NAME:latest ' + sh 'docker push $REDISTRY/$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/**', 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: "$GITLAB_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@gitlab.devops.kubesphere.local:30080/$GITLAB_ACCOUNT/devops-sample-s2i.git --tags' + } + sh 'docker tag $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$NAMESPACE/$APP_NAME:$TAG_NAME ' + sh 'docker push $REDISTRY/$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/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") + } + } + } +} diff --git a/deploy/Jenkinsfile-online b/deploy/Jenkinsfile-online new file mode 100644 index 00000000..3e827d15 --- /dev/null +++ b/deploy/Jenkinsfile-online @@ -0,0 +1,117 @@ +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' + REDISTRY = 'docker.io' + DOCKERHUB_NAMESPACE = 'docker_username' + GITHUB_ACCOUNT = 'kubesphere' + APP_NAME = 'devops-sample-s2i' + SONAR_TOKEN_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') { + withSonarQubeEnv('sonar') { + sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN_ID" + } + 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 $REDISTRY/$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 $REDISTRY -u "$DOCKER_USERNAME" --password-stdin' + sh 'docker push $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' + } + } + } + } + + stage('push latest'){ + when{ + branch 'master' + } + steps{ + container ('maven') { + sh 'docker tag $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest ' + sh 'docker push $REDISTRY/$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-sample-s2i.git --tags' + } + sh 'docker tag $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME ' + sh 'docker push $REDISTRY/$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") + } + } + } +} diff --git a/deploy/dev-ol/devops-sample-svc.yaml b/deploy/dev-ol/devops-sample-svc.yaml new file mode 100644 index 00000000..24fff6f3 --- /dev/null +++ b/deploy/dev-ol/devops-sample-svc.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: kubesphere + component: ks-sample-dev + name: ks-sample-dev + namespace: kubesphere-sample-dev +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 + nodePort: 30861 + selector: + app: kubesphere + component: ks-sample-dev + tier: backend + sessionAffinity: None + type: NodePort \ No newline at end of file diff --git a/deploy/dev-ol/devops-sample.yaml b/deploy/dev-ol/devops-sample.yaml new file mode 100644 index 00000000..3c2fce9f --- /dev/null +++ b/deploy/dev-ol/devops-sample.yaml @@ -0,0 +1,52 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + labels: + app: kubesphere + component: ks-sample-dev + tier: backend + name: ks-sample-dev + namespace: kubesphere-sample-dev +spec: + progressDeadlineSeconds: 600 + replicas: 1 + selector: + matchLabels: + app: kubesphere + component: ks-sample-dev + tier: backend + template: + metadata: + labels: + app: kubesphere + component: ks-sample-dev + tier: backend + spec: + containers: + - env: + - name: CACHE_IGNORE + value: js|html + - name: CACHE_PUBLIC_EXPIRATION + value: 3d + image: $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER + readinessProbe: + httpGet: + path: / + port: 8080 + imagePullPolicy: Always + name: ks-sample + ports: + - containerPort: 8080 + protocol: TCP + resources: + limits: + cpu: 200m + memory: 500Mi + requests: + cpu: 100m + memory: 100Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + dnsPolicy: ClusterFirst + restartPolicy: Always + terminationGracePeriodSeconds: 30 \ No newline at end of file diff --git a/deploy/dev/devops-sample.yaml b/deploy/dev/devops-sample.yaml index 55ccbfc2..d2a0adcd 100644 --- a/deploy/dev/devops-sample.yaml +++ b/deploy/dev/devops-sample.yaml @@ -29,6 +29,10 @@ spec: - name: CACHE_PUBLIC_EXPIRATION value: 3d image: $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER + readinessProbe: + httpGet: + path: / + port: 8080 imagePullPolicy: Always name: ks-sample ports: diff --git a/deploy/prod-ol/devops-sample-svc.yaml b/deploy/prod-ol/devops-sample-svc.yaml new file mode 100644 index 00000000..6211066c --- /dev/null +++ b/deploy/prod-ol/devops-sample-svc.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: kubesphere + component: ks-sample + name: ks-sample + namespace: kubesphere-sample-prod +spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 + nodePort: 30961 + selector: + app: kubesphere + component: ks-sample + tier: backend + sessionAffinity: None + type: NodePort \ No newline at end of file diff --git a/deploy/prod-ol/devops-sample.yaml b/deploy/prod-ol/devops-sample.yaml new file mode 100644 index 00000000..76a1c81b --- /dev/null +++ b/deploy/prod-ol/devops-sample.yaml @@ -0,0 +1,57 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + labels: + app: kubesphere + component: ks-sample + tier: backend + name: ks-sample + namespace: kubesphere-sample-prod +spec: + progressDeadlineSeconds: 600 + replicas: 2 + selector: + matchLabels: + app: kubesphere + component: ks-sample + tier: backend + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + type: RollingUpdate + template: + metadata: + labels: + app: kubesphere + component: ks-sample + tier: backend + spec: + containers: + - env: + - name: CACHE_IGNORE + value: js|html + - name: CACHE_PUBLIC_EXPIRATION + value: 3d + image: $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME + readinessProbe: + httpGet: + path: / + port: 8080 + imagePullPolicy: Always + name: ks + ports: + - containerPort: 8080 + protocol: TCP + resources: + limits: + cpu: 200m + memory: 500Mi + requests: + cpu: 100m + memory: 100Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + dnsPolicy: ClusterFirst + restartPolicy: Always + terminationGracePeriodSeconds: 30 \ No newline at end of file diff --git a/deploy/prod/devops-sample.yaml b/deploy/prod/devops-sample.yaml index 2cd6ee12..cfae180d 100644 --- a/deploy/prod/devops-sample.yaml +++ b/deploy/prod/devops-sample.yaml @@ -34,6 +34,10 @@ spec: - name: CACHE_PUBLIC_EXPIRATION value: 3d image: $REDISTRY/$NAMESPACE/$APP_NAME:$TAG_NAME + readinessProbe: + httpGet: + path: / + port: 8080 imagePullPolicy: Always name: ks ports: From 8d4226a77a1ab11c07a8a1398e7f6f88e2c5a774 Mon Sep 17 00:00:00 2001 From: soulseen Date: Fri, 12 Apr 2019 13:57:33 +0800 Subject: [PATCH 11/14] clean --- Jenkinsfile | 2 +- Jenkinsfile-online | 4 +- deploy/Jenkinsfile | 117 -------------------------------------- deploy/Jenkinsfile-online | 117 -------------------------------------- 4 files changed, 3 insertions(+), 237 deletions(-) delete mode 100644 deploy/Jenkinsfile delete mode 100644 deploy/Jenkinsfile-online diff --git a/Jenkinsfile b/Jenkinsfile index 9084439f..42631aed 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,7 +17,7 @@ pipeline { NAMESPACE = 'library' GITLAB_ACCOUNT = 'admin1' APP_NAME = 'devops-sample-s2i' - SONAR_TOKEN_ID= 'sonar-token' + SONAR_CREDENTIAL_ID= 'sonar-token' } stages { diff --git a/Jenkinsfile-online b/Jenkinsfile-online index d5272ab3..02766c21 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -17,7 +17,7 @@ pipeline { DOCKERHUB_NAMESPACE = 'docker_username' GITHUB_ACCOUNT = 'kubesphere' APP_NAME = 'devops-sample-s2i' - SONAR_TOKEN_ID= 'sonar-token' + SONAR_CREDENTIAL_ID= 'sonar-token' } stages { @@ -40,7 +40,7 @@ pipeline { 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" +- sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" - } } timeout(time: 1, unit: 'HOURS') { diff --git a/deploy/Jenkinsfile b/deploy/Jenkinsfile deleted file mode 100644 index 7a3501bb..00000000 --- a/deploy/Jenkinsfile +++ /dev/null @@ -1,117 +0,0 @@ -pipeline { - agent { - node { - label 'maven' - } - } - - parameters { - string(name:'TAG_NAME',defaultValue: '',description:'') - } - - environment { - HARBOR_CREDENTIAL_ID = 'harbor-id' - GITLAB_CREDENTIAL_ID = 'gitlab-id' - KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' - REDISTRY = 'harbor.devops.kubesphere.local:30280' - NAMESPACE = 'library' - GITLAB_ACCOUNT = 'admin1' - APP_NAME = 'devops-sample-s2i' - SONAR_TOKEN_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') { - withSonarQubeEnv('sonar') { - sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN_ID" - } - 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 -t $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' - withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$HARBOR_CREDENTIAL_ID" ,)]) { - sh 'echo "$DOCKER_PASSWORD" | docker login $REDISTRY -u "$DOCKER_USERNAME" --password-stdin' - sh 'docker push $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' - } - } - } - } - - stage('push latest'){ - when{ - branch 'master' - } - steps{ - container ('maven') { - sh 'docker tag $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$NAMESPACE/$APP_NAME:latest ' - sh 'docker push $REDISTRY/$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/**', 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: "$GITLAB_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@gitlab.devops.kubesphere.local:30080/$GITLAB_ACCOUNT/devops-sample-s2i.git --tags' - } - sh 'docker tag $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$NAMESPACE/$APP_NAME:$TAG_NAME ' - sh 'docker push $REDISTRY/$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/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") - } - } - } -} diff --git a/deploy/Jenkinsfile-online b/deploy/Jenkinsfile-online deleted file mode 100644 index 3e827d15..00000000 --- a/deploy/Jenkinsfile-online +++ /dev/null @@ -1,117 +0,0 @@ -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' - REDISTRY = 'docker.io' - DOCKERHUB_NAMESPACE = 'docker_username' - GITHUB_ACCOUNT = 'kubesphere' - APP_NAME = 'devops-sample-s2i' - SONAR_TOKEN_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') { - withSonarQubeEnv('sonar') { - sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN_ID" - } - 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 $REDISTRY/$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 $REDISTRY -u "$DOCKER_USERNAME" --password-stdin' - sh 'docker push $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' - } - } - } - } - - stage('push latest'){ - when{ - branch 'master' - } - steps{ - container ('maven') { - sh 'docker tag $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest ' - sh 'docker push $REDISTRY/$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-sample-s2i.git --tags' - } - sh 'docker tag $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME ' - sh 'docker push $REDISTRY/$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 438c5dd412ad955a7955fd587f83bbffb00efe64 Mon Sep 17 00:00:00 2001 From: soulseen Date: Fri, 12 Apr 2019 14:21:15 +0800 Subject: [PATCH 12/14] modify HARBORNAMESPACE --- Jenkinsfile | 14 +++++++------- deploy/dev/devops-sample.yaml | 2 +- deploy/prod/devops-sample.yaml | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e108176e..8759bad2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { GITLAB_CREDENTIAL_ID = 'gitlab-id' KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' REDISTRY = 'harbor.devops.kubesphere.local:30280' - NAMESPACE = 'library' + HARBORNAMESPACE = 'library' GITLAB_ACCOUNT = 'admin1' APP_NAME = 'devops-sample-s2i' SONAR_CREDENTIAL_ID= 'sonar-token' @@ -54,10 +54,10 @@ pipeline { steps { container ('maven') { sh 'mvn -o -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package' - sh 'docker build -t $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' + sh 'docker build -t $REDISTRY/$HARBORNAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$HARBOR_CREDENTIAL_ID" ,)]) { sh 'echo "$DOCKER_PASSWORD" | docker login $REDISTRY -u "$DOCKER_USERNAME" --password-stdin' - sh 'docker push $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' + sh 'docker push $REDISTRY/$HARBORNAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' } } } @@ -69,8 +69,8 @@ pipeline { } steps{ container ('maven') { - sh 'docker tag $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$NAMESPACE/$APP_NAME:latest ' - sh 'docker push $REDISTRY/$NAMESPACE/$APP_NAME:latest ' + sh 'docker tag $REDISTRY/$HARBORNAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$HARBORNAMESPACE/$APP_NAME:latest ' + sh 'docker push $REDISTRY/$HARBORNAMESPACE/$APP_NAME:latest ' } } } @@ -99,8 +99,8 @@ pipeline { sh 'git tag -a $TAG_NAME -m "$TAG_NAME" ' sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@gitlab.devops.kubesphere.local:30080/$GITLAB_ACCOUNT/devops-sample-s2i.git --tags' } - sh 'docker tag $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$NAMESPACE/$APP_NAME:$TAG_NAME ' - sh 'docker push $REDISTRY/$NAMESPACE/$APP_NAME:$TAG_NAME ' + sh 'docker tag $REDISTRY/$HARBORNAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$HARBORNAMESPACE/$APP_NAME:$TAG_NAME ' + sh 'docker push $REDISTRY/$HARBORNAMESPACE/$APP_NAME:$TAG_NAME ' } } } diff --git a/deploy/dev/devops-sample.yaml b/deploy/dev/devops-sample.yaml index d2a0adcd..5599871d 100644 --- a/deploy/dev/devops-sample.yaml +++ b/deploy/dev/devops-sample.yaml @@ -28,7 +28,7 @@ spec: value: js|html - name: CACHE_PUBLIC_EXPIRATION value: 3d - image: $REDISTRY/$NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER + image: $REDISTRY/$HARBORNAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER readinessProbe: httpGet: path: / diff --git a/deploy/prod/devops-sample.yaml b/deploy/prod/devops-sample.yaml index cfae180d..32ffc0a0 100644 --- a/deploy/prod/devops-sample.yaml +++ b/deploy/prod/devops-sample.yaml @@ -33,7 +33,7 @@ spec: value: js|html - name: CACHE_PUBLIC_EXPIRATION value: 3d - image: $REDISTRY/$NAMESPACE/$APP_NAME:$TAG_NAME + image: $REDISTRY/$HARBORNAMESPACE/$APP_NAME:$TAG_NAME readinessProbe: httpGet: path: / From 7eb3aa7778415b66f4fbd5ea728c4657a0869307 Mon Sep 17 00:00:00 2001 From: soulseen Date: Fri, 12 Apr 2019 14:35:30 +0800 Subject: [PATCH 13/14] modify APP_NAME --- Jenkinsfile | 4 ++-- Jenkinsfile-online | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8759bad2..ef22fb34 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { REDISTRY = 'harbor.devops.kubesphere.local:30280' HARBORNAMESPACE = 'library' GITLAB_ACCOUNT = 'admin1' - APP_NAME = 'devops-sample-s2i' + APP_NAME = 'devops-java-sample' SONAR_CREDENTIAL_ID= 'sonar-token' } @@ -97,7 +97,7 @@ pipeline { 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@gitlab.devops.kubesphere.local:30080/$GITLAB_ACCOUNT/devops-sample-s2i.git --tags' + sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@gitlab.devops.kubesphere.local:30080/$GITLAB_ACCOUNT/devops-java-sample.git --tags' } sh 'docker tag $REDISTRY/$HARBORNAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$HARBORNAMESPACE/$APP_NAME:$TAG_NAME ' sh 'docker push $REDISTRY/$HARBORNAMESPACE/$APP_NAME:$TAG_NAME ' diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 2a160638..aa03b3d8 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -16,7 +16,7 @@ pipeline { REDISTRY = 'docker.io' DOCKERHUB_NAMESPACE = 'docker_username' GITHUB_ACCOUNT = 'kubesphere' - APP_NAME = 'devops-sample-s2i' + APP_NAME = 'devops-java-sample' SONAR_CREDENTIAL_ID= 'sonar-token' } @@ -97,7 +97,7 @@ pipeline { 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-sample-s2i.git --tags' + sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@github.com/$GITHUB_ACCOUNT/devops-java-sample.git --tags' } sh 'docker tag $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME ' sh 'docker push $REDISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME ' From a54c0d3c747937a20f0b7362237efe52ae85a857 Mon Sep 17 00:00:00 2001 From: soulseen Date: Fri, 12 Apr 2019 15:10:13 +0800 Subject: [PATCH 14/14] modify env NAMESPANCE --- Jenkinsfile | 14 +++++++------- deploy/dev/devops-sample.yaml | 2 +- deploy/prod/devops-sample.yaml | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ef22fb34..a3663fd3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { GITLAB_CREDENTIAL_ID = 'gitlab-id' KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' REDISTRY = 'harbor.devops.kubesphere.local:30280' - HARBORNAMESPACE = 'library' + HARBOR_NAMESPACE = 'library' GITLAB_ACCOUNT = 'admin1' APP_NAME = 'devops-java-sample' SONAR_CREDENTIAL_ID= 'sonar-token' @@ -54,10 +54,10 @@ pipeline { steps { container ('maven') { sh 'mvn -o -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package' - sh 'docker build -t $REDISTRY/$HARBORNAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' + sh 'docker build -t $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$HARBOR_CREDENTIAL_ID" ,)]) { sh 'echo "$DOCKER_PASSWORD" | docker login $REDISTRY -u "$DOCKER_USERNAME" --password-stdin' - sh 'docker push $REDISTRY/$HARBORNAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' + sh 'docker push $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' } } } @@ -69,8 +69,8 @@ pipeline { } steps{ container ('maven') { - sh 'docker tag $REDISTRY/$HARBORNAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$HARBORNAMESPACE/$APP_NAME:latest ' - sh 'docker push $REDISTRY/$HARBORNAMESPACE/$APP_NAME:latest ' + sh 'docker tag $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:latest ' + sh 'docker push $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:latest ' } } } @@ -99,8 +99,8 @@ pipeline { sh 'git tag -a $TAG_NAME -m "$TAG_NAME" ' sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@gitlab.devops.kubesphere.local:30080/$GITLAB_ACCOUNT/devops-java-sample.git --tags' } - sh 'docker tag $REDISTRY/$HARBORNAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$HARBORNAMESPACE/$APP_NAME:$TAG_NAME ' - sh 'docker push $REDISTRY/$HARBORNAMESPACE/$APP_NAME:$TAG_NAME ' + sh 'docker tag $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME ' + sh 'docker push $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME ' } } } diff --git a/deploy/dev/devops-sample.yaml b/deploy/dev/devops-sample.yaml index 5599871d..0a59e257 100644 --- a/deploy/dev/devops-sample.yaml +++ b/deploy/dev/devops-sample.yaml @@ -28,7 +28,7 @@ spec: value: js|html - name: CACHE_PUBLIC_EXPIRATION value: 3d - image: $REDISTRY/$HARBORNAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER + image: $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER readinessProbe: httpGet: path: / diff --git a/deploy/prod/devops-sample.yaml b/deploy/prod/devops-sample.yaml index 32ffc0a0..f0584f1f 100644 --- a/deploy/prod/devops-sample.yaml +++ b/deploy/prod/devops-sample.yaml @@ -33,7 +33,7 @@ spec: value: js|html - name: CACHE_PUBLIC_EXPIRATION value: 3d - image: $REDISTRY/$HARBORNAMESPACE/$APP_NAME:$TAG_NAME + image: $REDISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME readinessProbe: httpGet: path: /