Skip to content

Commit

Permalink
Merge pull request #81 from chilianyi/master
Browse files Browse the repository at this point in the history
Remove deprecated tag from ci/cicd template && Change kubernetesDeplo…
  • Loading branch information
chilianyi authored Oct 21, 2022
2 parents e2cf426 + 57342e4 commit 17666b1
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 97 deletions.
68 changes: 34 additions & 34 deletions charts/ks-devops/templates/cluster-template-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,46 @@ metadata:
annotations:
devops.kubesphere.io/displayNameEN: &defaultDisplayName "Continuous Integration (CI)"
devops.kubesphere.io/displayNameZH: "持续集成 (CI)"
devops.kubesphere.io/descriptionEN: &defaultDescription "[Deprecated] Continuous integration (CI) is the process of automatically detecting, pulling, building, and (in most cases) unit testing after source code changes."
devops.kubesphere.io/descriptionZH: "【已弃用】持续集成(CI)是在源代码变更后自动检测、拉取、构建和(在大多数情况下)进行单元测试的过程。"
devops.kubesphere.io/descriptionEN: &defaultDescription "Continuous integration (CI) is the process of automatically detecting, pulling, building, and (in most cases) unit testing after source code changes."
devops.kubesphere.io/descriptionZH: "持续集成(CI)是在源代码变更后自动检测、拉取、构建和(在大多数情况下)进行单元测试的过程。"
devops.kubesphere.io/icon: "ci-temple-en.svg"
spec:
template: |
pipeline {
agent {
node {
label 'base'
}
}
environment {
DOCKER_CREDENTIAL_ID = 'dockerhub'
KUBECONFIG_CREDENTIAL_ID = 'kubeconfig'
REGISTRY = 'docker.io'
DOCKERHUB_NAMESPACE = 'shaowenchen'
APP_NAME = 'devops-python-sample'
SONAR_CREDENTIAL_ID = 'sonar-token'
agent {
node {
label 'base'
}
parameters {
string(name: 'BRANCH_NAME', defaultValue: 'master', description: '')
}
stages {
stage('clone code') {
steps {
container('base') {
checkout([$class: 'GitSCM', branches: [[name: '*/$BRANCH_NAME']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/kubesphere/devops-python-sample.git']]])
}
}
}
environment {
DOCKER_CREDENTIAL_ID = 'dockerhub'
KUBECONFIG_CREDENTIAL_ID = 'kubeconfig'
REGISTRY = 'docker.io'
DOCKERHUB_NAMESPACE = 'shaowenchen'
APP_NAME = 'devops-python-sample'
SONAR_CREDENTIAL_ID = 'sonar-token'
}
parameters {
string(name: 'BRANCH_NAME', defaultValue: 'master', description: '')
}
stages {
stage('clone code') {
steps {
container('base') {
checkout([$class: 'GitSCM', branches: [[name: '*/$BRANCH_NAME']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/kubesphere/devops-python-sample.git']]])
}
stage('build & push') {
steps {
container('base') {
withCredentials([usernamePassword(credentialsId : "$DOCKER_CREDENTIAL_ID" ,passwordVariable: 'DOCKER_PASSWORD' ,usernameVariable: 'DOCKER_USERNAME' ,)]) {
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
sh 'docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$BUILD_NUMBER .'
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$BUILD_NUMBER'
}
}
}
}
}
stage('build & push') {
steps {
container('base') {
withCredentials([usernamePassword(credentialsId : "$DOCKER_CREDENTIAL_ID" ,passwordVariable: 'DOCKER_PASSWORD' ,usernameVariable: 'DOCKER_USERNAME' ,)]) {
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
sh 'docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$BUILD_NUMBER .'
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$BUILD_NUMBER'
}
}
}
}
}
}
138 changes: 75 additions & 63 deletions charts/ks-devops/templates/cluster-template-cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,90 @@ metadata:
annotations:
devops.kubesphere.io/displayNameEN: "Continuous Integration & Delivery (CI/CD)"
devops.kubesphere.io/displayNameZH: "持续集成&交付 (CI/CD)"
devops.kubesphere.io/descriptionEN: "[Deprecated] Continuous deployment (CD) refers to the idea of automatically providing the release version in the continuous delivery pipeline to end users. According to the user\'s installation method, automatic deployment in the cloud environment, app upgrades (such as apps on mobile phones), website updates, or only the list of available versions."
devops.kubesphere.io/descriptionZH: "【已弃用】持续部署(CD)是指能够自动提供持续交付管道中发布版本给最终用户使用的想法。根据用户的安装方式,在云环境中自动部署、app 升级(如手机上的应用程序)、更新网站或只更新可用版本列表。"
devops.kubesphere.io/descriptionEN: "Continuous deployment (CD) refers to the idea of automatically providing the release version in the continuous delivery pipeline to end users. According to the user\'s installation method, automatic deployment in the cloud environment, app upgrades (such as apps on mobile phones), website updates, or only the list of available versions."
devops.kubesphere.io/descriptionZH: "持续部署(CD)是指能够自动提供持续交付管道中发布版本给最终用户使用的想法。根据用户的安装方式,在云环境中自动部署、app 升级(如手机上的应用程序)、更新网站或只更新可用版本列表。"
devops.kubesphere.io/icon: "cicd-temple-en.svg"
spec:
template: |
pipeline {
agent {
node {
label 'maven'
}
}
parameters {
string(name:'TAG_NAME',defaultValue: '',description:'')
agent {
node {
label 'maven'
}
environment {
DOCKER_CREDENTIAL_ID = 'dockerhub-id'
GITHUB_CREDENTIAL_ID = 'github-id'
KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig'
REGISTRY = 'docker.io'
DOCKERHUB_NAMESPACE = 'docker_username'
GITHUB_ACCOUNT = 'kubesphere'
APP_NAME = 'devops-java-sample'
}
stages {
stage('clone code') {
steps {
container('maven') {
checkout([$class: 'GitSCM', branches: [[name: '*/$BRANCH_NAME']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/kubesphere/devops-python-sample.git']]])
}
}
}
stage ('unit test') {
steps {
container ('maven') {
sh 'mvn clean -o -gs `pwd`/configuration/settings.xml test'
}
}
}
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 = 'docker_username'
GITHUB_ACCOUNT = 'kubesphere'
APP_NAME = 'devops-java-sample'
}
stages {
stage('clone code') {
steps {
container('maven') {
checkout([$class: 'GitSCM', branches: [[name: '*/$BRANCH_NAME']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/kubesphere/devops-python-sample.git']]])
}
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 ('unit test') {
steps {
container ('maven') {
sh 'mvn clean -o -gs `pwd`/configuration/settings.xml test'
}
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 ('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('deploy to dev') {
steps {
input(id: 'deploy-to-dev', message: 'deploy to dev?')
kubernetesDeploy(configs: 'deploy/dev-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
}
}
}
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') {
steps {
container('maven') {
input(id: 'deploy-to-dev', message: 'deploy to dev?')
withCredentials([kubeconfigContent(credentialsId : 'KUBECONFIG_CREDENTIAL_ID' ,variable : 'KUBECONFIG_CONFIG' ,)]) {
sh 'mkdir -p ~/.kube/'
sh 'echo "$KUBECONFIG_CONFIG" > ~/.kube/config'
sh 'envsubst < deploy/dev-ol/deploy.yaml | kubectl apply -f -'
}
}
stage('deploy to production') {
steps {
input(id: 'deploy-to-production', message: 'deploy to production?')
kubernetesDeploy(configs: 'deploy/prod-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
}
}
}
stage('deploy to production') {
steps {
container('maven') {
input(id: 'deploy-to-production', message: 'deploy to production?')
withCredentials([kubeconfigContent(credentialsId : 'KUBECONFIG_CREDENTIAL_ID' ,variable : 'KUBECONFIG_CONFIG' ,)]) {
sh 'mkdir -p ~/.kube/'
sh 'echo "$KUBECONFIG_CONFIG" > ~/.kube/config'
sh 'envsubst < deploy/prod-ol/deploy.yaml | kubectl apply -f -'
}
}
}
}
}
}

0 comments on commit 17666b1

Please sign in to comment.