configure app for multiple workstations local / dev, test, prod osx and pc

I am new to coldbox and after attending cfunited 2010 I am working to
rollout 3.0 for a new backend to our internal application.

I am trying to figure out where/how is the preferred process to handle
multiple workstations running the app locally for develop i.e. making
it os agnostic and servers that could have different configs.

basically in the older version of the app there is a giant switch
statement that handles /detects what type of machine you are on and
sets up the application correctly.

any pointers examples of this would be very helpful :stuck_out_tongue:

tyvm,

chris

The environment control interceptor is your friend here but the
default that ships with ColdBox is based on request URLs rather than
hostnames.

Here's a version that uses the native hostname:

component extends="coldbox.system.interceptors.EnvironmentControl" {

  public string function detectEnvironment( array environmentsArray ) {
    // the environment cannot change during the application's life so we
can cache this:
    if ( structKeyExists( variables, 'selectedEnvironment' ) ) {
      setSetting( 'ENVIRONMENT', variables.selectedEnvironment );
      return variables.selectedEnvironment;
    }
    
    var myHost = createObject( 'java', 'java.net.InetAddress'
).getLocalHost().getHostName();
    // force development unless we find a match for production:
    var environment = 'development';
    var logger = logbox.getLogger( this );
    logger.debug( 'myHost=' & myHost );
    
    for ( var i = 1; i <= arrayLen( arguments.environmentsArray ); ++i ) {
      var hostPatterns = trim( arguments.environmentsArray[ i
].XMLAttributes.hosts );
      for ( var j = 1; j <= listLen( hostPatterns ); ++j ) {
        if ( REFind( listGetAt ( hostPatterns, j ), myHost ) != 0 ){
          environment = trim( arguments.environmentsArray[ i ].XMLAttributes.name );
          // update the ColdBox ENVIRONMENT setting:
          setSetting( 'ENVIRONMENT', environment );
          logger.debug( 'Environment ' & environment & ' selected.' );
          if ( find( 'development', environment ) == 0 ) {
            var cats = logBox.getConfig().getAllCategories();
            var cat = 0;
            for ( cat in cats ) {
              if ( cats[ cat ].levelMax > logBox.logLevels.INFO ) {
                logger.debug( 'Non-Development: reset levelMax for ' & cats[
cat ].name );
                cats[ cat ].levelMax = logBox.logLevels.INFO;
              }
            }
          }
          variables.selectedEnvironment = environment;
          return environment;
        }
      }
    }
    // update the ColdBox ENVIRONMENT setting:
    setSetting( 'ENVIRONMENT', environment );
    logger.debug( 'Environment ' & environment & ' defaulted.' );
    variables.selectedEnvironment = environment;
    return environment;
  }
  
}

Here's how to declare it in coldbox.xml:

    <!-- USE ENVIRONMENT CONTROL -->
    <Interceptor class="ws.model.interceptors.EnvironmentControlByHost">
      <Property name='configFile'>config/environments.xml.cfm</Property>
    </Interceptor>

Here's a fragment of the environments.xml file:

<environment name="development-charlie" urls="unused"
hosts="charlie-griefers,mycingular.net">
  <!-- where email bounces should go to -->
  <Setting name="BounceEmail" value="charlie@....com" />
  ...
</environment>

<environment name="development-mark" urls="unused" hosts="markdrew">
  <!-- where email bounces should go to -->
  <Setting name="BounceEmail" value="mark@....com" />
...
  <IOC>
    <Framework type="coldspring" reload="false"
objectCaching="false">config/ColdSpring.xml.cfm</Framework>
  </IOC>
</environment>

<environment name="development-sean" urls="unused"
hosts="Sean-Corfields,scorfield,myvzw.com">
  <!-- where email bounces should go to -->
  <Setting name="BounceEmail" value="sean@....org" />
...
  <!-- testing settings -->
  <Setting name="DebugMode" value="true" />
</environment>

Just find some string that's unique for each machine. My entry has
parts of my desktop and my laptop machine names. The .com / .net stuff
in Charlie's and mine are so it works properly if we're connected via
our broadband cards - fortunately we're on different ISPs and we're
the only two devs who work on the road!

HTH,
Sean

Oh, and I should mention that it also dynamically forces the highest
logging level to INFO unless you're on development so you can use
DEBUG to your heart's content and not worry about it ever showing up
in production!

If you are using the ColdBox.cfc config in ColdBox 3, then you can add a custom environment detection to the ColdBox.cfc like so:

// custom code to detect environment by hostname. must return a string
string function detectEnvironment()
{
return createObject( ‘java’, ‘java.net.InetAddress’ ).getLocalHost().getHostName();
}

// John’s dev box is called amber
void function amber()
{
// custom settings for this environment
coldbox.debugMode = true;
coldbox.handlerCaching = false;
coldbox.eventCaching = false;
coldbox.debugPassword = “”;
coldbox.reinitPassword = “”;
}

http://wiki.coldbox.org/wiki/ConfigurationCFC.cfm#Custom_Environment_Detection

I believe it is a lot simpler than that.

In your Coldbox.cfc you can do this.

// environment settings, create a detectEnvironment() method to detect it yourself.

// create a function with the name of the environment so it can be executed if that environment is detected

// the value of the environment is a list of regex patterns to match the cgi.http_host.

environments = {

development = “127.0.0.1,localhost,dev.mydomain.com

};

Then add a function called development and add the extra configs for that environment in that function.

Regards,

Andrew Scott

http://www.andyscott.id.au/

Hi Andrew,

Yes that is the way ColdBox does it out of the box. I believe the original question and the example Sean posted was using the computer name, not the host name, so that a dev team can all work off their “localhost” but have different setups based on computer name.

Of course I might have missed the point completely! :slight_smile:

  • John

Sean - I like where this is going, but I am considering using an ini
file external to the configuration and svn code repo so it can be
completely dynamic, would you recommend a different method of handling
this? I was thinking of using an includes/helpers/ method that would
read the ini named ApplicationConfig.cfm for the required pathing,
dbname, etc, core settings that could be different per server/local
desktop setup for both windows and osx boxes.

thoughts?

I figured I would add a method to the config Coldbox.cfc method in
3.0M6 that would call the helper that would read that file and modify
the config variables, this way its only called when the application
loads or is refreshed.