views:

42

answers:

2

I am using mercurial for website development. I "think" I'm using it correctly.

I develop on my development machine, commit fairly regularly. I will somewhat regularly push my commits to my hosted site-dev repository.

If things are set up how I want them for the live site, I push from my dev machine to the hosted site-live repository. Then I pull down from that repository onto the live server.

However, there are some changes that need to be made (changing directories from localhost to www.example.com, changing the DB connection stuff, etc.).

What I did was made these changes on my live machine, then pushed them back up to the site-live repository. I don't know why I did that, really, but at least there's a changeset sitting there with the necessary config changes.

What I don't know how to do is manage this process. I'm a little lost beyond committing, pushing and pulling with hg. I'm a single developer and haven't even done a merge yet.

Is there some way to keep that particular changeset identified, and just apply it, hopefully even BEFORE I pull from the repo down to the live server?

I think you can tell from my question that I'm in a little over my head with hg and workflow at the moment ;)

+4  A: 

This is my understanding:

What essentially you are trying to do is have a development, staging and deployment environment. You do your development using 'development' repository, test it on a staging environment and then once satisfied, pull those changes into deployment repository. And when you pull from staging to deployment, you need to change your environment / configuration data.

My take is you should not be changing the configuration at all.

You should have configuration files such that you have a

  1. basic configuration file

    basic.conf

  2. Environment specific overrides

    basic.dev.conf, basic.staging.conf and basic. deployment.conf

  3. Use environment variable:

    The overrides to the basic configuration data should be defined via an environment
    specific variable : APP_ENV : dev or staging or deploy

This way you should be able to override the configuration based on the environment without changing the configuration information.

It is not a good idea to rely on making changes to config files each time you pull your code from development to staging to deployment.

pyfunc
Yes, I figured it was a bad idea! :) I think I can figure out how to change all my php stuff based on querying the environment and using a different config file based on the result. Where I think I'd be stuck is the .htaccess file. I'm assuming that would all be done through Apache somehow?
neomech
@neomech: You could keep out or you could keep live server in version control. But create a mechanism for configuration overrides based on env and you would have a perfect workflow.
pyfunc
Okay, I'm going to head in that direction. I think I'll just stick the .htaccess file in the .hgignore list, modify as necessary for the various envrionments. The other configuration changes I can deal with through php getenv and if statements (I think). Thanks for the feedback.
neomech
+2  A: 

I would keep the live server outside the version control. Meaning that I would have a small "install" script that pulls updates from the repository, removes any unnecessary development files, and applies the correct configuration files. Both development and production configuration files should be in version control.

Morgan
Making an install script is currently beyond my capabilities, but I will take a look at it down the road. Thanks!
neomech
In my experience it is better to start with the install script for a product at the beginning, and update it every time when some new special condition comes in. Doing it at the end is more cumbersome, since you need to append all the special cases a long time after they emerged.
Rudi