Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I make my repository my DocumentRoot for my website?

I setup mercurial on my server, but I am unclear how things should be. I am looking for more examples of different setups, but perhaps I am using the wrong keywords. Right now, it is only going to be a handful of developers, and I am unsure if I should just make the repo as the DocumentRoot. I really don't know what questions to ask since this is new to me, but I would appreciate it if anyone could provide some knowledge and guidance. Some questions that I do have right now is, how I should setup my servers and repositories? Should I setup a separate VirtualHost for a test clone before making it live? Anything would be helpful! Thanks in advance!

like image 408
Strawberry Avatar asked Feb 22 '12 23:02

Strawberry


3 Answers

There's probably not a reason to do this. I would keep them separate but set up an automated process (either a custom script or continuous integration (CI)) to deploy from Mercurial to the site by running a single command. Optionally, you can make every commit trigger a deployment.

EDIT: With continuous integration, it is the CI's server's responsibility for deploying. If you use SSH, the CI would pull from hg, export, then upload through SSH. That should address your issues. For a comparison of CI servers that support Mercurial, see this question.

like image 162
Matthew Flaschen Avatar answered Nov 19 '22 17:11

Matthew Flaschen


I don't have The answer to give you, since many variables and need affect the workflow, but here is some links to get you started :

  1. http://www.zdnetasia.com/a-development-workflow-for-mercurial-62204755.htm
  2. https://www.mercurial-scm.org/wiki/Workflows
  3. http://www.webdevelopment.nicholastuck.com/tools/one-project-one-repository-mercurial-used-right/

I will also recommend you to read this excellent Mercurial introduction : http://hginit.com/

You can also find various questions on SO about workflows with Mercurial, have a look on the sidebars to the right for example.

When you will have some more specific question, don't hesitate to ask again !

like image 34
krtek Avatar answered Nov 19 '22 18:11

krtek


I would make your DocumentRoot directory a first-level subdirectory of your repository, and here's some reasons why:

  1. If you're using something like Apache to manage your server, you could put other meta-information - like sites-available and sites-enabled configuration files - in a sibling directory, since they're not really a part of the website documents.
  2. Similarly, you can keep a "docs" directory right next to the code.
  3. If your repository root is your DocumentRoot, all other things being equal, you are also serving up your .hg directory, where your whole repository history is, and your .hgignore file, that kind of thing. You can fix this with a .htaccess file, of course, but it's simpler just to have the child folder.

Essentially, codebases tend not to be exactly one-to-one matches with deployed sites, so I tend to favor having the document root be a subdirectory.

Deployment is a whole 'nother can of worms. It really depends on your needs as to what you do, but here's what I do:

I run a VirtualBox instance on my computer that looks as close as possible to what my deployed server looks like, at least as close as I can get the configuration files to be. I would argue that this approach is less error-prone than an additional VirtualHost entry. Depending on the project, I can get this down to being identical minus perhaps some DNS entries, so I can set everything up to either point to testing.myproject or production.myproject, and this I always automate (I use chef, but that is overkill for a smaller project) so that it's testable code and not prone to finger-fumbling. There's nothing worse than running smoke tests that wipe your database - and have the config accidentally pointing to your prod db. Running a virtual machine lets you painlessly test upgrades to the environment or OS of your server, and you can nuke and restore to a snapshot if you want to go to an earlier state of the machine's configuration.

If you really want to prevent SSH developer access to your prod machines - and IMO, that's a bad idea, because if you have problems on your production server, you've prevented your developers from diagnosing or fixing it - then I think your best bet is to use something like hudson, which is a continuous integration framework. You only give ssh access to the Hudson user to run your deploy script, but anyone (with the right privileges set in Hudson) can run that job. In fact, this is handy to have in an environment where you have e.g. some product management members you want to have the ability to update the production server without being able to log in. The "poor man's" version of this is using sudo to allow your devs to run a command as another user who does have ssh access - and only allowing them to run the publish script.

I would still recommend giving your devs access to your machine, though you don't have to hand over the keys to the kingdom. Just create a "developers" group, assign your devs to it, and give it enough permissions to play with the necessary directories of the server, and you should be good to go.

like image 1
Matt Avatar answered Nov 19 '22 16:11

Matt