How to work with a single git repo on 2 servers: production and testing

git

We have a single git repository on a test server (let's call it test1). The repository is very simple, just master no branches or anything fancy. The goal of this repo is to track changes to /etc/puppet and all of its sub folders. It's usually clean and synced with head.

Now we want to copy everything in test1:/etc/puppet to a production server (let's call it prod1) while maintaining a proper git workflow between to two machines. Whenever changes on test1 are ready for production, we want to use git to push them from test1 to prod1. The goal here is to be able to quickly revert back changes on prod1 if anything breaks.

This is what I have of so far:

  1. Setup a bare git repo (git init –bare) on test1:/opt/puppet.git to act as an intermediate server.
  2. Push data from test1:/etc/puppet to the bare.
  3. On prod1 init a new repo in /etc/puppet
  4. Add test1:/opt/puppet.git bare as remote to prod1:/etc/puppet
  5. Pull master data on from test1 to prod1 whenever we want to apply changes to production.

What are your thoughts? Should we continue to use a single master branch or we need to create a new devel branch? If we create devel branch, how do we use it with the newly created bare repo?

Best Answer

If I summarize your request, what you want, is to have an architecture with 1 git server which receives all the pushes from users, and automated pushes to prod when it's ready.

This is exactly what is done with architectire based on gerrit review system for instance. The workflow is as follow :

  1. Git pull from prod server
  2. Do you changes locally
  3. Git push to test server (always in dedicated branch)
  4. Assign reviewer to the commit and add extra hooks to launch for instance smoke test on jenkins (the hakks are added during installation pahse).
  5. When reviewers have accepted the code and the jenkins smoke test are ok, if trivial merge is still possible with master, push is done via gerrit automatically.

So the good point here is that nobody (if properly configured) can push to master without minimal review and basic test. So you master branch from prod is (almost) always clean.

Related Topic