5

In our company we have really powerful linux based build servers (double Xeon with 40 core) and not so powerful win7 laptops. We building our product in C/C++ language for an esoteric CPU. The compiler only exist in Linux. I can edit my git repo with Qt Creator. It is working and quite fast and everything. But I can't build the source on our Laptop. We have a main git repo and I can clone the same repo to my laptop and to our build server. I want to achieve that when I press the build button my code magically building on build server. I did a proof of concept solution where my build script do a git diff on my repo and scp it to the build server than it ssh to build server apply that diff on the server repo than start and wait the compilation. But that solution is not so fool proof. I think a better approaching/method is exist. So how can I build my git repo on external server?

flup
  • 26,937
  • 7
  • 52
  • 74
  • One common method is to have a post-receive hook on a server repo, you push to that repo and it does a checkout and drives the build. – jthill Mar 13 '15 at 01:48
  • Regardless of how you manage to get the build server to build your sources, wouldn't be even nicer to have some feedback before you commit? Is there perhaps a cross compiler that runs on your laptop? – flup Mar 15 '15 at 19:00

3 Answers3

4

If you can push to a bare repo on the build server, then you can associate to that bare repo a post-receive hook (.git/hooks/post-receive) which will:

  • checkout the code

    #!/bin/sh
    git --work-tree=/var/www/domain.com --git-dir=/var/repo/site.git checkout -f
    
  • trigger the compilation.

That way, you don't have to handle the diff yourself.
You only have to associate to the build button the action to push your branch to the bare repo of the build server, and the post-receive hook will do the rest.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @Industrial-antidepressant that is the idea: the bare repo allows you to push to it, but from the bare repo you can checkout its content to a working tree located anywhere you want, and use that working tree for building. – VonC Mar 14 '15 at 21:29
  • I will try this, looks good to me. I didn't know that I can check out a bare repo to a working dir. – Industrial-antidepressant Mar 14 '15 at 22:41
2

You could switch to a forking Workflow, where each developer in the company has a personal public bare repo, which is a fork of the official central repository.

Then, when you want to build your changes, you push them to (a branch or the master of) your own personal public repo.

The build server not only clones the official central repository, but also your public repo. So when you push to your personal public repo, the build server merges the changes and does a personal build for you. Just like it probably already does for the official central repository?

Note that this is not too different from @VonC s answer, just focusses a bit more on the workflow. The personal public repo may well be on the build server, like @VonC suggests. Or it could be somewhere else. As long as it's some place public enough that the build server and you and your colleagues can find it.

flup
  • 26,937
  • 7
  • 52
  • 74
2

Consider integrating http://jenkins-ci.org/ to your workflow, to take care of the build process, using a "git post-receive hook" to trigger the build as (suggested by @VonC).

If you want to use the "Forking Workflow" as suggested by @flup, you can take a look to http://gitlab.com which provides an easy way to manage pull/merge requests, fork repositories and to add hooks.

Josue Abarca
  • 305
  • 3
  • 8