Mercurial - keeping deployed and development repositories
I am working on a PHP website where I have just added a switch for what environment it is running in - development
f开发者_开发问答or when it is running on my local site, and production
when it is running live on the web host:
<?php
define('ENV','development');
//or
define('ENV','production');
I have the site under VC with Mercurial, and usually simply deploy my site with hg push
(the server runs hg too), however, with the addition of this switch, the "production" site will always differ from the "development" site in that the version deployed live will always be set to production
instead of development
.
This means my deployment process goes from
- Develop
- Test
hg commit -m "Made changes"
hg push
ssh host hg update
- Go to 1.
to
- Develop
- Test
hg commit -m "Made changes"
- Change
development
toproduction
- `hg commit -m "dev -> prod"
hg push
ssh host hg update
- (later:) Change
production
->development
hg commit -m "prod -> dev"
- Go to 1.
Which is obviously not great.
Is there some way to keep one insulated from the other, so that the live site will always be set to production
and my local copy set to development
?
Instead of having a switch, have a development branch and a production branch.
hg up prodbranch
hg merge -r devbranch
hg push
ssh yourserver hg update prodbranch
If you have an Apache webserver, you could just set this in server/vhost/per-directory/.htaccess config:
SetEnv Deployment development
Or in production
SetEnv Deployment production
And in your script use:
define('ENV',$_ENV['Deployment'])
I assume (as it usually is) that the actual webserver / virtualhost config is outside the normal code.
http://httpd.apache.org/docs/2.2/mod/mod_env.html#setenv
Have you thought about just not putting your conifguration file under version control?
精彩评论