1232121 发表于 2016-5-9 10:07:37

docker(二):简单的代码推送脚本

环境是部署出来了,安装部署在docker测试容器里,不过每次都是要重复的帮测试和开发同事发布代码到测试环境,工作量瞬间变大,而且重复的执行推送脚本也感到郁闷,因为是测试环境用,简单的写了个传参的脚本让他们自己执行了。安装部署在docker测试容器里
docker_update.sh:
#!/bin/sh
autoCommod='--username=svntest --password=111111 --no-auth-cache --non-interactive --config-dir /root/.subversion'
svn='/bin/svn'
domain=''#domain name
operateType=''#trunk,branch or release
target=''#null if trunk,or version if others

if [ $? != 0 ] ; then exit 1; fi

while [ -n "$1" ] ;do
    case "$1" in
      --domain) domain="$2";shift;;
      -t) operateType='trunk';shift;;
      -b) operateType='branches';target="$2";shift;;
      -r) operateType='release';target="$2";shift;;
      --help) help $0;exit;;
      --) shift;break;;
    esac
    shift;
done

if [ -z $domain ] ;then
    echo 'error: no domainm !';
    exit;
fi

if [ -z $operateType ] ;then
    echo 'error: trunk or branches ?';
    exit;
fi

[ ! -d /data/code/$domain ] &&\
mkdir /data/code/$domain -p


rm -rf /home/wwwroot/$domain/hotdocs/

[ ! -d /home/wwwroot/$domain/hotdocs/ ] &&\
mkdir /home/wwwroot/$domain/hotdocs/ -p

$svn checkout svn://192.168.0.168/$domain/data/code/$domain/ $autoCommod

if [ $? -eq 0 ];then
      echo "update ok !"
   else
      echo "error"
   fi



codeDir=/data/code/$domain
webDir=/home/wwwroot/$domain   
svnURL='svn://192.168.0.168/$domain'


case $operateType in
    'trunk')
      trunkDir=${codeDir}/trunk
      if [ ! -e $trunkDir ]; then
         #cd codeDir         
         /bin/svn checkout svn://192.168.0.168/$domain/trunk $trunkDir $autoCommod

      fi

      ln -s /data/code/$domain/trunk/ /home/wwwroot/$domain/hotdocs/public
      ;;

    'branches'|'release')
      branchesDir=${codeDir}/$operateType/$target
      if [ ! -e $branchesDir ]; then
         cd ${codeDir}/${operateType}/
         $svn cleanup $autoCommod
         $svn checkout ${svnURL}/${operateType}/$target $branchesDir $autoCommod

      fi

      ln -s /data/code/$domain/branches/$target /home/wwwroot/$domain/hotdocs/public
      ;;
esac


[ ! -d /home/logs/$domain/access/ ] &&\
mkdir /home/logs/$domain/access/ -p
########################end   #############################

###新域的代码部署流程例子:cd /home/ceshi/scriptssh docker_new_update.sh --domain test.com -t
sh docker_new_update.sh --domain test.com -b 1.1
sh docker_new_update.sh --domain test.com -r 1.1绑定域名:
192.168.0.201 test.com打开浏览器输入
test.com备注:
--domain domain_name 指定域名
-t 切换到trunk
-b 开发分支名 切换到branch
-r 发布分支名 切换到releasesh docker_new_update.sh --domain 域名 主干
sh docker_new_update.sh --domain 域名 分支 分支名
############# end ############################

因为容器重启后ip会发生变化,所以自己又写了个脚本把ip固定,固定为主服务器同一个网段的ip。这样是比较方便的,只要在hosts里面绑定域名,就可以直接用域名访问测试的容器了。以下为使用pipework来固定ip:
###安装pipework
wget https://github.com/jpetazzo/pipework
cp ~/pipework/pipework /usr/local/bin/
chmod +x /usr/local/bin/pipework

###创建不带网络的容器
docker run -itd --name docker-ceshi --net=none -h ceshiceshi/centos:v0.0.3 /bin/bash

###使用pipework固定新建容器ceshi的ip为192.168.0.200:
pipework br0 -i ens2 docker-ceshi 192.168.0.200/24@192.168.0.254

###


页: [1]
查看完整版本: docker(二):简单的代码推送脚本