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:(完成高可用的部署及服務的心跳健康檢查)