您好,登錄后才能下訂單哦!
上面左邊是我的個(gè)人微 信,如需進(jìn)一步溝通,請(qǐng)加好 友。 右邊是我的公眾號(hào)“Openstack私有云”,如有興趣,請(qǐng)關(guān)注。
很久都想動(dòng)手實(shí)踐一下所謂的CI/CD持續(xù)集成開發(fā),主要是工作中沒有用到,另外對(duì)開發(fā)這一塊領(lǐng)域也不是特別熟悉,現(xiàn)在基礎(chǔ)設(shè)施自動(dòng)化不就是為了為上層應(yīng)用服務(wù)的嗎,開發(fā)部門也是爺啊,也需要伺候好,哈哈。
簡單介紹哦一下CI/CD的概念,字面意思就是持續(xù)集成/持續(xù)部署或交付 ,說明如下:
持續(xù)集成(Continuous Integration,CI):在持續(xù)集成環(huán)境中,開發(fā)人員會(huì)頻繁(一日多次)的提交代碼測(cè)試,在構(gòu)建之前必須先通過單元測(cè)試,有一個(gè)測(cè)試用例失敗就不能集成繼續(xù),這樣目的是快速發(fā)現(xiàn)問題和修復(fù)。然后代碼構(gòu)建、部署、測(cè)試,再對(duì)測(cè)試結(jié)果進(jìn)行反饋,不斷執(zhí)行這個(gè)過程。
持續(xù)部署(Continuous Deployment,CD):持續(xù)部署是可以靈活的將項(xiàng)目部署到任意環(huán)境,如測(cè)試環(huán)境、預(yù)生產(chǎn)環(huán)境、生產(chǎn)環(huán)境,以便質(zhì)量團(tuán)隊(duì)或用戶使用,發(fā)現(xiàn)問題及反饋。
持續(xù)交付(Continuous Delivery,CD):將最終產(chǎn)品發(fā)布到生產(chǎn)環(huán)境,給用戶使用。
下面這張圖是通過git+docker register + Jenkins + docker 實(shí)現(xiàn)CI/CD的一個(gè)簡單示意圖(來自網(wǎng)上)。
可以看到,邏輯關(guān)系還是很簡單的,就是開發(fā)人員將開發(fā)代碼上傳到git,觸發(fā)Jenkins的自動(dòng)代碼編譯并構(gòu)建鏡像,將鏡像推送到docker倉庫,比如Harbor,測(cè)試環(huán)境或生產(chǎn)環(huán)境再從docker倉庫中拉取鏡像部署。
廢話不多少,開始規(guī)劃開干。
發(fā)布流程如下:
1.開發(fā)語言:Java
2.項(xiàng)目代碼版本管理:Git
3.代碼編譯:Maven
4.持續(xù)集成:Jenkins
5.交付:以Docker鏡像形式進(jìn)行交付,提交至鏡像倉庫
6.部署:Docker主機(jī)創(chuàng)建容器
環(huán)境規(guī)劃如下:
Jenkins 192.168.1.46
Docker 192.168.1.45
Git/Registry 192.168.1.44
操作系統(tǒng):CentOS7.2
鏡像名稱格式:
項(xiàng)目名-模塊名:代碼版本(tag)
工作流程:
1.開發(fā)人員提交代碼到Git版本倉庫;
2.Jenkins人工/定時(shí)觸發(fā)項(xiàng)目構(gòu)建;
3.Jenkins拉取代碼、代碼編譯、打包鏡像、推送到鏡像倉庫;
4.Jenkins在Docker主機(jī)創(chuàng)建容器并發(fā)布
部署Git倉庫
在192.168.1.44 主機(jī)安裝Git,如下:
1.安裝Git # yum install git -y 2.創(chuàng)建Git用戶并設(shè)置密碼 # useradd git # echo git | passwd --stdin git 3.創(chuàng)建倉庫 su - git mkdir solo.git cd solo.git git --bare init 4.訪問創(chuàng)建的這個(gè)倉庫 # git clone git@192.168.1.44:/home/git/solo.git
上傳項(xiàng)目到Git倉庫
從Github上找了一個(gè)開源的JAVA博客項(xiàng)目作為演示。 拉取代碼 # git clone https://github.com/b3log/solo.git 添加私有倉庫地址 # cd solo/ # git remote remove origin # git remote add origin git@192.168.1.44:/home/git/solo.git 提交到私有倉庫 # git add . # git commit -m "all" # git push origin master
在192.168.1.45 安裝Docker與配置Java環(huán)境,如下:
1.安裝依賴包 # yum install -y yum-utils device-mapper-persistent-data lvm2 2.添加Docker軟件包源: # yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo 3.安裝Docker CE # yum install docker-ce -y 4.配置加速器 # curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://bc437cce.m.daocloud.io 5.啟動(dòng)并開機(jī)啟動(dòng) # systemctl start docker # systemctl enable docker 6.安裝Java和Maven環(huán)境 首先在oracle官網(wǎng)下載jdk安裝包jdk-8u192-linux-x64.tar.gz # tar zxf jdk-8u192-linux-x64.tar.gz # mv jdk1.8.0_192 /usr/local/jdk1.8 # wget https://archive.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz # tar zxf apache-maven-3.5.4-bin.tar.gz # mv apache-maven-3.5.4 /usr/local/maven3.5 # vi /etc/profile MAVEN_HOME=/usr/local/maven3.5 JAVA_HOME=/usr/local/jdk1.8 PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME PATH CLASSPATH # source /etc/profile 7.安裝git,需要在jenkins運(yùn)行pipeline的時(shí)候需要用到git: yum install git -y
安裝Jenkins
Jenkins是一個(gè)開源軟件項(xiàng)目,是基于Java開發(fā)的一種持續(xù)集成工具,用于代碼編譯、部署、測(cè)試等工作。
Jenkins也是一個(gè)跨平臺(tái)的,大多數(shù)主流的平臺(tái)都支持,而且安裝很簡單,我們這里以部署war包方式安裝它。
下載地址:https://jenkins.io/download
在192.168.1.46主機(jī)安裝Jenkins,下載Tomcat二進(jìn)制包將war包到webapps下即可:
先安裝Java環(huán)境, # tar zxf jdk-8u192-linux-x64.tar.gz # mv jdk1.8.0_192 /usr/local/jdk1.8 # vi /etc/profile JAVA_HOME=/usr/local/jdk1.8 PATH=$PATH:$JAVA_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME PATH CLASSPATH # source /etc/profile # wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war # wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz # tar zxf apache-tomcat-8.5.37.tar.gz # mv apache-tomcat-8.5.37 /usr/local/tomcat-jenkins # rm /usr/local/tomcat-jenkins/webapps/* -rf # unzip jenkins.war -d /usr/local/tomcat-jenkins/webapps/ROOT # cd /usr/local/tomcat-jenkins/bin/ # ./startup.sh # tail -f ../logs/catalina.out ... Jenkins initial setup is required. An admin user has been created and a password generated. Please use the following password to proceed to installation: a832e00bc8c3484698f74862a3a2459a This may also be found at: /root/.jenkins/secrets/initialAdminPassword ...
部署成功,訪問Jenkins:http://192.168.1.46:8080
注意在防火墻上將8080端口打開:
firewall-cmd --add-port=8080/tcp
firewall-cmd --add-port=8080/tcp --permanent
輸入上面日志輸出的密碼:a832e00bc8c3484698f74862a3a2459a,或者從本機(jī)/root/.jenkins/secrets/initialAdminPassword文件獲取,點(diǎn)擊繼續(xù),選擇安裝推薦的插件。
等待一會(huì)兒安裝插件完成。之后創(chuàng)建第一個(gè)管理用戶:
賬號(hào)密碼admin 。接下來對(duì)jenkins進(jìn)行配置:
名稱:Slave節(jié)點(diǎn)名字
并發(fā)構(gòu)建數(shù):同一時(shí)間下發(fā)該Slave最大任務(wù)數(shù)
遠(yuǎn)程工作目錄:Slave上的工作目錄
標(biāo)簽:標(biāo)記,用于識(shí)別哪一個(gè)Slave
用法:只負(fù)責(zé)Job標(biāo)記到該Slave的任務(wù)
啟動(dòng)方式:Linux Slave一般采用SSH連接
主機(jī):Slave IP地址,這里是Docker主機(jī)IP
Credentials:選擇剛創(chuàng)建的憑據(jù),SSH連接到該主機(jī)的用戶名和密碼
Java路徑:Slave上java絕對(duì)路徑
添加新節(jié)點(diǎn)之后,需要連接這個(gè)docker節(jié)點(diǎn),首次連接的時(shí)候回報(bào)錯(cuò)ssh_hosts沒有保存這個(gè)地址的公鑰,需要在后臺(tái)直接使用ssh登錄一下192.168.1.45 ,如下:
[root@jenkins secrets]# ssh 192.168.1.45 The authenticity of host '192.168.1.45 (192.168.1.45)' can't be established. ECDSA key fingerprint is 64:b6:7a:b9:9d:65:e2:57:3f:61:d8:dc:6c:cc:6a:78. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.1.45' (ECDSA) to the list of known hosts. root@192.168.1.45's password: Last login: Sat Feb 2 17:34:39 2019 from 192.168.1.22 [root@docker ~]#
之后就能正確登錄新節(jié)點(diǎn),如下:
授權(quán)Docker主機(jī)免交互拉取Git倉庫
在Docker主機(jī)192.168.1.45 創(chuàng)建密鑰對(duì):
# ssh-keygen # 一路回車 # ssh-copy-id git@192.168.1.44 測(cè)試免交互登錄: # ssh git@192.168.1.44
新建任務(wù)
Pipeline是一套運(yùn)行于Jenkins上的工作流框架,將原來獨(dú)立運(yùn)行的單個(gè)或多個(gè)任務(wù)連續(xù)起來,發(fā)布流程使用Groovy腳本書寫整個(gè)生命周期,并且支持從代碼庫直接讀取該腳本,這種理念是目前CI/CD的最佳實(shí)踐。
Jenkinsfile內(nèi)容如下:
node ("192.168.1.45") { // 指定Slave標(biāo)簽 // 拉取代碼 stage('Git Checkout') { checkout([$class: 'GitSCM', branches: [[name: '$Tag']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'git@192.168.1.44:/home/git/solo.git']]]) } // $Tag引用用戶交互輸入的tag // 代碼編譯 stage('Maven Build') { sh ''' export JAVA_HOME=/usr/local/jdk1.8 /usr/local/maven3.5/bin/mvn clean package -Dmaven.test.skip=true ''' } // 項(xiàng)目打包到鏡像并推送到鏡像倉庫 stage('Build and Push Image') { sh ''' REPOSITORY=192.168.1.44/library/solo:${Tag} cat >> Dockerfile << EOF FROM 192.168.1.44/library/tomcat:latest RUN rm -rf /usr/local/tomcat/webapps/ROOT COPY target/*.war /usr/local/tomcat/webapps/ROOT.war CMD ["catalina.sh", "run"] EOF docker build -t $REPOSITORY . docker login -u ywb -p yourpassword 192.168.1.44 docker push $REPOSITORY ''' // 根據(jù)$Tag作為鏡像版本號(hào) } // 部署到Docker主機(jī) stage('Deploy to Docker') { sh ''' REPOSITORY=192.168.1.44/library/solo:${Tag} docker rm -f blog-solo |true docker image rm $REPOSITORY |true docker login -u ywb -p yourpassword 192.168.1.44 docker container run -d --name blog-solo -v /usr/local/jdk1.8:/usr/local/jdk -p 88:8080 $REPOSITORY ''' } }
在192.168.1.44 上模擬提交代碼創(chuàng)建tag:
[git@harbor solo]$ cd solo [git@harbor solo]$ touch src/main/webapp/123.txt [git@harbor solo]$ git add . [git@harbor solo]$ git commit -m "1" [master fca1bcb] 1 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/webapp/123.txt [git@harbor solo]$ git tag 1.0.0 [git@harbor solo]$ git push origin 1.0.0 git@192.168.1.44's password: Counting objects: 10, done. Delta compression using up to 2 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (6/6), 438 bytes | 0 bytes/s, done. Total 6 (delta 3), reused 1 (delta 0) To git@192.168.1.44:/home/git/solo.git * [new tag] 1.0.0 -> 1.0.0 [git@harbor solo]$
發(fā)布測(cè)試?。。。。。。。。?!
自動(dòng)化構(gòu)建部署是成功了,在構(gòu)建過程中可以直接看build Histroy中的console輸出,如下:
具體內(nèi)容如下,以供參考:
Started by user administrator Running in Durability level: MAX_SURVIVABILITY [Pipeline] Start of Pipeline [Pipeline] node Running on docker in /var/jenkins_home/workspace/blog-solo [Pipeline] { [Pipeline] stage [Pipeline] { (Git Checkout) [Pipeline] checkout No credentials specified Fetching changes from the remote Git repository Checking out Revision fca1bcbd6c4b3fe99625c68ae11d1166d06af556 (1.0.0) Commit message: "1" First time build. Skipping changelog. [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Maven Build) [Pipeline] sh > git rev-parse --is-inside-work-tree # timeout=10 > git config remote.origin.url git@192.168.1.44:/home/git/solo.git # timeout=10 Fetching upstream changes from git@192.168.1.44:/home/git/solo.git > git --version # timeout=10 > git fetch --tags --progress git@192.168.1.44:/home/git/solo.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git rev-parse origin/1.0.0^{commit} # timeout=10 > git rev-parse 1.0.0^{commit} # timeout=10 > git config core.sparsecheckout # timeout=10 > git checkout -f fca1bcbd6c4b3fe99625c68ae11d1166d06af556 # timeout=10 + export JAVA_HOME=/usr/local/jdk1.8 + JAVA_HOME=/usr/local/jdk1.8 + /usr/local/maven3.5/bin/mvn clean package -Dmaven.test.skip=true [INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for org.b3log:solo:war:2.9.9 [WARNING] 'dependencies.dependency.systemPath' for org.patchca:patchca:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/lib/net/pusuo/patchca-0.5.0.jar will be unresolvable by dependent projects @ line 245, column 25 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. [WARNING] [INFO] [INFO] ---------------------------< org.b3log:solo >--------------------------- [INFO] Building Solo 2.9.9 [INFO] --------------------------------[ war ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ solo --- [INFO] Deleting /var/jenkins_home/workspace/blog-solo/target [INFO] [INFO] --- jacoco-maven-plugin:0.8.2:prepare-agent (prepare-agent) @ solo --- [INFO] argLine set to -javaagent:/root/.m2/repository/org/jacoco/org.jacoco.agent/0.8.2/org.jacoco.agent-0.8.2-runtime.jar=destfile=/var/jenkins_home/workspace/blog-solo/target/jacoco.exec [INFO] [INFO] --- license-maven-plugin:3.0:format (default) @ solo --- [INFO] Updating license headers... [WARNING] Unknown file extension: /var/jenkins_home/workspace/blog-solo/src/main/resources/docker/local.properties.h3 [WARNING] Unknown file extension: /var/jenkins_home/workspace/blog-solo/src/main/resources/docker/local.properties.mysql [INFO] Updating license header in: /var/jenkins_home/workspace/blog-solo/src/main/webapp/css/default-admin.min.css [INFO] Updating license header in: /var/jenkins_home/workspace/blog-solo/src/main/webapp/css/default-base.min.css [INFO] Updating license header in: /var/jenkins_home/workspace/blog-solo/src/main/webapp/css/default-init.min.css [INFO] Updating license header in: /var/jenkins_home/workspace/blog-solo/src/main/webapp/js/admin/latkeAdmin.min.js [INFO] Updating license header in: /var/jenkins_home/workspace/blog-solo/src/main/webapp/js/common.min.js [INFO] Updating license header in: /var/jenkins_home/workspace/blog-solo/src/main/webapp/js/page.min.js [WARNING] Unknown file extension: /var/jenkins_home/workspace/blog-solo/src/test/resources/skins/Jane/css/_icon.scss [WARNING] Unknown file extension: /var/jenkins_home/workspace/blog-solo/src/test/resources/skins/Jane/css/base.scss [WARNING] Unknown file extension: /var/jenkins_home/workspace/blog-solo/src/test/resources/markdown_syntax.text [WARNING] Unable to find a comment style definition for some files. You may want to add a custom mapping for the relevant file extensions. [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ solo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 9 resources [INFO] [INFO] --- maven-min-plugin:1.0.4:min (default) @ solo --- [INFO] Merged [ src/main/webapp/js/admin/admin.js, src/main/webapp/js/admin/editor.js, src/main/webapp/js/admin/editorTinyMCE.js, src/main/webapp/js/admin/editorKindEditor.js, src/main/webapp/js/admin/editorCodeMirror.js, src/main/webapp/js/admin/tablePaginate.js, src/main/webapp/js/admin/article.js, src/main/webapp/js/admin/comment.js, src/main/webapp/js/admin/articleList.js, src/main/webapp/js/admin/draftList.js, src/main/webapp/js/admin/pageList.js, src/main/webapp/js/admin/others.js, src/main/webapp/js/admin/linkList.js, src/main/webapp/js/admin/preference.js, src/main/webapp/js/admin/pluginList.js, src/main/webapp/js/admin/userList.js, src/main/webapp/js/admin/categoryList.js, src/main/webapp/js/admin/commentList.js, src/main/webapp/js/admin/plugin.js, src/main/webapp/js/admin/main.js, src/main/webapp/js/admin/about.js ], [21] files [INFO] Minimizing [srcPath=src/main/webapp/js/admin/latkeAdmin.js, targetPath=src/main/webapp/js/admin/latkeAdmin.min.js] [INFO] Minimizing [srcPath=src/main/webapp/css/default-admin.css, targetPath=src/main/webapp/css/default-admin.min.css] [INFO] Minimizing [srcPath=src/main/webapp/css/default-base.css, targetPath=src/main/webapp/css/default-base.min.css] [INFO] Minimizing [srcPath=src/main/webapp/css/default-init.css, targetPath=src/main/webapp/css/default-init.min.css] [INFO] Minimizing [srcPath=src/main/webapp/js/common.js, targetPath=src/main/webapp/js/common.min.js] [INFO] Minimizing [srcPath=src/main/webapp/js/page.js, targetPath=src/main/webapp/js/page.min.js] [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ solo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 141 source files to /var/jenkins_home/workspace/blog-solo/target/classes [WARNING] /var/jenkins_home/workspace/blog-solo/src/main/java/org/b3log/solo/util/Markdowns.java: /var/jenkins_home/workspace/blog-solo/src/main/java/org/b3log/solo/util/Markdowns.java uses or overrides a deprecated API. [WARNING] /var/jenkins_home/workspace/blog-solo/src/main/java/org/b3log/solo/util/Markdowns.java: Recompile with -Xlint:deprecation for details. [WARNING] /var/jenkins_home/workspace/blog-solo/src/main/java/org/b3log/solo/processor/CategoryProcessor.java: Some input files use unchecked or unsafe operations. [WARNING] /var/jenkins_home/workspace/blog-solo/src/main/java/org/b3log/solo/processor/CategoryProcessor.java: Recompile with -Xlint:unchecked for details. [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ solo --- [INFO] Not copying test resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ solo --- [INFO] Not compiling test sources [INFO] [INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ solo --- [INFO] Tests are skipped. [INFO] [INFO] --- maven-war-plugin:3.2.2:war (default-war) @ solo --- [INFO] Packaging webapp [INFO] Assembling webapp [solo] in [/var/jenkins_home/workspace/blog-solo/target/solo] [INFO] Processing war project [INFO] Copying webapp webResources [/var/jenkins_home/workspace/blog-solo/src/main/resources/lib/net/pusuo] to [/var/jenkins_home/workspace/blog-solo/target/solo] [INFO] Copying webapp resources [/var/jenkins_home/workspace/blog-solo/src/main/webapp] [INFO] Webapp assembled in [1661 msecs] [INFO] Building war: /var/jenkins_home/workspace/blog-solo/target/solo.war [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 22.847 s [INFO] Finished at: 2019-02-12T14:57:51+08:00 [INFO] ------------------------------------------------------------------------ [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Build and Push Image) [Pipeline] sh + REPOSITORY=192.168.1.44/library/solo:1.0.0 + cat + docker build -t 192.168.1.44/library/solo:1.0.0 . Sending build context to Docker daemon 193.1MB Step 1/4 : FROM 192.168.1.44/library/tomcat:latest ---> 7ee26c09afb3 Step 2/4 : RUN rm -rf /usr/local/tomcat/webapps/ROOT ---> Using cache ---> 6fd3776d336d Step 3/4 : COPY target/*.war /usr/local/tomcat/webapps/ROOT.war ---> 681b8e7f75a3 Step 4/4 : CMD ["catalina.sh", "run"] ---> Running in 022995c66416 Removing intermediate container 022995c66416 ---> 77f8ed952a88 Successfully built 77f8ed952a88 Successfully tagged 192.168.1.44/library/solo:1.0.0 + docker login -u ywb -p Y4yhl9t,./ 192.168.1.44 WARNING! Using --password via the CLI is insecure. Use --password-stdin. WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded + docker push 192.168.1.44/library/solo:1.0.0 The push refers to repository [192.168.1.44/library/solo] e64f746232b6: Preparing 2ff6a1cc612d: Preparing 32386b730743: Preparing d27bd82364ad: Preparing b17b783848f6: Preparing c3041009a55f: Preparing 362dc50d53f9: Preparing b20924a475a9: Preparing c258ca0f6e4f: Preparing 0f640c03c372: Preparing 76dfa41f0a1d: Preparing c240c542ed55: Preparing badfbcebf7f8: Preparing c3041009a55f: Waiting 362dc50d53f9: Waiting b20924a475a9: Waiting c258ca0f6e4f: Waiting 0f640c03c372: Waiting 76dfa41f0a1d: Waiting c240c542ed55: Waiting badfbcebf7f8: Waiting 32386b730743: Pushed 2ff6a1cc612d: Pushed e64f746232b6: Pushed b17b783848f6: Pushed c3041009a55f: Pushed b20924a475a9: Pushed c258ca0f6e4f: Pushed 0f640c03c372: Pushed 76dfa41f0a1d: Pushed d27bd82364ad: Pushed c240c542ed55: Pushed badfbcebf7f8: Pushed 362dc50d53f9: Pushed 1.0.0: digest: sha256:f3a46b4b409aa404ee621dab89152fc9d8986a9cf367324c96cfdeb52a0b4669 size: 3045 [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Deploy to Docker) [Pipeline] sh + REPOSITORY=192.168.1.44/library/solo:1.0.0 + docker rm -f blog-solo + true Error: No such container: blog-solo + docker image rm 192.168.1.44/library/solo:1.0.0 + true + docker login -u ywb -p Y4yhl9t,./ 192.168.1.44 WARNING! Using --password via the CLI is insecure. Use --password-stdin. WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded + docker container run -d --name blog-solo -v /usr/local/jdk1.8:/usr/local/jdk -p 88:8080 192.168.1.44/library/solo:1.0.0 Unable to find image '192.168.1.44/library/solo:1.0.0' locally 1.0.0: Pulling from library/solo ab1fc7e4bf91: Already exists 35fba333ff52: Already exists f0cb1fa13079: Already exists 3d79c18d1bc0: Already exists ff1d0ae4641b: Already exists 8883e662573f: Already exists adab760d76bd: Already exists 86323b680e93: Already exists 14a2c1cdce1c: Already exists ee59bf8c5470: Already exists 067f988306af: Already exists 9bb416c07ed0: Already exists 71085ba70bfc: Pulling fs layer 71085ba70bfc: Verifying Checksum 71085ba70bfc: Download complete 71085ba70bfc: Pull complete Digest: sha256:f3a46b4b409aa404ee621dab89152fc9d8986a9cf367324c96cfdeb52a0b4669 Status: Downloaded newer image for 192.168.1.44/library/solo:1.0.0 9ed4af7df3f808f150e0d5967890a0acfb98eb19958b4cec5499bfc1e0d90de5 [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS
最后到192.168.1.45的docker服務(wù)器中檢查容器是否部署成功:
[root@docker solo]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6e7bee278c4c 192.168.1.44/library/solo:v2.0 "catalina.sh run" 6 minutes ago Up 5 seconds 0.0.0.0:88->8080/tcp blog-solo
在我這個(gè)環(huán)境中,發(fā)現(xiàn)容器已經(jīng)部署,但是容器運(yùn)行有問題,使用docker logs 查看相關(guān)報(bào)錯(cuò)如下:
12-Feb-2019 07:45:45.148 WARNING [localhost-startStop-1] org.apache.catalina.startup.SetContextPropertiesRule.begin [SetContextPropertiesRule]{Context} Setting property 'antiJARLocking' to 'true' did not find a matching property. 12-Feb-2019 07:45:49.546 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. [WARN ]-[2019-02-12 07:45:49]-[org.b3log.latke.Latkes:611]: !!!!Runtime mode is [DEVELOPMENT], please make sure configured it with [PRODUCTION] in latke.properties if deployed on production environment!!!! [ERROR]-[2019-02-12 07:45:51]-[org.b3log.latke.Latkes:836]: Read skin [Jane]'s configuration failed: null [ERROR]-[2019-02-12 07:45:51]-[org.b3log.solo.SoloServletListener:302]: Can't load the default skins, please make sure skin [Jane] is under skins directory and structure correctly
由于是應(yīng)用方面的報(bào)錯(cuò),沒有深究,后面有空再看是什么原因。
至此,這個(gè)實(shí)驗(yàn)已經(jīng)做完。
總結(jié):
這個(gè)實(shí)驗(yàn)做下來,對(duì)我來說主要的難點(diǎn)在于不熟悉版本管理工具marven以及git等開發(fā)方面的工具,只能說對(duì)CI/CD持續(xù)集成部署做了一次簡單的摸索。
使用過程中遇到任何問題,首先看報(bào)錯(cuò)和日志,問題最多的地方是jenkins的pipeline腳本執(zhí)行,在執(zhí)行過程中,需要對(duì)腳本有一個(gè)充分的消化了解,碰到問題的時(shí)候,通過查看輸入日志來定位問題所在。
整個(gè)結(jié)構(gòu)主要包括3個(gè)部分,鏡像倉庫harbor、jenkins、docker ,其中還有g(shù)it倉庫和git客戶端,直接復(fù)用放在了harbor服務(wù)器上 。harbor是原來部署過的資源,jenkins是直接通過下載war包部署在tomcat上,docker與harbor之間的配置需要匹配,我的環(huán)境里面harbor配置的是http方式,需要在docker端配置insecure registry 。
CI/CD持續(xù)集成部署對(duì)于開發(fā)測(cè)試來說還是非常有用的,這個(gè)實(shí)驗(yàn)是使用docker作為容器的運(yùn)行環(huán)境(slave) ,另外,還可以使用kubernetes作為容器承載環(huán)境,配置會(huì)更復(fù)雜一些,但是部署完成后的使用會(huì)更加健壯和方便。這一塊后續(xù)再花時(shí)間進(jìn)行實(shí)踐。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。