您好,登錄后才能下訂單哦!
上面左邊是我的個人微 信,如需進一步溝通,請加好 友。 右邊是我的公眾號“Openstack私有云”,如有興趣,請關注。
很久都想動手實踐一下所謂的CI/CD持續集成開發,主要是工作中沒有用到,另外對開發這一塊領域也不是特別熟悉,現在基礎設施自動化不就是為了為上層應用服務的嗎,開發部門也是爺啊,也需要伺候好,哈哈。
簡單介紹哦一下CI/CD的概念,字面意思就是持續集成/持續部署或交付 ,說明如下:
持續集成(Continuous Integration,CI):在持續集成環境中,開發人員會頻繁(一日多次)的提交代碼測試,在構建之前必須先通過單元測試,有一個測試用例失敗就不能集成繼續,這樣目的是快速發現問題和修復。然后代碼構建、部署、測試,再對測試結果進行反饋,不斷執行這個過程。
持續部署(Continuous Deployment,CD):持續部署是可以靈活的將項目部署到任意環境,如測試環境、預生產環境、生產環境,以便質量團隊或用戶使用,發現問題及反饋。
持續交付(Continuous Delivery,CD):將最終產品發布到生產環境,給用戶使用。
下面這張圖是通過git+docker register + Jenkins + docker 實現CI/CD的一個簡單示意圖(來自網上)。
可以看到,邏輯關系還是很簡單的,就是開發人員將開發代碼上傳到git,觸發Jenkins的自動代碼編譯并構建鏡像,將鏡像推送到docker倉庫,比如Harbor,測試環境或生產環境再從docker倉庫中拉取鏡像部署。
廢話不多少,開始規劃開干。
發布流程如下:
1.開發語言:Java
2.項目代碼版本管理:Git
3.代碼編譯:Maven
4.持續集成:Jenkins
5.交付:以Docker鏡像形式進行交付,提交至鏡像倉庫
6.部署:Docker主機創建容器
環境規劃如下:
Jenkins 192.168.1.46
Docker 192.168.1.45
Git/Registry 192.168.1.44
操作系統:CentOS7.2
鏡像名稱格式:
項目名-模塊名:代碼版本(tag)
工作流程:
1.開發人員提交代碼到Git版本倉庫;
2.Jenkins人工/定時觸發項目構建;
3.Jenkins拉取代碼、代碼編譯、打包鏡像、推送到鏡像倉庫;
4.Jenkins在Docker主機創建容器并發布
部署Git倉庫
在192.168.1.44 主機安裝Git,如下:
1.安裝Git # yum install git -y 2.創建Git用戶并設置密碼 # useradd git # echo git | passwd --stdin git 3.創建倉庫 su - git mkdir solo.git cd solo.git git --bare init 4.訪問創建的這個倉庫 # git clone git@192.168.1.44:/home/git/solo.git
上傳項目到Git倉庫
從Github上找了一個開源的JAVA博客項目作為演示。 拉取代碼 # 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環境,如下:
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.啟動并開機啟動 # systemctl start docker # systemctl enable docker 6.安裝Java和Maven環境 首先在oracle官網下載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運行pipeline的時候需要用到git: yum install git -y
安裝Jenkins
Jenkins是一個開源軟件項目,是基于Java開發的一種持續集成工具,用于代碼編譯、部署、測試等工作。
Jenkins也是一個跨平臺的,大多數主流的平臺都支持,而且安裝很簡單,我們這里以部署war包方式安裝它。
下載地址:https://jenkins.io/download
在192.168.1.46主機安裝Jenkins,下載Tomcat二進制包將war包到webapps下即可:
先安裝Java環境, # 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,或者從本機/root/.jenkins/secrets/initialAdminPassword文件獲取,點擊繼續,選擇安裝推薦的插件。
等待一會兒安裝插件完成。之后創建第一個管理用戶:
賬號密碼admin 。接下來對jenkins進行配置:
名稱:Slave節點名字
并發構建數:同一時間下發該Slave最大任務數
遠程工作目錄:Slave上的工作目錄
標簽:標記,用于識別哪一個Slave
用法:只負責Job標記到該Slave的任務
啟動方式:Linux Slave一般采用SSH連接
主機:Slave IP地址,這里是Docker主機IP
Credentials:選擇剛創建的憑據,SSH連接到該主機的用戶名和密碼
Java路徑:Slave上java絕對路徑
添加新節點之后,需要連接這個docker節點,首次連接的時候回報錯ssh_hosts沒有保存這個地址的公鑰,需要在后臺直接使用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 ~]#
之后就能正確登錄新節點,如下:
授權Docker主機免交互拉取Git倉庫
在Docker主機192.168.1.45 創建密鑰對:
# ssh-keygen # 一路回車 # ssh-copy-id git@192.168.1.44 測試免交互登錄: # ssh git@192.168.1.44
新建任務
Pipeline是一套運行于Jenkins上的工作流框架,將原來獨立運行的單個或多個任務連續起來,發布流程使用Groovy腳本書寫整個生命周期,并且支持從代碼庫直接讀取該腳本,這種理念是目前CI/CD的最佳實踐。
Jenkinsfile內容如下:
node ("192.168.1.45") { // 指定Slave標簽 // 拉取代碼 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 ''' } // 項目打包到鏡像并推送到鏡像倉庫 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 ''' // 根據$Tag作為鏡像版本號 } // 部署到Docker主機 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 上模擬提交代碼創建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]$
發布測試!!!!!!!!!!
自動化構建部署是成功了,在構建過程中可以直接看build Histroy中的console輸出,如下:
具體內容如下,以供參考:
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服務器中檢查容器是否部署成功:
[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
在我這個環境中,發現容器已經部署,但是容器運行有問題,使用docker logs 查看相關報錯如下:
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
由于是應用方面的報錯,沒有深究,后面有空再看是什么原因。
至此,這個實驗已經做完。
總結:
這個實驗做下來,對我來說主要的難點在于不熟悉版本管理工具marven以及git等開發方面的工具,只能說對CI/CD持續集成部署做了一次簡單的摸索。
使用過程中遇到任何問題,首先看報錯和日志,問題最多的地方是jenkins的pipeline腳本執行,在執行過程中,需要對腳本有一個充分的消化了解,碰到問題的時候,通過查看輸入日志來定位問題所在。
整個結構主要包括3個部分,鏡像倉庫harbor、jenkins、docker ,其中還有git倉庫和git客戶端,直接復用放在了harbor服務器上 。harbor是原來部署過的資源,jenkins是直接通過下載war包部署在tomcat上,docker與harbor之間的配置需要匹配,我的環境里面harbor配置的是http方式,需要在docker端配置insecure registry 。
CI/CD持續集成部署對于開發測試來說還是非常有用的,這個實驗是使用docker作為容器的運行環境(slave) ,另外,還可以使用kubernetes作為容器承載環境,配置會更復雜一些,但是部署完成后的使用會更加健壯和方便。這一塊后續再花時間進行實踐。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。