This discussion is archived
8 Replies Latest reply: Apr 21, 2013 10:10 AM by jschellSomeoneStoleMyAlias RSS

Traversing between dev and prod environments

800839 Newbie
Currently Being Moderated
Hi,

In my code base I need to switch on & off certain features based on the environment like "Dev" or "Prod". These configurations are coupled with the source code is there any where we can write a logic or using some configuration where we can switch "On" and "Off" the respective configuration for "Dev" and "Prod" ? What are the best ways of doing so? Having a flag or using a separate build.xml , etc please clarify.

Thanks.
  • 1. Re: Traversing between dev and prod environments
    gimbal2 Guru
    Currently Being Moderated
    I don't get it. Answering these kind of questions is your job. If you outsource that to a forum without even giving any kind of hint that you did some thinking yourself, you're basically admitting that you're failing.

    I can't believe that. What have you come up with yourself?
  • 2. Re: Traversing between dev and prod environments
    800839 Newbie
    Currently Being Moderated
    To make it clear:-

    When I switch between "Dev" and "Prod" env, I need to add or not add some configuration in the respective XML files used by both env. For example when I am in Dev env. I need to add certain configuration in the code, but when it is in PROD env. I do not need that change. Which is the best way to switch on & off , where on is for Dev and Off is for Prod env? I dont need the flag concept here. Please clarify.

    Thanks.
  • 3. Re: Traversing between dev and prod environments
    rp0428 Guru
    Currently Being Moderated
    >
    When I switch between "Dev" and "Prod" env, I need to add or not add some configuration in the respective XML files used by both env. For example when I am in Dev env. I need to add certain configuration in the code, but when it is in PROD env. I do not need that change. Which is the best way to switch on & off , where on is for Dev and Off is for Prod env? I dont need the flag concept here. Please clarify.
    >
    Use a different XML configuration file for each environment. Your code can read the configuration information and base its actions on the content.

    If that doesn't answer your question then you need to provide a specific example of what you mean.
  • 4. Re: Traversing between dev and prod environments
    800839 Newbie
    Currently Being Moderated
    Thanks. Having 2 different config XML one for "Dev" and other for "Prod" is fine. But how we load the XML config for "Dev" or "Prod" ? using a separate build.xml for these environments? or Is there any better way to load these? Please clarify.
  • 5. Re: Traversing between dev and prod environments
    rp0428 Guru
    Currently Being Moderated
    >
    Having 2 different config XML one for "Dev" and other for "Prod" is fine. But how we load the XML config for "Dev" or "Prod" ? using a separate build.xml for these environments? or Is there any better way to load these? Please clarify.
    >
    How to load the config file is up to you depending on your requirements.

    One way is to use a command-line argument when you launch your application: 'config_file=xxx'. Using that method you can change the configuration for each run of the app if you want.

    If the config is CONSTANT for the app but different for the environment then you would determine the correct config file to use when you build your deployment jars. The config file could even be a file within the jar.

    That can be accomplished by using a parameter for the build process. With ANT you would typically define a DEV target and a PROD target.
  • 6. Re: Traversing between dev and prod environments
    916903 Newbie
    Currently Being Moderated
    If you have 2 config files, you have to maintain two config files which can be dangerous, what happens if you add a property in dev then forget to add it in your prod one.

    A better approach is to use a proper build tool like maven, then set up profiles e.g dev/prd which filter their respective values into your one config file.

    config.xml
    env=${filter.env}

    dev_filter.properties
    filter.env=dev

    prd_filter.properties
    filter.env=prd
  • 7. Re: Traversing between dev and prod environments
    rp0428 Guru
    Currently Being Moderated
    Looks like you didn't bother to read my entire reply.
    >
    If you have 2 config files, you have to maintain two config files which can be dangerous, what happens if you add a property in dev then forget to add it in your prod one.
    >
    Yes - with 2 config files you have two files to maintain. But that is NOT 'dangerous'. What 'happens' will be what the code is designed to do for that property difference.
    >
    A better approach is to use a proper build tool like maven, then set up profiles e.g dev/prd which filter their respective values into your one config file.
    >
    Which is pretty much a duplicate of what I already said in my reply the last part of which was this:
    >
    That can be accomplished by using a parameter for the build process. With ANT you would typically define a DEV target and a PROD target.
    >
    This is the KEY PART of my reply which you apparently missed:
    >
    If the config is CONSTANT for the app but different for the environment then you would determine the correct config file to use when you build your deployment jars. The config file could even be a file within the jar.
    >
    It is very common for configuration parameters to differ IN VALUE ONLY, not in the number of properties. There are many examples of this: path names, IP addresses, port numbers, application server configuration parameters, etc.

    The number and names of those parameters are CONSTANT for the application but will have a DIFFERENT value depending on the environment.

    As I said in my reply, and you repeated, those can be incorporated into the build process.

    But you don't always want to rebuild an entire applicaton just to change to value of a parameter for testing or for a different environment.

    And using the build process doesn't eliminate the issue you mention. You still have to maintain two sections or files: one for DEV and one for PROD. And the information in the PROD section may contain sensitive information that a DEV developer should not even have access to. That means it will be in a separate location or maybe on a separate server.
  • 8. Re: Traversing between dev and prod environments
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    913900 wrote:
    A better approach is to use a proper build tool like maven, then set up profiles e.g dev/prd which filter their respective values into your one config file.
    And what happens if you build using the dev properties and then deliver that build into production? Certainly looks "dangerous" to me.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points