在Gitlab中使用'git checkout -f'从裸机git repo部署文件 [英] Using 'git checkout -f' to deploy files from a bare git repo in Gitlab

查看:634
本文介绍了在Gitlab中使用'git checkout -f'从裸机git repo部署文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的工作场所实施Gitlab,并将每个人都转移到更好的代码审查,问题管理与提交直接相关,并与Pivotal跟踪器上的用户故事集成。



我目前的测试应用设置是这样的:


  1. 将所有代码我的基于PHP的网络应用程序位于:/var/opt/gitlab/git-data/repositories/git/test-app.git


  2. 部署目录是:/ var / www / test-app


在Git repo目录中,我执行了以下操作:

  export GIT_WORK_TREE = / var / www / test-app 
git checkout -f master

这个工作就像一个魅力,所有的文件都可以在/ var / www / test-app中访问。



这里是我被困的地方。我希望Gitlab服务器只能托管Git裸机,而不是部署目录。部署目录将托管在单独的服务器上。



有没有办法将不同的服务器设置为GIT_WORK_TREE?我试着把我的服务器的细节放在那里,例如:

  GIT_WORK_TREE=git@devserver.mydomain.com:/ var / www / test-app 

但没有骰子。





谢谢。

解决方案

在远程服务器上检出,您应该(在同一个后接收挂钩中)推送到远程服务器。



由于 Git 2.3.3 2.4.0 ,使用推送部署,使用git服务器端的配置 receive.denyCurrentBranch = updateInstead

请注意,这种方法有一些注意事项。



  • 您的服务器将包含一个 .git 目录,包含项目的整个历史记录。您可能想要确保不能为用户提供服务!

  • 在部署期间,用户可能会暂时遇到站点不一致的状态,一些文件位于旧版本和其他新版本,甚至是半写的文件。如果这是您的项目的一个问题,推送部署可能不适合您。

  • 如果您的项目需要构建步骤,则必须明确设置,或许通过githooks。



I am in the process of implementing Gitlab at my workplace and transitioning everyone over to it for better code reviews, issue management directly linked to commits, and integration with user stories on Pivotal tracker.

My current setup for a test app is as such:

  1. Git bare repo with all the code for my PHP based web-app found in: /var/opt/gitlab/git-data/repositories/git/test-app.git

  2. Deploy directory is: /var/www/test-app

In the Git repo directory, I did the following:

export GIT_WORK_TREE=/var/www/test-app
git checkout -f master

This worked like a charm and all the files are accessible in /var/www/test-app as expected.

Here is where I am stumped. I want the Gitlab server to ONLY host the Git bare repos and not the deploy directories. The deploy directory is to be hosted on a separate server.

Is there a way to have a different server setup as the GIT_WORK_TREE? I tried putting my server's details in there such as :

GIT_WORK_TREE=git@devserver.mydomain.com:/var/www/test-app

but no dice.

Is this even possible or am I barking up the wrong tree here? Would love some advice.

Thanks.

解决方案

Instead of trying to checkout on a distant server, you should instead (in the same post-receive hook) push to that distant server.

Since Git 2.3.3 and 2.4.0, using a push-to-deploy, using the config receive.denyCurrentBranch = updateInstead on the git server side.
Note that there are some caveats to this approach.

  • Your server will contain a .git directory containing the entire history of your project. You probably want to make extra sure that it cannot be served to users!
  • During deploys, it will be possible for users momentarily to encounter the site in an inconsistent state, with some files at the old version and others at the new version, or even half-written files. If this is a problem for your project, push-to-deploy is probably not for you.
  • If your project needs a "build" step, then you will have to set that up explicitly, perhaps via githooks.

这篇关于在Gitlab中使用'git checkout -f'从裸机git repo部署文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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