赞
踩
传统工作流程:
1.java项目开发
2.提交项目代码到(git或svn)
3.运维拉取项目代码
4.编译项目代码
5.放到服务器上,通过命令启动
6.测试
自动化部署流程:
1.开发人员提交代码到Git版本仓库;
2.git仓库上配置了一个webHook的可以触发Jenkins的构建/Jenkins人工/定时触发项目构建;
3.Jenkins拉取代码、代码编码、打包镜像、推送到镜像仓库;
4.测试机器 pull 新版本的镜像,运行测试上线。
2. Jenkins安装
~ > docker run -u root --name jenkins -d -p 8090:8080 -p 52000:50000 -v jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock --restart=always jenkinsci/blueocean
~ > docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5bed5edc1154 jenkinsci/blueocean "/sbin/tini -- /usr/…" About a minute ago Up About a minute 0.0.0.0:8090->8080/tcp, 0.0.0.0:52000->50000/tcp jenkins
# 查看宿主机存储卷
~ > docker volume inspect jenkins-data
~ > docker inspect jenkins | grep Mounts -A 20
# 查看初始密码
~ > docker exec -it jenkins bash
bash-5.1# cat /var/jenkins_home/secrets/initialAdminPassword
# 或者
~ > docker logs jenkins
# which git
git
/usr/bin/git
ip
password
BUILD_ID=dontKillMe
cd /usr/local/hello/
./start.sh hello hello.jar
# ./docker.sh
# jar包部署脚本 #!/bin/bash source /etc/profile echo '开始执行脚本' project=$2 dir=/usr/local/$1/ echo "当前jar包:$project" cd $dir echo "当前目录:$dir" pid=`ps -ef | grep $dir$project | grep -v grep | awk '{print $2}'` echo "要结束的jar的pid为:$pid" if [ -n "$pid" ] then kill -9 $pid fi # 绝对路径 jenkins有时候读不到 nohup java -jar $dir$project >/dev/null 2>log &
#!/bin/bash
echo '开始执行脚本'
# mv hello.jar ../backup/hello.jar.`date +%Y%m%d`
echo '删除正在运行的hello服务'
docker container rm -f hello
echo '删除hello镜像'
docker image rm test/hello
# mv hello.jar admin.jar
echo '构建当前目录下的dockerfile文件'
docker build -t test/hello .
echo '#运行镜像构建容器'
docker run --name=hello -p 9890:9890 -itd -v /usr/local/hello/logs:/usr/local/logs test/hello
Dockerfile
FROM java:8
WORKDIR /usr/local/hello
ADD hello.jar hello.jar
EXPOSE 8090
ENTRYPOINT java -jar hello.jar
hello > curl http://127.0.0.1:9890/test
hello world
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。