LimeSoda Environment Configuration

This article is part of a series covering 3rd party n98-magerun modules/extensions.

The next article presents a solution to manage several developer, staging, production environements with a n98-magerun module and and a Magento module (can be installed at once).
If you have multiple Magento environments i.e. for all your developers you know the problem. Someone dumps a database and share it with another developer. Now every developer runs in the same boring issue. Changing the configuration according to the current environment. The list of configurations grows and grows… You know the problems.

At this point the solution of Limesoda can help you.

Installation

You need to install the file directly in your Magento installation via modman.

modman clone https://github.com/LimeSoda/LimeSoda_EnvironmentConfiguration.git

After the installation you must define the name of your config environment. This can be done in config.xml (in this case
the app/etc/local.xml file).

Define your dev-environment:

<config>
    <global>
        <limesoda>
            <environment>
                <name>dev</name>
            </environment>
        </limesoda>
    </global>
</config>

Default environment

Create a new Magento module to define a config. Add a global > limesoda > environments node to your config.xml file.

<?xml version="1.0"?>
<config>
    <global>
        <limesoda>
            <environments>
                 <default />
            </environments>
        </limesoda>
    </global>
</config>

This was easy! We have our first default environment defined.

Now we can run n98-magerun with the new embedded command.

n98-magerun.phar ls:env:configure default

The output is currently empty, because our environment has no commands defined.

Define commands

Now we extend the previous config and add some n98-magerun commands. You can call every n98-magerun command as batch.

<?xml version="1.0"?>
<config>
    <global>
        <limesoda>
            <environments>
                <default>
                    <commands>
                        <set_base_url>config:set web/unsecure/base_url http://magento.local/</set_base_url>
                        <set_sec_base_url>config:set web/unsecure/base_url http://magento.local/</set_sec_base_url>
                        <cf>cache:flush</cf>
                    </commands>
                </default>
            </environments>
         </limesoda>
    </global>
</config>

This calls two config settings and a cache flush sequentially.

Using variables

If you look at the previous example you see that we used the same url two times. Let’s create a varible for that and see how simple is is to use a variable.

<limesoda>
    <environments>
        <default>
            <variables>
                <base_url><![CDATA[http://magento.local/]]></base_url>
            </variables>
            <commands>
                <set_base_url>config:set web/unsecure/base_url ${base_url}</set_base_url>
                <set_sec_base_url>config:set web/secure/base_url ${base_url}</set_sec_base_url>
                <cf>cache:flush</cf>
            </commands>
        </default>
    </environments>
</limesoda>

Run n98-magerun again and you should see that output:

n98-magerun.phar ls:env:configure default
web/unsecure/base_url => http://magento.local/
web/secure/base_url => http://magento.local/
Cache cleared
FPC cleared

Nesting environments

This was very cool, but nesting the environments is really hot!
Let’s do it.
You can do it by adding the attribut parent to your environment definition in XML.

A typical setup could be:

.
├── default
│   ├── dev
│   │   ├── developer1
│   │   ├── developer2
│   │   └── developer3
│   ├── production
│   └── staging

Now we define this setup in our config:

<?xml version="1.0"?>
<config>
    <global>
        <limesoda>
            <environments>
                <default>
                    <!-- Commands etc. -->
                </default>
                <dev parent="default" />
                <developer1 parent="dev" />
                <developer2 parent="dev" />
                <developer3 parent="dev" />
                <staging parent="default" />
                <production parent="default" />
            </environments>
        </limesoda>
    </global>
</config>

The command processes your configs recursivly. That’s the power of the LimeSode Environment Configuration module.

If you like this way to manage your environments give the modules a change.
You can fetch the module from github.

https://github.com/LimeSoda/LimeSoda_EnvironmentConfiguration

One Pingback/Trackback