I have some Java projects that use Apache Commons Configuration and they get deployed to multiple servers in multiple environments (dev/test/prod).
All code is the same, but some config items change, such as JMS URLs (dev should point to dev, etc) as well as the server name and environment (I use these config items for debugging).
Example:
<config>
<!-- environment can be dev|test|prod -->
<environment>dev</environment>
<serverName>myServer1</serverName>
<jmsUrl>http://my-jms-url-dev1,http://my-jms-url-dev2</jmsUrl>
</config>
Currently, I deploy, build, then edit the files manually to provide the server-specific configurations. I want a way to automate this when I deploy it to individual servers, but all the ways I’ve considered require an equal amount of pain to setup.
-
ANT – Check out the project with SVN and build it on each server with ANT. ANT reads the server name and the environment from two static files – .servername and .environment – and copies a server-specific config to the generic config. The problem with this is, I still have to create a config file for each server (I have 24 servers, and this may increase, so scalability is not good).
-
SVN – Branch each of my projects to a server-specific distribution. Here, scalability is worse and it becomes a nightmare to maintain.
Does anybody have any tips for me?
I figured this out.
Step 1.
Get the host name:
Step two, create a template file and use to copy the file and do a find/replace on it:
The .servername.template file contains this string:
Then, I use a web service to get a JSON string to tell me what environment I’m in. And I use the task to process the JSON and get the environment.
Pretty heavy-duty for such a simple task, but it works!