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

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

问题描述

我正在我的工作场所实施 Gitlab,并将每个人都过渡到它,以便更好地进行代码审查、与提交直接相关的问题管理以及与 Pivotal 跟踪器上的用户故事集成.

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. 带有我基于 PHP 的 web 应用程序的所有代码的 Git 裸仓库位于:/var/opt/gitlab/git-data/repositories/git/test-app.git

  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

部署目录为:/var/www/test-app

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

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

In the Git repo directory, I did the following:

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

这就像一个魅力,所有文件都可以按预期在/var/www/test-app 中访问.

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

这就是我难过的地方.我希望 Gitlab 服务器只托管 Git 裸存储库而不是部署目录.部署目录将托管在单独的服务器上.

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.

有没有办法像 GIT_WORK_TREE 一样设置不同的服务器?我尝试将我的服务器的详细信息放在那里,例如:

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

但没有骰子.

这是可能的还是我在这里吠错了树?希望得到一些建议.

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

谢谢.

推荐答案

您应该(在同一个 post-receive 挂钩中)推送到远程服务器,而不是尝试在远程服务器上结帐.

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

自从 Git 2.3.32.4.0,使用 push-to-deploy,使用配置 receive.denyCurrentBranch = updateInsteadgit 服务器端.
请注意,这种方法有一些注意事项.

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.

  • 您的服务器将包含一个 .git 目录,其中包含您项目的整个历史记录.您可能需要额外确保它不能提供给用户!
  • 在部署过程中,用户可能会瞬间遇到站点状态不一致的情况,有些文件是旧版本,有些文件是新版本,甚至是写了一半的文件.如果这对您的项目来说是个问题,那么推送部署可能不适合您.
  • 如果您的项目需要构建"步骤,那么您必须明确设置,可能通过 githooks.
  • 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天全站免登陆