Json settings files supported in deployment

leecheneler1's Avatar

leecheneler1

20 Sep, 2016 10:53 AM

Hi,

So currently there is good support for setting xml settings via parameters.xml.

Would it be possible to add json support? A simple way to do this would be to mimic the route Asp.Net Core has taken with it's configuration API.

In a project you might have appSettings.json, then you could also create an appSettings.appveyor.json that is merged during deployment. It doesn't need to be a full copy of appSettings.json but could just contain a subset of it. This approach works really well in Asp.Net Core and is super simple to understand and maintain.

Thoughts?

Keep being awesome, thanks,
Lee

  1. Support Staff 1 Posted by Feodor Fitsner on 21 Sep, 2016 08:19 PM

    Feodor Fitsner's Avatar

    When parameters.xml is used it's "baked" into resulting Web Deploy package and then you can specify parameters during deployment. So, you can use the same immutable package and deploy it over and over to multiple environments.

    I'm not very familiar with appSettings.json - do they follow the same approach or it's build-time thing?

  2. 2 Posted by leecheneler1 on 21 Sep, 2016 09:43 PM

    leecheneler1's Avatar

    So they do it at runtime, but it would be amazing if you this could be done during an appVeyor deploy as json is the future, xml is dead in the water....

    Proposed solution

    You might have a json settings file appSettings.json with:

    {
       "first": "dev var",
        "second": {
            "third": "dev var"
        }
    }
    

    And then you could have an appveyor deployment json file next to it called appSettings.appveyor.json:

    {
       "first": "%Appveyor_Deployment_Env_Var%",
        "second": {
            "third": "%Appveyor_Deployment_Env_Var%"
        }
    }
    

    Then these 2 files are merged, with properties in the appveyor file overwriting any matching properties in the actual settings file. The way Asp.Net Core merges config you could just overwrite a small part of the config file like this:

    {
        "second": {
            "third": "%Appveyor_Deployment_Env_Var%"
        }
    }
    

    Asp.Net Core is making a huge push into the json space for configuration as its much more natural to express settings objects in json.

    Current solution we have in place

    Our current solution is the following:

    Deployment environment variables configured in appveyor.

    Node script to update the json settings called appSettings.appveyor.js:

    var fs = require('fs');
    patchSettings('appSettings.json');
    function patchSettings(jsonPath) {
        // parse file
    var json = fs.readFileSync(jsonPath, 'utf8'); var settings = JSON.parse(json.substring(json.indexOf('{'))); // apply settings settings.first = process.env.Appveyor_Deployment_Env_Var; settings.second.third = process.env.Appveyor_Deployment_Env_Var; // save file fs.writeFileSync(jsonPath, JSON.stringify(settings, null, '\t')); }

    Then we run that with a deploy.ps1 script during the appveyor deployment:

    node appSettings.appveyor.js
    
  3. Support Staff 3 Posted by Feodor Fitsner on 22 Sep, 2016 09:37 PM

    Feodor Fitsner's Avatar

    Thanks for your thoughts!

  4. 4 Posted by Alisson on 18 Jun, 2018 05:43 AM

    Alisson's Avatar

    How do we run this `deploy.ps1` script during the deployment?

  5. 5 Posted by Ilya Finkelshte... on 18 Jun, 2018 06:32 PM

    Ilya Finkelshteyn's Avatar

    @Alisson Can you clarify more about your deployment? Is it inline or environment deployment (difference described here)? Is it agent deployment?

  6. Owen McDonnell closed this discussion on 27 Aug, 2018 08:42 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac