Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: recommended setup for web development

Tags:

git

gitolite

For two weeks now I've been trying to implement Git at our office. Rather than lack of documentation it's the wealth of examples, tutorials and the various uses of git that have made me confused as to what is a recommended setup for web development.

I think I have a decent setup in mind, but before diving into yet another structure, I'd like to check with more experienced people. I have the following in mind:

  • Workstations push to a local staging server (A)
  • Local staging server works with gitolite to properly divide roles
  • A hook automatically pushes any change to the staging server onto the production server (B)

This is visualized below: enter image description here

Does this make sense? We have a variety of smaller PHP websites, nothing very complicated. The doubts I have are:

  • What kind of 'hook' should I use for (B)?
  • Should I also run gitolite on the production server? I feel I should not, because after all it is just one user that uploads things to the server (the hook on the staging server), but I'm not sure.
  • My starting point is: we have all websites on the Production server, and not yet on the Staging server nor the Workstations. What is a convenient way of "pulling" them down to staging and workstations, at the initial setup?

Now, the following questions are some extra thoughts, not of utmost important at the moment but share your thoughts if you happen to know more:

  • For simplicity I prefer to be able to run git push from the workstation and have both the staging server and production server updated. But sometimes it might be useful to only update the staging server and check out things over there first, before going live. Is there an easy solution?

  • In reality we have not only one but several different production servers. But only one staging server. Is there a way of configuring different production servers so that git automatically pushes them out to the right server?

Thanks in advance for sharing your thoughts!

like image 695
user852091 Avatar asked Aug 15 '11 23:08

user852091


People also ask

How is Git used in web development?

Overview. Git is an excellent resource to use for web development as it allows you to streamline live updates in addition to providing a copy of your website files. For example, you can create your website on your home computer and use Git to push a copy of those files to your DreamHost web server.

Is Git necessary for web development?

GitHub has become one of the few necessary platforms to use in today's web development world. It is a great tool that makes your life easier, has the potential to make you stand out from other web developers and hosts some of the biggest and most interesting projects out there today.

What is Git and GitHub in web development?

Git is an example of a VCS, and GitHub is a web site + infrastructure that provides a Git server plus a number of really useful tools for working with git repositories individually or in teams, such as reporting issues with the code, reviewing tools, project management features such as assigning tasks and task statuses ...


2 Answers

  • What kind of 'hook' should I use for (B)?

You should use the post-receive or post-update hooks to do that

  • Should I also run gitolite on the production server? I feel I should not, because after all it is just one user that uploads things to the server (the hook on the staging server), but I'm not sure.

Not mandatory for the reasons you've mentioned, but since gitolite is pretty simple to setup it won't hurt

  • My starting point is: we have all websites on the Production server, and not yet on the Staging server nor the Workstations. What is a convenient way of "pulling" them down to staging and workstations, at the initial setup?

For each of them you can simply execute these commands

cd /path/of/project
git init
# optionally create and edit your .gitignore file before the next step
git add .
git commit

and then from your staging server run a git clone command.

  • For simplicity I prefer to be able to run git push from the workstation and have both the staging server and production server updated. But sometimes it might be useful to only update the staging server and check out things over there first, before going live. Is there an easy solution?

I can't see an easy solution for this task, however I don't like your solution with automated production deployment, something could go bad and you'll break your production site, so I prefer citizen conn multiple remote solution. You can manage things better with gitolite and permission handling. Everybody can push on staging server but a restricted group of people can push to production server.

  • In reality we have not only one but several different production servers. But only one staging server. Is there a way of configuring different production servers so that git automatically pushes them out to the right server?

You could store your production server address in some text file in the project and then use the content of that file in your git hook.

like image 99
Fabio Avatar answered Oct 03 '22 23:10

Fabio


You don't want to run a git server on your production web server. And you really don't want your git repository files on your production server either. Personally I like to keep things simple and not mix up my deployment process with my SCM process.

So I guess I'm not going to answer your question about git, but I do use git for all my web projects, and here's the type of deployment setup I use:

I usually use git only for SCM, and use an internal server to host the repositories (this could very well be the same machine as the staging server).

For deployment, I usually use a rake script, since I like ruby. But a bash script would do just as well. The bash version would be something like this:

# deploy_staging.sh
rsync -va --delete --exclude-from excludes.txt ./ stagingserver:/htdocs/www.mysite.com/

# deploy_prod.sh
rsync -va --delete --exclude-from excludes.txt ./ realserver:/htdocs/www.mysite.com/

# deploy_all.sh
bash deploy_staging.sh || exit $?
bash deploy_prod.sh

# excludes.txt
.git
deploy_*.sh
excludes.txt

Developers that are authorized to publish to the servers have their SSH keys added to appropriate accounts on the server machines.

Nice and simple, easy to replicate, no messing around with setting up hooks, and everything is nicely contained in the repository, you have clear control over what gets deployed, and you can check it out and run deploy from anywhere that has the right network access.

like image 42
avh4 Avatar answered Oct 03 '22 22:10

avh4