1

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.

Kopty
  • 538
  • 5
  • 20
  • The gitlab server should be the gitlab server, and nothing else. It sounds like you want to setup up a continuous integration/build server which automatically deploys to your staging server after a commit to gitlab. – Stuart Grassie May 04 '15 at 12:14
  • Yes that is exactly what I am looking to do. Do you have any insight on that matter? – Kopty May 04 '15 at 12:32
  • There are plenty of CI servers, such as Gitlab's own CI, Jenkins, Teamcity etc. We have Jenkins setup here with a plugin which makes it look like a Gitlab CI, which builds projects on commit, runs tests and deploys. – Stuart Grassie May 04 '15 at 12:54
  • I understand there are alternatives, and much more thorough ways to do this, which I will explore eventually.However, right now I am searching for the answer to my question: is it possible to do this (git checkout -f) across different servers? – Kopty May 04 '15 at 13:14
  • If you use a CI server, then you don't need to use git to do this, as the CI server would deploy the files for you. – Stuart Grassie May 04 '15 at 13:15

1 Answers1

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.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yes I actually have this running right now in our existing workflow but want to move away from it for the exact reason you pointed out -- that our server contains a .git directory which is not safe. My task is to ensure that is not the case anymore, which is why I am exploring options such as this. – Kopty May 04 '15 at 12:47