[horde] Runtime configuration switching

Greg Rundlett grundlett at savaje.com
Mon Sep 26 15:24:16 PDT 2005


Lennon Day-Reynolds wrote:

>In general, the Horde apps we use (core, Ingo, Imp, Turba) have been great to
>work with, but one feature that I've found consistently missing is a way of
>maintaining multiple "deoplyment images", such as "development", "testing", and
>"production", and switching between them without having to manually track down
>all the places in the global and per-app configuration where a path, hostname,
>etc., might be located.
>
>If you've configured Apache, you should have some idea what I mean: instead of
>putting everything in a single, flat configuration, you can switch between
>various configuration sets based on the current hostname or URL patterns. My
>goal is to keep a single version-controlled source tree checked out and
>synchronized on my development workstation, test server, and production server,
>without having to manually swap out configuration files for each environment.
>
>I've made some headway on a one-off, hackish solution to this problem for our
>environment here, but since I can't believe I'm the first to need this kind of
>functionality, I wanted to poll the group to see what solutions other Horde
>admins and hackers have used to address this issue. It seems to me that the
>dev/test/publish cycle for most sites could be sped up significantly with some
>sort of runtime configuration switching available across the Horde codebase.
>
>Thanks in advance,
>
>Lennon Day-Reynolds
>
>System Support Specialist
>Technology Infrastructure Services
>Reed College
>
>  
>
The way that i do it is to add to the BOTTOM of horde/config/conf.php 
Not only do i setup multiple environments, but I even switch depending 
on whether my horde application is being run from the command line so 
that I can skip authentication for (cron) scripted interaction with the 
application.

E.g. starting with line 80 of my conf.php

//* CONFIG END. DO NOT CHANGE ANYTHING IN OR BEFORE THIS LINE. *//

//**/
/ * Here we override some settings from the gui, so as to set values according to/
/ * which environment we're in without having to keep separate copies of this file
/ /* /
/ * The configuration allows for growing the list of available proxies/
/ * We can also grow the list of available environements (like staging)/
/ * and it already includes a 'localhost' environment which hopefully will/
/ * allow us to get working on a local environment with fewer dependencies/
/ */
/ * Each "Application Server" can be set individually for fine-tuning the /
/ * working environment to suit test needs.  Since we use VirtualHost containers/
/ * in Apache to define our Server, we can switch off the $_SERVER['SERVER_NAME']/
/ * to read in our settings at runtime./
/ *//

$proxies = array(
    'proxy'  => 'proxy.savaje.com',
    'proxy2' => 'proxy-2.savaje.com',
);

/// we can grow the list of available environments/
/// and tweak settings on an individual environment basis/
$appServerSettings = array (
    'production' => array(
        'useProxy' => *true*,
        'proxy' => $proxies['proxy'],
        'proxyAlias'=> 'ab2',
        'useAuth' => *true*,
        'sql'=> array(
            'persistent' => *false*,
            'hostspec' => 'localhost',
            'username' => 'horde',
            'password' => 'secret',
            'socket' => '/tmp/mysql.sock',
            'protocol' => 'unix',
            'database' => 'horde',
            'charset' => 'iso-8859-1',
            'phptype' => 'mysql'
        ),
    ),
    'development' => array(
        'useProxy' => *true*,    
        'proxy' => $proxies['proxy2'],
        'proxyAlias'=> 'ab-dev',
        'useAuth' => *true*,/// should normally be true/
        'sql'=> array(
            'persistent' => *false*,
            'hostspec' => 'localhost',
            'username' => 'horde',
            'password' => 'secret',
            'socket' => '/tmp/mysql.sock',
            'protocol' => 'unix',
            'database' => 'horde-dev',
            'charset' => 'iso-8859-1',
            'phptype' => 'mysql'
        ),
    ),
    'localhost' => array(
        'useProxy' => *false*,    
        'proxy' => *null*,
        'proxyAlias'=> *null*,
        'useAuth' => *false*,
        'sql'=> array(
            'persistent' => *false*,
            'hostspec' => 'localhost',
            'username' => 'horde',
            'password' => 'secret',
            'socket' => '/tmp/mysql.sock',
            'protocol' => 'unix',
            'database' => 'horde',
            'charset' => 'iso-8859-1',
            'phptype' => 'mysql'
        ),
    ),
    'command line' => array(
        'useProxy' => *false*,    
        'proxy' => *null*,
        'proxyAlias'=> *null*,
        'useAuth' => *false*,
        'sql'=> array(
            'persistent' => *false*,
            'hostspec' => 'localhost',
            'username' => 'horde',
            'password' => 'secret',
            'socket' => '/tmp/mysql.sock',
            'protocol' => 'unix',
            'database' => 'horde',
            'charset' => 'iso-8859-1',
            'phptype' => 'mysql'
        ),
    ),

);

/// create an environment where we can run command line scripts and not use /
/// authentication/
if (php_sapi_name() == 'cli') {
    $envType = 'command line';
    $conf['server']['name'] = "{$proxies['proxy']}/ab2/";
} else {
    /// our setups are based on the virtual host settings/
    /// the $_SERVER['SERVER_NAME'] will not be set in CLI environment, and /
    /// without a isset check, we'd get a warning, so set it to something innocuous/
    if(!isset($_SERVER['SERVER_NAME'])) $_SERVER['SERVER_NAME'] = 'localhost';
    switch ($_SERVER['SERVER_NAME']) {
        case 'ab.dev.example.com':
            $envType = 'development';
            break;
        case 'ab.example.com':
            $envType = 'production';
            break;
        case localhost:
        *default*:
            $envType = 'localhost';
            break;
    }
}


$useProxy   = $appServerSettings[$envType]['useProxy'];
$proxy      = $appServerSettings[$envType]['proxy'];
$proxyAlias = $appServerSettings[$envType]['proxyAlias'];
$useAuth    = $appServerSettings[$envType]['useAuth'];

if (!$useAuth) {
    $conf['auth']['driver'] = 'auto';
    $conf['auth']['params']['username'] = 'staticUser';
    $conf['auth']['params']['password'] = '';
    $conf['auth']['params']['requestuser'] = *false*;    
}
/// make our environment settings flow through to horde settings/
if($useProxy === *true*) {
    $conf['use_ssl'] = 1;
    $conf['server']['name'] = "$proxy/$proxyAlias";
    $conf['server']['port'] = '443';
    $conf['cookie']['domain'] = $proxy;
    $conf['cookie']['path'] = '/';
    $conf['logo']['link'] = "https://$proxy/$proxyAlias/";
}

/// map all the db settings through to horde/
foreach ($appServerSettings[$envType]['sql'] as $key=>$value) {
  $conf['sql'][$key] = $value;
}



-- 
Greg Rundlett

Release Engineering Team
SavaJe Technologies
(978) 259-2029

[random sig fortune]
The Rabbits				The Cow
Here is a verse about rabbits		The cow is of the bovine ilk;
That doesn't mention their habits.	One end is moo, the other, milk.
		-- Ogden Nash



More information about the horde mailing list