Kopty
Kopty

Reputation: 548

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

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 :

[email protected]:/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.

Upvotes: 1

Views: 557

Answers (1)

VonC
VonC

Reputation: 1326376

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.

Upvotes: 1

Related Questions