In my last post I discussed using a domain model of the environment to give clarity around the architecture of an application, in a way that allows acceptance tests to be written in a technology agnostic way.
Last time I discussed the case where there were two environments – a local in-memory version, and a UAT version. I created Java class for each one, to illustrate the example.
In this post, I want to discuss what happens when you put a scripting language on top of this domain model.
When dealing with complex architectures or big teams, there are many shared environments, or at least, common infrastructure. Ideally, the staging and production environments should differ ONLY by configuration.
By using a scripting language (such as ruby) to define your environments you quickly customize an environment without having to rebuild your enterprise manifest.
For instance:
prod.config.rb:
database_host :main_ora_server do host ip("10.1.2.3") version "10.1" tools_dir "/opt/ora/10.1/bin" end database_schema :user_service_schema do schema_name "e_users" user_name "scott" password "tiger" host :main_ora_server migrations zip("user_schema/migrations") end webapp :web_ui do artifact war( "web-ui.war" ) environment do user_datasource :user_service_schema end end %w( web1, web2, web3, web4 ).each do | w | w_ip = #function on w webserver w.to_sym do host ip( "10.2.3.#{w_ip}" ) hosts_webapp :web_ui end end
From this configuration, I’m intending to deploy a web app to 4 servers each with one web app, all pointing at the same database. I’ve also defined a migration script for that database.
This is quite similar to a capistrano configuration, except in this case I’m not actually do the deployment – I’m defining it, and allowing the same configuration to be used in different contexts. For instance, I may have a monitoring tool which takes the same file and pings each service. I may generate a diagram. Each of these semi-fictional tools would be invoked in a similar way:
deploy prod.config.rb enterprise-mainfest-1.2.6 monitor prod.config.rb service-agent@jabberd.myco visualize prod.config.rb target-dir
This config file can be placed in your favourite version control system, merged, diffed, and generally munged. It’s clear enough that both devs and sys admins can talk about it, and it encourages differences in environments to be encapsulated.
In general, the power of having a rich domain model means that you can share knowledge across the team AND ensure high fidelity of that information
Of course, the above domain model won’t be exactly what you need, but if you start off with a simple model, and use other agile infrastructure techniques, then you’ll find you can evolve a domain model which is JUST rich enough for your purposes.