jenkins+rancher+docker部署服务。cicd思想实践
1. 首先打开jenkins,在对应的项目下建立item. (隐私需要,只截取了关键部分)
设置自己的项目名称,我这里设置了test. 属于流水线作业。
2. 点开项目。开始配置。
对此项目进行描述
properties中指定运行的环境,我这个是开发环境。
设置流水线的作业。 那么就要给他jenkinsfile文件。我这里是svn进行的版本管理,直接指定jenkinsfile所在的svn路径和账号权限
3. jenkinsfile内容
我们可以看到,jenkinsfile描述了一个一个的stage。就是通过这种流水线式的stage完成项目的部署。
node ("${env.NODE_DEFINED}") { timestamps { stage('clean'){ cleanWs() } stage('Checkout source_code'){ checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: "${CREDENTIAL_ID}", depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'https://svn.fzyun.io/wise/project/aiplatform']], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']]) } stage('code compile jar'){ sh ''' apt-get update && apt-get install maven -y mvn clean package ''' } stage('Checkout deployment1'){ checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: "${CREDENTIAL_ID}", depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'https://svn.fzyun.io/wise/project/aiplatform/deployment']], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']]) } stage('build aiplatform-jar image'){ sh ''' docker build -t ${HUB}/founder/aiplatform_middle:002 . docker push ${HUB}/founder/aiplatform_middle:002 ''' } withEnv(["DOCKER_TAG=1.0.0.${env.BUILD_NUMBER}"]) { stage('prepare'){ sh ''' sed -i 's/mirrors.fzyun.io/mirrors.aliyun.com/g ' /etc/apt/sources.list apt-get update -y apt-get install wget -y wget --ftp-user=xxx--ftp-password=xxxxxxx -r -l 0 ftp://ftp3.dc2.fzyun.io/wise/dh_test/* ''' } stage('build aiplatform image'){ sh ''' cd ftp3.dc2.fzyun.io/wise/dh_test docker build -t ${HUB}/founder/aiplatform:${DOCKER_TAG} . docker push ${HUB}/founder/aiplatform:${DOCKER_TAG} ''' } stage('Checkout deployment2'){ checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: "${CREDENTIAL_ID}", depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'https://svn.fzyun.io/wise/project/aiplatform/deployment']], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']]) } stage('deploy'){ sh ''' founder-compose up -s aiplatform -d --force-recreate ''' } } } }
4. 之后我们就可以直接进行build了。
5. 结果:
其中涉及到docker和ranche.
dockerfile: (这个是先通过此步骤打包成jar)
ftp/dockerfile:(此dockerfile是需要上传到ftp,同时dict也需要上传,然后在jenkinsfile中完成ftp文件的拉取)
docker-compose.yml: (完成服务的部署)
rancher-compose.yml:(完成高可用的部署及服务的心跳健康检查)