我怎样才能通过推送自动进行结帐? [英] How can I automagically make a checkout upon push?

查看:95
本文介绍了我怎样才能通过推送自动进行结帐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下情况:

我有一个包含JavaScript项目代码的git仓库foo.git。在这个版本库中有一个分支 production ,它包含了代码的状态,这个代码是由一个从 / var / www / foo 。该存储库是该项目的主存储库。



是否可以将 / var / www / foo 更新为每当有人推送到特定的分支时,都会收到 production 结账?你可能会认为git守护进程(或者是所有用户通过SSH登录的用户git)有权写入所述目录。 解决方案

你必须在服务器上用 git init --bare 创建一个裸仓库。
然后使用 post-receive 钩子触发您的部署。
您部署的方式取决于您。


我的部署策略



我通常会将 deploy director,在某处合乎逻辑。
然后每次结账时,我将最新的分支解压到 deploy / COMMIT_ID ,其中 COMMIT_ID 是最新的推动。一旦结帐完成,您可以重新指向最新的部署目录。

  deploy.git / 
deploy /
a7922231 /
b2f0a2af /
最新 - > b2f0a2af



解压更新



使用 git-checkout ,我通常使用 git-archive 将分支解包到目录中。

 #假设当前目录是deploy.git 
HEAD =`cat refs / heads / master`
mkdir -p。 ./deploy/${HEAD}
git archive master | tar -x -C ../deploy/${HEAD}

您的网络服务器可以指向 deploy / latest ,更新或多或少是原子的。



我经常在生产中使用它,与同一个目录下的解包相比,它具有一些优势。


  1. 回滚很容易

  2. post-unpack过程,比如在不中断当前部署的情况下编译或安装依赖项。



提示




  1. 每次更新,附加到部署日志中,说明更新何时发生,以及它们的哈希ID是什么。这使回滚更容易


Consider the following situation:

I have a git repository foo.git that contains code of a javascript project. In this repository there is a branch production that contains the state of the code as served by a web-server which fetches the code from /var/www/foo. This repository is the master repository for the project. Everybody pushes and pulls from/to it.

Is it possible to have /var/www/foo updated to a checkout of production whenever someobody pushes to that particular branch? You may assume that the git daemon (or the user git which is the user all people log in to to connect via SSH) is entitled to write to said directory.

解决方案

You have to create a bare repository on the server with git init --bare. Then use a post-receive hook to trigger your deploy. How you deploy is up to you.

My Deployment Strategy

I usually place a deploy director, somewhere logical. Then each checkout, I unpack the latest branch to deploy/COMMIT_ID where COMMIT_ID is the hash of the latest push. Once the checkout is complete, you can re-point a symlink to the latest deployment directory.

My usual directory structure:

deploy.git/
deploy/
    a7922231/
    b2f0a2af/
    latest -> b2f0a2af 

Unpacking the Update

Rather than use a git-checkout, I usually use git-archive to unpack a branch into a directory.

# Assuming current directory is deploy.git
HEAD=`cat refs/heads/master`
mkdir -p ../deploy/${HEAD}
git archive master | tar -x -C ../deploy/${HEAD}

Your web-server can point to deploy/latest, updates will be more-or-less atomic.

I use this often in production, and has a few benefits over unpacking over the same directory.

  1. rollbacks are easy
  2. you can do post-unpack procedures, like compile or install dependencies without interrupting the current deployment

Tips

  1. each update, append to a deploy log that says when updates occurred, and what their hash ids are. This makes rollbacks much easier.

这篇关于我怎样才能通过推送自动进行结帐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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