主要思路:
1、做三个文件夹,用于放置不可随意修改的配置文件(测试发布、预发布、真实发布)
2、每次都先修改配置文件再进行构建(构建时会先把配置文件复制到构建的目录,再同步到发布的目录)
3、发布完代码后,创建备份目录并复制代码到备份目录进行备份
4、使用脚本需要传执行类型和构建ID
shell脚本如下:
#!/bin/sh echo "$1" model=$ echo "${model}" version=$ project_MainDir="/data/www/vhosts/git_track/ods" project_ConfigDir="${project_MainDir}/config" project_srcDir="${project_MainDir}/src" project_BuildDir="${project_MainDir}/builds" project_ExcludeFile="${project_MainDir}/shell/exclude.txt" project_DeployDir="/data/www/vhosts/ods.wondershare.cn/httpdocs" project_PreDir="/data/www/vhosts/test-ods.wondershare.cn/httpdocs" rsync_Passwd="/usr/local/rsync/etc/rsyncd206.passwd" case $model in deploy_Test) echo "deploy_model: ${model}" echo "version: ${version}" #复制配置文件 yes | cp -f ${project_ConfigDir}/test/application/database.php ${project_srcDir}/test/application/ yes | cp -f ${project_ConfigDir}/test/application/config.php ${project_srcDir}/test/application/ #同步代码到发布目录 /usr/local/rsync/bin/rsync -zavP --exclude-from=${project_ExcludeFile} --delete ${project_srcDir}/test/ ${project_DeployDir} chown -R apache.users ${project_DeployDir} #创建备份目录 mkdir ${project_BuildDir}/T${version} #把代码复制到备份目录 cp -r ${project_srcDir}/test/* ${project_BuildDir}/T${version}/ ;; deploy_Pre) echo "deploy_model: ${model}" echo "version: ${version}" yes | cp -f ${project_ConfigDir}/pre/application/database.php ${project_srcDir}/release/application/ yes | cp -f ${project_ConfigDir}/pre/application/config.php ${project_srcDir}/release/application/ /usr/local/rsync/bin/rsync -zrltDvP --exclude-from=${project_ExcludeFile} --delete --password-file=${rsync_Passwd} ${project_srcDir}/release/ apache@192.168.10.206::apache${project_PreDir}/ mkdir ${project_BuildDir}/P${version} cp -r ${project_srcDir}/release/* ${project_BuildDir}/P${version}/ ;; deploy_Real) echo "deploy_model: ${model}" echo "version: ${version}" yes | cp -f ${project_ConfigDir}/real/application/database.php ${project_srcDir}/release/application/ yes | cp -f ${project_ConfigDir}/real/application/config.php ${project_srcDir}/release/application/ /usr/local/rsync/bin/rsync -zrltDvP --exclude-from=${project_ExcludeFile} --delete --password-file=${rsync_Passwd} ${project_srcDir}/release/ apache@192.168.10.206::apache${project_DeployDir}/ mkdir ${project_BuildDir}/R${version} cp -r ${project_srcDir}/release/* ${project_BuildDir}/R${version}/ ;; rollback_Pre) echo "rollback_model: ${model}" echo "version: ${version}" #echo "/usr/local/rsync/bin/rsync -zrltDvP --exclude-from=${project_ExcludeFile} --delete --password-file=${rsync_Passwd} ${project_BuildDir}/P${version}/ apache@192.168.10.206::apache${project_DeployDir}/${project_PreDir}/" > /test.txt /usr/local/rsync/bin/rsync -zrltDvP --exclude-from=${project_ExcludeFile} --delete --password-file=${rsync_Passwd} ${project_BuildDir}/P${version}/ apache@192.168.10.206::apache${project_PreDir}/ ;; rollback_Real) echo "rollback_model: ${model}" echo "version: ${version}" /usr/local/rsync/bin/rsync -zrltDvP --exclude-from=${project_ExcludeFile} --delete --password-file=${rsync_Passwd} ${project_BuildDir}/R${version}/ apache@192.168.10.206::apache${project_DeployDir}/ ;; *) exit ;; esac
1、测试发布
2、预发布:
2、真实发布:
3、回滚发布:
case $deploy_evn in Rollback_Pre) url="$pre_version" ;; Rollback_Real) url="$real_version" ;; *) exit ;; esac model="$deploy_evn" projectName=`echo "$url"|awk -F '/' '{print $6}'` rollbackID=`echo "$url"|awk -F '/' '{print $7}'` /bin/sh /usr/local/rsync/woshrs/hrs.sh $model $rollbackID