Using 'git checkout -f' to deploy files from a bare git repo in Gitlab

泪湿孤枕 提交于 2019-12-18 07:12:57

问题


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.


回答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.

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


来源:https://stackoverflow.com/questions/30029713/using-git-checkout-f-to-deploy-files-from-a-bare-git-repo-in-gitlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!