用于网站的Git/接收后/测试和生产站点的分离 [英] Git for Websites / post-receive / Separation of Test and Production Sites

查看:113
本文介绍了用于网站的Git/接收后/测试和生产站点的分离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Git来管理我的网站的源代码和部署,并且目前在同一盒子上运行测试网站和实时网站.按照此资源 http://toroid.org/ams/git-website-howto 最初,我想出了以下接收后挂接脚本,以区分对实际站点的推送和对测试站点的推送:

I'm using Git to manage my website's source code and deployment, and currently have the test and live sites running on the same box. Following this resource http://toroid.org/ams/git-website-howto originally, I came up with the following post-receive hook script to differentiate between pushes to my live site and pushes to my test site:

while read ref
do
  #echo "Ref updated:"
  #echo $ref -- would print something like example at top of file
  result=`echo $ref | gawk -F' ' '{ print $3 }'`
  if [ $result != "" ]; then
    echo "Branch found: "
    echo $result
    case $result in
      refs/heads/master )
        git --work-tree=c:/temp/BLAH checkout -f master
        echo "Updated master"
        ;;
      refs/heads/testbranch )
        git --work-tree=c:/temp/BLAH2 checkout -f testbranch
        echo "Updated testbranch"
        ;;
      * )
        echo "No update known for $result"
        ;;
    esac
  fi
done
echo "Post-receive updates complete"

但是,我怀疑这实际上是安全的:)我绝不是Git专家,但是我猜想Git可能会跟踪当前已检出的分支头,并且这种方法可能具有潜在的潜力.使它无休止地迷惑.

However, I have doubts that this is actually safe :) I'm by no means a Git expert, but I am guessing that Git probably keeps track of the current checked-out branch head, and this approach probably has the potential to confuse it to no end.

那么几个问题:

  1. 这样安全吗?

  1. IS this safe?

一种更好的方法是将我的基本存储库作为测试站点存储库(具有相应的工作目录),然后将该存储库将更改推送到新的实时站点存储库,该新的实时站点存储库具有与之对应的工作目录.现场基地?这还将使我可以将生产移动到其他服务器,并保持部署链完整.

Would a better approach be to have my base repository be the test site repository (with corresponding working directory), and then have that repository push changes to a new live site repository, which has a corresponding working directory to the live site base? This would also allow me to move the production to a different server and keep the deployment chain intact.

我缺少什么吗?使用Git管理网站时,是否存在一种不同的,干净的方法来区分测试和生产部署?

Is there something I'm missing? Is there a different, clean way to differentiate between test and production deployments when using Git for managing websites?

作为对Vi的回答的补充说明,是否有一个很好的方法来执行删除操作,而又不会过多地破坏文件系统?

As an additional note in light of Vi's answer, is there a good way to do this that would handle deletions without mucking with the file system much?

谢谢你, -沃尔特

PS-我为多个存储库想出的脚本(除非听说得更好,否则一直在使用)如下:

PS - The script I came up with for the multiple repos (and am using unless I hear better) is as follows:

sitename=`basename \`pwd\``

while read ref
do
  #echo "Ref updated:"
  #echo $ref -- would print something like example at top of file
  result=`echo $ref | gawk -F' ' '{ print $3 }'`
  if [ $result != "" ]; then
    echo "Branch found: "
    echo $result
    case $result in
      refs/heads/master )
        git checkout -q -f master
        if [ $? -eq 0 ]; then
            echo "Test Site checked out properly"
        else
            echo "Failed to checkout test site!"
        fi
        ;;
      refs/heads/live-site )
        git push -q ../Live/$sitename live-site:master
        if [ $? -eq 0 ]; then
            echo "Live Site received updates properly"
        else
            echo "Failed to push updates to Live Site"
        fi
        ;;
      * )
        echo "No update known for $result"
        ;;
    esac
  fi
done
echo "Post-receive updates complete"

然后../Live/$sitename中的存储库(这些是在初始化后添加了工作树的裸"存储库)具有基本的后接收功能:

And then the repo in ../Live/$sitename (these are "bare" repos with working trees added after init) has the basic post-receive:

git checkout -f
if [ $? -eq 0 ]; then
    echo "Live site `basename \`pwd\`` checked out successfully"
else
    echo "Live site failed to checkout"
fi

推荐答案

有一种更好的方法是让我的 基础存储库将成为测试站点 储存库(具有相应的工作 目录),然后将其 存储库将更改推送到新的活动 站点存储库,其中包含一个 对应的工作目录 现场基地?这也将允许 我将生产转移到 不同的服务器,并保持 完整的部署链.

Would a better approach be to have my base repository be the test site repository (with corresponding working directory), and then have that repository push changes to a new live site repository, which has a corresponding working directory to the live site base? This would also allow me to move the production to a different server and keep the deployment chain intact.

是的.在极少数情况下,您希望将测试站点托管在生产站点的旁边.几乎在所有方面都是危险且不专业的,更不用说数据库损坏,Web服务器锁定等.

Yes definitely. It's a very rare occasion you want your test site hosted right next to your production site. It's dangerous and unprofessional in almost every regard, not to speak about database corruption, webserver lockups etc.

我通常有用于测试目的的VM设置.效果很好,旅行时可以随身携带在笔记本电脑上.

I do usually have a VM setup for testing purposes. Works very well and I can have it with me on my laptop while travelling.

使用git部署您的网站是一个很好的主意,很多其他人也在这样做(例如Rob Conery).无论如何,如果您碰巧有一个在线和测试站点,则应该在存储库中为它们建立单独的分支,并在相应的服务器存储库上将其设置为远程跟踪分支.您的工作流程变得像在测试分支中进行工作一样容易,将其推送到测试,测试,合并以进行实时发布.

Using git to deploy your website is a very good idea, there are a lot of other people doing so (e.g. Rob Conery). If you happen to have a live and testing site anyway, you should have seperate branches for them in your repository, set-up as remote-tracking branches on the corresponding server repositories. Your workflow becomes as easy as doing work in your test branch, push it to test, test it, merge to live and push live.

老实说,不要让自己变得太难了.

Honestly, don't make it too hard for yourself.

这篇关于用于网站的Git/接收后/测试和生产站点的分离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆