龙空技术网

12、构建jenkins/Docker持续集成PHP环境

动漫IT 149

前言:

此刻我们对“imagephp”大体比较重视,各位老铁们都想要分析一些“imagephp”的相关知识。那么小编同时在网上收集了一些关于“imagephp””的相关资讯,希望朋友们能喜欢,小伙伴们快快来了解一下吧!

1、配置一个workpress的项目2、配置svn3、添加一个Parameter用于限定发布名称4、添加一个String Parameter用于svn版本回滚5、在jenkins的构建里配置打包脚本

#!/bin/bash#Jenkins打包脚本#BUILD_ID=DontKillMedate_time=`date +%Y%m%d%H%M%S`echo "************************************************开*始*打*包************************************************"if [ ! -z $Reversion ];then    /usr/bin/svn upgrade $WORKSPACE --username cce --password caichangen    /usr/bin/svn --username cce --password caichangen co $SVN_URL@$Reversion $WORKSPACE --force --no-auth-cache    if [ ! -z $Reversion ];then        echo "你回滚的版本为:$Reversion "    fielse    Reversion=$SVN_REVISIONfitar -zvcf $Sites.tar.gz ./*if [ ! -d /data/sourcecode ];then    mkdir -pv /data/sourcecodefiecho "************************************************开*始*备*份************************************************"mv $Sites.tar.gz /data/sourcecode/${Sites}-${date_time}.tar.gzecho -n 'Loading'echo -n '.'echo -n '.'echo -n '.'echochown ops:ops /data/sourcecode/ -Recho "************************************************开*始*发*布************************************************"sudo -u ops -H bash -x /data/jenkins/scripts/online-latest-www-deploy.sh ${Sites} ${date_time} ${SVN_REVISION}echo "************************************************发*布*成*功************************************************"rm -f /data/sourcecode/${Sites}-${date_time}.tar.gz
6、配置发布脚本
[root@node2 ~]# cat /data/jenkins/scripts/online-latest-www-deploy.sh#!/bin/bash#线上中转机发布脚本#### check if [ ! -n "$1" ];then        echo "Please enter your file's name. ex: sh online-stable-api-deploy.sh kaopu"        exit 10finame=$1date_time=$2reversion=$3ansible -s 172.16.1.73 -m copy -a "src=/data/sourcecode/${name}-${date_time}.tar.gz dest=/data/source_packet/${name}.tar.gz" && \ansible 172.16.1.73 -s -a "bash -x /data/jenkins/scripts/online-latest-www-deploy.sh ${name} ${date_time} ${reversion}"
7、配置基础镜像,并上传至仓库nginx
[root@node3 ~]# ls /data/jenkins/deploy/lnmp/base/nginx/default.conf  Dockerfile  nginx-1.8.1.tar.gz  nginx.conf  wwwroot[root@node3 ~]# cat /data/jenkins/deploy/lnmp/base/nginx/DockerfileFROM centos:centos6MAINTAINER caichangenADD nginx-1.8.1.tar.gz /RUN yum install -y openssl-devel pcre-devel gcc gcc-c++ && \    useradd -r -M -s /sbin/nologin www && \    cd /nginx-1.8.1 && \    ./configure --prefix=/usr/local/nginx --with-pcre --with-file-aio --with-http_ssl_module --with-http_flv_module --with-http_dav_module --with-http_sub_module --with-http_mp4_module --with-http_realip_module --with-http_addition_module --with-http_gzip_static_module --with-http_stub_status_module --lock-path=/usr/local/nginx/nginx.lock --pid-path=/usr/local/nginx/run/nginx.pid --http-scgi-temp-path=/usr/local/nginx/scgi --http-fastcgi-temp-path=/usr/local/nginx/fcgi/ --http-uwsgi-temp-path=/usr/local/nginx/uwsgi --http-proxy-temp-path=/usr/local/nginx/proxy/ --http-client-body-temp-path=/usr/local/nginx/client/ --user=www && \    make -j 2 && \    make install && \    mkdir -pv /usr/local/nginx/conf/vhosts && \    mkdir -pv /data/wwwroot /data/logs && \    chown www:www -R /data/wwwroot && \    rm -rf /nginx-1.8.1ADD nginx.conf /usr/local/nginx/conf/nginx.confADD default.conf /usr/local/nginx/conf/vhosts/default.confCMD /usr/local/nginx/sbin/nginxEXPOSE 80[root@node3 ~]# docker build -t 172.16.1.72:5000/nginx:base /data/jenkins/deploy/lnmp/base/nginx/[root@node3 ~]# docker push 172.16.1.72:5000/nginx:base
注意:nginx需要在配置文件里面添加daemon off;使nginx能够后台运行php
[root@node3 ~]# ls /data/jenkins/deploy/lnmp/base/php/Dockerfile  php-7.1.12.tar.gz[root@node3 ~]# cat /data/jenkins/deploy/lnmp/base/php/Dockerfile FROM centos:centos6MAINTAINER caichangenADD php-7.1.12.tar.gz /WORKDIR /php-7.1.12RUN rpm -vih  && \    yum install -y libjpeg-turbo-devel curl-devel libxml2-devel libpng-devel freetype-devel php-mcrypt libmcrypt-devel zlib-devel php-gd re2c bison bison-devel gcc gcc-c++ openssl-devel && \    mkdir -pv /data/wwwroot && \    useradd -r -M -s /sbin/nologin www && \    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-libxml-dir=/usr --with-mcrypt --enable-gd-native-ttf \    --with-fpm-user=www --with-freetype-dir --enable-mbstring --enable-mbregex --with-iconv-dir --enable-sysvsem --enable-sockets --with-mysql \    --with-mysqli --with-jpeg-dir --disable-rpath --enable-bcmath --with-png-dir --enable-shmop --with-openssl --with-gettext --enable-pcntl \    --with-xmlrpc --enable-soap --enable-xml --enable-zip --enable-fpm --with-iconv --with-mhash --with-curl --with-gd && \    make -j 2 && \    make install && \    cp php.ini-production /usr/local/php/etc/php.ini && \    cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && \    cp /usr/local/php/etc/php-fpm.d/ /usr/local/php/etc/php-fpm.d/ && \    sed -i 's/127.0.0.1:9000/0.0.0.0:9000/' /usr/local/php/etc/php-fpm.d/  && \    rm -rf /php-7.1.12 && \    chown www:www -R /data/wwwrootCMD ["/usr/local/php/sbin/php-fpm","-F"]EXPOSE 9000[root@node3 ~]# docker build -t 172.16.1.72:5000/php:base /data/jenkins/deploy/lnmp/base/php/[root@node3 ~]# docker push 172.16.1.72:5000/php:base
8、配置上线Dockerfile并且通过docker-compose进行编排
[root@node3 ~]# cat /data/jenkins/deploy/lnmp/docker-compose.yml version: "2"services:  php:    image: php:online  nginx:    image: nginx:online    links:      - "php:php"    ports:      - "80:80"[root@node3 ~]# cat /data/jenkins/deploy/lnmp/nginx/Dockerfile FROM 172.16.1.72:5000/nginx:baseMAINTAINER caichangenADD www /data/wwwrootRUN chown www:www -R /data/wwwrootCMD /usr/local/nginx/sbin/nginxVOLUME /data/logsEXPOSE 80[root@node3 ~]# cat /data/jenkins/deploy/lnmp/php/Dockerfile FROM 172.16.1.72:5000/php:baseMAINTAINER caichangenADD www /data/wwwrootRUN /bin/chown www:www -R /data/wwwroot/CMD ["/usr/local/php/sbin/php-fpm","-F"]EXPOSE 9000
9、目标主机配置上线脚本
[root@node3 nginx]# cat /data/jenkins/scripts/online-latest-www-deploy.sh #!/bin/bash#if [ ! -n "$1" ];then        echo "Please enter your file's name. ex: sh online-stable-api-deploy.sh kaopu"        exit 10finame=$1date_time=$2reversion=$3rm -rf /data/jenkins/deploy/lnmp/nginx/www/* /data/jenkins/deploy/lnmp/php/www/*tar xvf /data/source_packet/${name}.tar.gz -C /data/jenkins/deploy/lnmp/nginx/www/tar xvf /data/source_packet/${name}.tar.gz -C /data/jenkins/deploy/lnmp/php/www/docker build -t nginx:online /data/jenkins/deploy/lnmp/nginx && \docker build -t php:online /data/jenkins/deploy/lnmp/php && \docker-compose -f /data/jenkins/deploy/lnmp/docker-compose.yml down && \docker-compose -f /data/jenkins/deploy/lnmp/docker-compose.yml up -d
10、测试发布11、测试文件变动的情况12、测试发布然后查看代码是否会随着我们的代码更新而改变13、测试我们的做的回滚接口,回滚到最初的版本,到我们的phpinfo14、查看

标签: #imagephp #phpnginx集成环境