Docker 结合Jenkins 构建持续集成环境

Docker 结合Jenkins  构建持续集成环境

Jenkins : 一个开源的持续集成工具, 提供软件版本发布、自动测试等一系列流程及丰富的插件

Maven: 一个自动化构建工具, 通过一段描述来管理项目的构建, 比如编译、打包等逻辑流程

SVN/Git: 源代码版本管理工具

Docker: 容器化技术: 打包项目环境与快速部署

1、安装SVN服务器

yum 安装

yum -y install subversion

 查看svn安装位置

rpm -ql subversion

编译安装

安装apr 包

yum install gcc-c++ -y
wget https://mirrors.cnnic.cn/apache/apr/apr-1.6.5.tar.gz
./configure --prefix=/usr/local/apr

安装 apr-util

wget https://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

下载subversion

wget http://apache.mirrors.tds.net/subversion/subversion-1.11.1.tar.gz

 下载sqlite

wget https://www.sqlite.org/snapshot/sqlite-snapshot-201903021525.tar.gz

 解压到

./subversion/sqlite-amalgamation

下载zlib

wget http://zlib.net/zlib-1.2.11.tar.gz
./configure --prefix=/usr/local/zlib

编译安装subversion

./configure --prefix=/usr/local/subversion --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

 这里需要注意./configure命令,这个命令作为编译配置有很多选项,如果失败,需要添加合适的选项,错误如下:
错误1:configure: error: Subversion requires LZ4 >= r129, or use --with-lz4=internal
解决:./configure命令添加 --with-lz4=internal选项
错误2:configure: error: Subversion requires UTF8PROC
解决:./configure命令添加  --with-utf8proc=internal

./configure --prefix=/usr/local/subversion --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-zlib=/usr/local/zlib --with-lz4=internal --with-utf8proc=internal
make && make install
ln -s /usr/local/subversion/bin/* /usr/bin/
 svnadmin --version


svnadmin, version 1.11.1 (r1850623)
   compiled Mar 25 2019, 00:35:20 on x86_64-unknown-linux-gnu

Copyright (C) 2019 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.
Subversion is open source software, see http://subversion.apache.org/

The following repository back-end (FS) modules are available:

* fs_fs : Module for working with a plain file (FSFS) repository.
* fs_x : Module for working with an experimental (FSX) repository.

with an experimental (FSX) repository.

 创建目录

mkdir /home/svn
svnadmin create /home/svn/repos
egrep -v "^$|^#" /home/svn/repos/conf/svnserve.conf 

[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
[sasl]
egrep -v "^$|^#" /home/svn/repos/conf/passwd 

[users]
test=123456
egrep -v "^$|^#" /home/svn/repos/conf/authz 

[aliases]
[groups]
[respo: /]
test = rw

启动

svnserve -d -r /home/svn/
ps -ef | grep svn
root     18974     1  0 04:19 ?        00:00:00 svnserve -d -r /home/svn/
root     18977 18738  0 04:20 pts/0    00:00:00 grep --color=auto svn

连接

SVN 搭建完成

2、搭建docker 镜像仓库

version: '3.2'
services:
  registry:
    image: registry
    ports:
      - 5000:5000
    restart: always
    container_name: registry
    volumes:
      - ./registry:/var/lib/registry

  

docker-compose up -d

  

[root@jenkins registry]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
990c1f5a57ad        registry            "/entrypoint.sh /e..."   31 seconds ago      Up 30 seconds       0.0.0.0:5000->5000/tcp   registry

  

pre / prd 机器上设置docker镜像仓库

[root@pre ~]# cat /etc/docker/daemon.json
{"registry-mirrors": ["http://04be47cf.m.daocloud.io"],"insecure-registries":["192.168.1.15:5000"]}

3、构建lnmp镜像

[root@jenkins nginx]# pwd
/home/lnmp/nginx
[root@jenkins nginx]# ll
total 1000
-rw-r--r-- 1 root root     567 Mar 29 16:42 Dockerfile
-rw-r--r-- 1 root root 1015384 Mar 29 16:43 nginx-1.14.2.tar.gz
-rw-r--r-- 1 root root     335 Mar 29 16:53 nginx.conf

 Nginx Dockerfile

FROM centos:7
MAINTAINER blog.51cto.com/ganbing
ENV TIME_ZOME Asia/Shanghai

RUN yum -y install gcc gcc-c++ make openssl-devel pcre-devel
ADD nginx-1.14.2.tar.gz /tmp

RUN cd /tmp/nginx-1.14.2 && 
        ./configure --prefix=/usr/local/nginx && 
        make -j 2 && 
        make install

RUN rm -rf /tmp/nginx* && yum clean all && 
        echo "${TIME_ZOME}" > /etc/timezone && 
        ln -sf /usr/share/zoneinfo/${TIME_ZOME} /etc/localtime

COPY nginx.conf /usr/local/nginx/conf/
WORKDIR /usr/local/nginx/
EXPOSE 80
CMD ["./sbin/nginx","-g","daemon off;"]

nginx.conf

server {
        listen 80;
        server_name localhost;
        root html;
        index index.html index.php;

        location ~ .php$ {
            root html;
            fastcgi_pass php-cgi:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }

 

[root@jenkins php]# pwd
/home/lnmp/php
[root@jenkins php]# ll
total 20516
-rw-r--r-- 1 root root     1328 Mar 30 10:45 Dockerfile
-rw-r--r-- 1 root root  1514966 Mar 12 21:18 libzip-1.2.0.tar.gz
-rw-r--r-- 1 root root 19421313 Mar  5 22:30 php-7.3.3.tar.gz
-rw-r--r-- 1 root root    64945 Mar 29 20:04 php.ini

  

php Dockerfile

FROM centos:7
MAINTAINER blog.51cto.com/ganbing
ENV TIME_ZOME Asia/Shanghai
RUN yum install -y gcc gcc-c++ make gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel zlib-devel perl
ADD php-7.3.3.tar.gz /tmp/
ADD libzip-1.2.0.tar.gz /tmp/

RUN cd /tmp/libzip-1.2.0 && 
        ./configure && 
        make && 
        make install

RUN  cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

RUN cd /tmp/php-7.3.3 && 
        ./configure --prefix=/usr/local/php 
        --with-config-file-path=/usr/local/php/etc 
        --with-mysql --with-mysqli 
        --with-openssl --with-zlib --with-curl --with-gd 
        --with-jpeg-dir --with-png-dir --with-iconv 
        --enable-fpm --enable-zip --enable-mbstring && 
        make -j 4 && 
        make install

RUN cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && 
        sed -i 's/127.0.0.1/0.0.0.0/g' /usr/local/php/etc/php-fpm.conf && 
        sed -i "21a daemonize=no" /usr/local/php/etc/php-fpm.conf && 
        echo "${TIME_ZOME}" > /etc/timezone && 
        ln -sf /usr/share/zoneinfo/${TIME_ZOME} /etc/localtime

COPY php.ini /usr/local/php/etc/
RUN rm -rf /tmp/php* && yum clean all
WORKDIR /usr/local/php/
EXPOSE 9000
CMD ["./sbin/php-fpm","-c","/usr/local/php/etc/php-fpm.conf"]

 

php.ini 为默认文件

构建镜像

docker build -t 192.168.1.15:5000/lnmp-nginx:base .
docker build -t 192.168.1.15:5000/lnmp-php:base .

docker push 192.168.1.15:5000/lnmp-php:base
docker push 192.168.1.15:5000/lnmp-nginx:base

  

  

查看仓库镜像

[root@pre ~]# curl http://192.168.1.15:5000/v2/_catalog
{"repositories":["lnmp-nginx","lnmp-php"]}

Jenkins 安装

安装jdk

yum -y install java

 安装 Ant Maven Tomcat

wget http://www.jpackage.org/jpackage50.repo -P /etc/yum.repos.d/
yum -y install ant maven tomcat

 设置tomcat编码为UTF-8

vim /etc/tomcat/server.xml

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8" />

 安装jenkins

wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
rpm --import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key
yum install jenkins -y
chkconfig jenkins on
service jenkins start

 http://ip:8080 访问jenkins, 安装推荐插件

全局工具配置

 

原文地址:https://www.cnblogs.com/blogscc/p/10591644.html