Git+Jenkins+Docker实现web项目的自动部署
2017-02-06 11:01
1086 查看
实验中使用的Git平台:
GitOsc
实验目的:
向GitOsc上传新代码后,自动通过Maven打包,然后构建相应的Tomcat镜像,并启动容器
一、准备GitOsc:
1.准备项目文件
2.准备GitOsc
注:
提示输入用户名和密码的时候,用户名使用完整的邮箱名
3.上传原始文件
git add *
git commit -m "AddFile"
git push origin master
二、配置Jenkins:
三、在GitOsc上配置PUSH钩子:
http://ghx:63919fc15e0b82c9b8c3ac47af8dabbd@180.172.232.87:9999/job/test-hello/build?token=test-token
//必须使用Jenkins的公网IP,注意映射9999端口和50000端口
四、修改hello项目的源代码,并push到GitOsc上:
1.修改源代码
2.上传新文件
git add *
git commit -m "Add newfile"
git push
效果:
附shell脚本:
脚本作用:
1.设置一个临时文件,记录该任务执行次数,用于做Tag
2.构建顺序:
使用源代码构建maven镜像,同时制作成war包->从maven容器中导出war包->构建新的tomcat镜像->push到私有仓库
3.删除原来的tomcat容器,并通过最新的tomcat镜像运行一个新的tomcat容器
4.依次删除不必要的容器&镜像:
删除旧的tomcat镜像->删除刚创建的maven容器->删除刚构建的maven镜像
5.最后向临时文件中传入累计数,供下次任务使用
GitOsc
实验目的:
向GitOsc上传新代码后,自动通过Maven打包,然后构建相应的Tomcat镜像,并启动容器
一、准备GitOsc:
1.准备项目文件
2.准备GitOsc
注:
提示输入用户名和密码的时候,用户名使用完整的邮箱名
3.上传原始文件
git add *
git commit -m "AddFile"
git push origin master
二、配置Jenkins:
三、在GitOsc上配置PUSH钩子:
http://ghx:63919fc15e0b82c9b8c3ac47af8dabbd@180.172.232.87:9999/job/test-hello/build?token=test-token
//必须使用Jenkins的公网IP,注意映射9999端口和50000端口
四、修改hello项目的源代码,并push到GitOsc上:
1.修改源代码
2.上传新文件
git add *
git commit -m "Add newfile"
git push
效果:
附shell脚本:
Registry_URL=192.168.1.200:5000 tmpfile=/root/tempfile if [ -e $tmpfile ] ; then sum=`cat $tmpfile` i=`expr $sum + 1` else sum=0 i=`expr $sum + 1` fi docker build -tmaven-hello:test $WORKSPACE/hello-maven docker create --namemaven-hello maven-hello:test docker cpmaven-hello:/hello/target/hello.war $WORKSPACE/hello-tomcat docker build -t$Registry_URL/tomcat-hello:test${i} $WORKSPACE/hello-tomcat docker push$Registry_URL/tomcat-hello:test${i} if docker ps -a |grep -itomcat-hello ; then docker rm -f tomcat-hello fi docker run -d -p 8888:8080--name tomcat-hello $Registry_URL/tomcat-hello:test${i} if docker images$Registry_URL/tomcat-hello | grep test${sum} ; then docker rmi -f$Registry_URL/tomcat-hello:test${sum} fi if docker ps -a |grep -imaven-hello ; then docker rm -f maven-hello fi if docker images maven-hello |grep test ; then docker rmi -f maven-hello:test fi echo $i >$tmpfile
脚本作用:
1.设置一个临时文件,记录该任务执行次数,用于做Tag
2.构建顺序:
使用源代码构建maven镜像,同时制作成war包->从maven容器中导出war包->构建新的tomcat镜像->push到私有仓库
3.删除原来的tomcat容器,并通过最新的tomcat镜像运行一个新的tomcat容器
4.依次删除不必要的容器&镜像:
删除旧的tomcat镜像->删除刚创建的maven容器->删除刚构建的maven镜像
5.最后向临时文件中传入累计数,供下次任务使用
相关文章推荐
- jenkins+maven+git+tomcat实现web项目的自动化部署
- Jenkins-Docker-SpringBoot-java-git-gradle-持续集成与自动部署-实现跨服务器部署
- 打造jenkins+docker+nodejs项目的自动部署环境(webhook)
- Php+WebHook实现项目自动部署 - 关于Git自动部署方案
- jenkins+maven+git+tomcat实现web项目的自动化部署
- git码云配置web hook钩子实现自动部署,git权限等问题,LAMP
- 使用 Git Hooks 实现自动项目部署
- 自动化发布项目之jenkins + git + maven 自动化部署一个web项目
- 基于Jenkins 实现php项目的自动化测试、自动打包和自动部署
- Jenkins进阶-Gitlab使用Webhook实现Push代码自动部署(3)
- jenkins+docker+nodejs项目的自动部署环境(案例)
- jenkins实现项目自动部署
- 基于Jenkins 实现php项目的自动化测试、自动打包和自动部署(-)
- 基于Jenkins 实现php项目的自动化测试、自动打包和自动部署
- Jenkins+git+webhook自动触发部署和测试任务
- 利用WebHook实现PHP自动部署Git代码
- 基于Jenkins 实现php项目的自动化测试、自动打包和自动部署
- (git)Bitbucket使用WebHook实现自动部署PHP代码
- 利用WebHook实现PHP自动部署Git代码
- 基于Jenkins 实现php项目的自动化测试、自动打包和自动部署