使用'git checkout -f'从Gitlab中的裸git仓库部署文件

时间:2021-03-28 01:22:35

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.

我正在我的工作场所实施Gitlab,并将所有人转移到它,以便更好地进行代码审查,直接链接到提交的问题管理,以及与Pivotal跟踪器上的用户故事集成。

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

    Git bare repo包含我基于PHP的web-app的所有代码:/var/opt/gitlab/git-data/repositories/git/test-app.git

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

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

In the Git repo directory, I did the following:

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

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.

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

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.

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

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_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.

1 个解决方案

#1


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.

从Git 2.3.3和2.4.0开始,使用push-to-deploy,在git服务器端使用config receive.denyCurrentBranch = updateInstead。请注意,这种方法有一些注意事项。

  • 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!
  • 您的服务器将包含一个.git目录,其中包含项目的整个历史记录。您可能想要确保它无法提供给用户!

  • 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.
  • 如果你的项目需要一个“构建”步骤,那么你必须明确地设置它,也许是通过githooks。

#1


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.

从Git 2.3.3和2.4.0开始,使用push-to-deploy,在git服务器端使用config receive.denyCurrentBranch = updateInstead。请注意,这种方法有一些注意事项。

  • 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!
  • 您的服务器将包含一个.git目录,其中包含项目的整个历史记录。您可能想要确保它无法提供给用户!

  • 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.
  • 如果你的项目需要一个“构建”步骤,那么你必须明确地设置它,也许是通过githooks。