混帐GIT_WORK_TREE远程后收到钩部署 [英] git GIT_WORK_TREE post-receive hook deployment remote

查看:1549
本文介绍了混帐GIT_WORK_TREE远程后收到钩部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用这个,收到后钩来更新我活的服务器

I'm trying to use this post-recieve hook to update my live server

GIT_WORK_TREE = /无功/网络/ www.example.org git的结帐-f

这是勾遥控器上的裸回购,我想现场的工作树是在不同的服务器上。

This hook is on the remote bare repo and I would like the live work tree to be on a different server.

我如何设置此,这样当钩大火它检查出来的文件到实时服务器,不是SSH从远程服务器到服务器直播?我在哪里定义这个?

How do I set this up so that when the hook fires it checks out the files to the live server, does it ssh from the remote server to the live server? Where do I define this?

下面就是我试图安装

http://www.dejaaugustine.com/2011/05/leveraging-git-as-a-full-fledged-web-development-tool/

但生活和测试坐在不同的服务器上,以裸露的回购协议,但不是用git拉我打算用 git的结帐-f

but live and test sit on separate servers to the bare repo, but instead of using git pull I was going to use git checkout -f.

推荐答案

以下解决方案更新与code直播服务器code群从另一台服务器上裸露的回购。该解决方案不使用SCP或复制文件覆盖住服务器上,因为我们要避免覆盖整个目录(使用Git,我们可以选择我们想要更新)。

The following solution updates a live server code base with code from a bare repo on another server. This solution does not use scp or copy files to overwrite on the live server, because we want to avoid overwriting a whole directory (with git we can choose what we want to update).

假设


  • 您正在推动的code到测试/临时服务器上裸库(或者它可能只是一台服务器来承载你的集中回购)

  • 您想更新您的code Live服务器在这裸露的回购协议

  • 您活的服务器是在不同的服务器上比你裸露的回购协议

在现场服务器:


  • 设置一个非裸git仓库承载实时文件: CD /var/www/www.yoursite.com和放大器;&安培; git的初始化

  • 从这个活的服务器,请确保您有SSH访问到你的纯仓库是服务器,使用SSH密钥(不包括这里)

  • 添加了集中回购: git的远程添加出身的git @ testserverip:/path/to/repo.git

  • 现在,每次要更新现场服务器code的基础上,你可以运行混帐获取原产地然后按 git的合并

  • Set up a non-bare git repo that hosts the live files: cd /var/www/www.yoursite.com && git init
  • From this live server, make sure you have ssh-access to the server where your bare repository is, using ssh-keys (not covered here)
  • Add the "centralized" repo: git remote add origin git@testserverip:/path/to/repo.git
  • Now, every time you want to update the live server code base, you can run git fetch origin followed by git merge

由于这是一个活的服务器,通常不希望任何合并,冲突造成麻烦。如果你不关心活的服务器上失去的变化(因为你可能永远不会改变什么活服务器上重要的),你可以使用混帐合并-m覆盖Live服务器-s递归-X他们的出身/主动分支现场的服务器上 -

Since this is a live server, you typically do not want any merge-conflicts to cause trouble. If you don't care about loosing changes on the live server (because you probably never change anything important on the live server), you can use git merge -m 'Overwriting live server' -s recursive -X theirs origin/active-branch-on-live-server

一个典型的情况是,你有活的服务器上的其他文件(临时文件,用户更改过的文件等),您不希望覆盖)。确保所有这些文件/目录添加到您的.gitignore文件,并确保它们不会被加git的增加。这样,他们就不会被当code是从你拉的影响集中式回购。

A typical scenario is that you have other files (temp files, user-changed files etc) on the live server that you do not want to overwrite). Make sure to add all these files/directories to your .gitignore-file and make sure they are not added by git add. That way, they will not be affected when code is pulled from you centralized repo.

如果您希望此设置对我来说更自动化,使现场服务器上的bash脚本:

If you want this setup to me more automatic, make a bash script on the live server:

git fetch origin
git merge -m 'Overwriting live server' -s recursive -X theirs origin/active-branch-on-live-server

将这个脚本作为一个可执行bash脚本(这里不讨论)。现在,您可以拨打集中服务器上的一个钩子脚本这个脚本,使现场服务器获取每一次更新,你把你的code。

Make this script as an executable bash script (not covered here). Now, you can call this script from a hook-script on the "centralized" server, so that the live server gets updated every time you push your code.

在集中回购/测试/临时服务器:

(你应该已经有一个光秃秃的回购在这里设置,如果没有创建它)。

(You should already have a bare repo set up here, if not create it).

在您的裸repo.git /钩/创建/编辑后接受文件,从而使活的服务器运行时,code上面创建的脚本被推到裸回购:

In your bare-repo.git/hooks/ create/edit the post-receive file, so that the live server runs the script created above when code is pushed to the bare repo:

#!/bin/bash
while read oldrev newrev refname
do
    branch=$(git rev-parse --symbolic --abbrev-ref $refname)

    # Use this if-sentence to only update live server if branch is the wanted branch, e.g. master or stable
    if [[ "stable" == "$branch" ]]; then
            # Fetch this branch from live-server
            ssh root@ip-to-live-server '/path/to/script-created-above'
    fi
done

请确保您的git的用户承载您的裸回购了通过SSH密钥访问您的在线服务器,服务器,这样的SSH上述作品脚本。

Make sure that the git user on you the server that hosts your bare repo has access to your live server via ssh-keys, so that the ssh in the script above works.

这是一个示意性的概述。详情可找到其他地方:

This is a schematic overview. Details can be found other places:


  • 关于现场服务器上覆盖文件:<一href=\"http://stackoverflow.com/a/10113231/1030104\">http://stackoverflow.com/a/10113231/1030104

  • 使用gitignore:<一href=\"http://stackoverflow.com/questions/343646/ignoring-directories-in-git-repos-on-windows\">Ignoring目录中的Git回购在Windows

  • 使用,收到后钩子脚本在给定的分支反应:<一href=\"http://stackoverflow.com/questions/7351551/writing-a-git-post-receive-hook-to-deal-with-a-specific-branch\">Writing一个Git后收到钩来处理特定的分支

  • About overwriting files on a live server: http://stackoverflow.com/a/10113231/1030104
  • Using gitignore: Ignoring directories in Git repos on Windows
  • Using a post-recieve hook script to react on a given branch: Writing a git post-receive hook to deal with a specific branch

这篇关于混帐GIT_WORK_TREE远程后收到钩部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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