Jenkins/git/maven/ssh/docker案例
前言
在看这篇文章最好看一下基于Jenkins/git/maven/ssh 案例了解一下整个构建过程;
https://blog.csdn.net/qq_19239339/article/details/80829315
安装centos
建议 CentOS-7-x86_64-Everything-1611.iso
安装 docker
进入Linux系统中执行 ifconfig
SECURE CRT SSH工具 使用Root 用户登录到Linux系统
执行命令 yum -y install docker 并等待下载安装完毕;
如果出现上图所示 需要执行命令rm -f /var/run/yum.pid 再执行yum -y install docker
vi/etc//sysconfig/selinux 修改SELINUX=disabled
reboot
启动 docker服务
service docker start .
docker version配置镜像加速
vim /etc/docker/daemon.json
{
"registry-mirrors":["https://registry.docker-cn.com"]
}
service docker start下载镜像tomcat
docker pull tomcat
编写Dcokerfile(一般情况由开发在代码中)
# This my first tomcat Dockerfile
# Version 1.0
# Base images 基础镜像
FROM tomcat
#MAINTAINER 维护者信息
MAINTAINER 379753498@qq.com
#ENV 设置环境变量
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
#ADD 文件放在当前目录下,拷过去会自动解压
ADD SpringMVCmybatis.war ./webapps/SpringMVCmybatis.war
#RUN 执行以下命令
#RUN rpm -ivh /usr/local/epel-release-latest-7.noarch.rpm
#WORKDIR 相当于cd
#WORKDIR /usr/local/nginx-1.8.0
#EXPOSE 映射端口
#EXPOSE 80
#CMD 运行以下命令
#CMD ["nginx"]
编写Shell脚本
Vi /home/Jenkins.sh
#!/bin/bash
cd /home
docker build -t tomcat:spring .
rm -rf /home/SpringMVCmybatis.war
rm -rf /home/Dockerfile
docker kill spring
docker rm spring
docker ps
docker run -d --name spring -p 8080:8080tomcat:spring
修改脚本执行权限
chmod a+x /home/Jenkins.sh
jenckins设置
1、 拷贝war包
2、 拷贝dockerfile
3、 执行/home/Jenkins.sh文件
构建测试
[INFO] Building war: C:\Users\Administrator\.jenkins\workspace\software\target\SpringMVCmybatis.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.618s
[INFO] Finished at: Thu Jul 05 14:55:00 CST 2018
[INFO] Final Memory: 39M/843M
[INFO] ------------------------------------------------------------------------
SSH: Connecting from host [computername]
SSH: Connecting with configuration [linux] ...
SSH: EXEC: STDOUT/STDERR from command [cd /home
./jenkins.sh] ...
Sending build context to Docker daemon 132.4 MB
Step 1/5 : FROM tomcat
---> 2d084b11164d
Step 2/5 : MAINTAINER 379753498@qq.com
---> Running in f360e81e32cc
---> 8c0466c8651c
Removing intermediate container f360e81e32cc
Step 3/5 : ENV LANG C.UTF-8
---> Running in e31cbe8ed5ee
---> e4329c773caa
Removing intermediate container e31cbe8ed5ee
Step 4/5 : ENV LC_ALL C.UTF-8
---> Running in 3580405a980b
---> 761deb932a7f
Removing intermediate container 3580405a980b
Step 5/5 : ADD SpringMVCmybatis.war ./webapps/SpringMVCmybatis.war
---> 80912795b7c3
Removing intermediate container 4707ce5dd932
Successfully built 80912795b7c3
Error response from daemon: Cannot kill container spring: No such container: spring
Error response from daemon: No such container: spring
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b17b345adb981132a913671749c2d7480c75b98a49bc006584a0ce18b9c39566
SSH: EXEC: completed after 12,602 ms
SSH: Disconnecting configuration [linux] ...
SSH: Transferred 2 ( 1 + 1 ) file(s)
Build step 'Send files or execute commands over SSH' changed build result to SUCCESS
Finished: SUCCESS
访问Linux宿主机
http://192.168.19.132:8080/SpringMVCmybatis/register
简单做的实验 页面是之前写的demo 见谅!