上面左边是我的个人微 信,如需进一步沟通,请加好 友。 右边是我的公众号“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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。