OctopusDeploy / Issues

| Public | Bug reports and known issues for Octopus Deploy and all related tools
https://octopus.com
162 stars 20 forks source link

Option to delete XML config transforms after applying #834

Closed nblumhardt closed 10 years ago

nblumhardt commented 10 years ago

Via http://help.octopusdeploy.com/discussions/questions/243-deleting-config-transformation-files-after-deploy

Lingering .config files cause issues for some applications.

PaulStovell commented 10 years ago

Given this file system:

Web.config
Web.Dev.config
Web.Prod.config
Web.Release.config

Assume we deployed to Prod. We would have run Web.Prod.config, and Web.Release.config. It's obvious those files should be deleted.

But how can we tell that Web.config should be kept, while Web.Dev.config shouldn't? I.e., how do we know which files are transforms and which files aren't?

Will the decision be based on the existence of:

xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"

On the root node?

nblumhardt commented 10 years ago

Perhaps we'd be better off introducing a Delete files feature, so you could just specify Web.*.config; Views\Web.*.config as the file list and match everything that needs to be cleaned up.

Doing it this way would be more generally useful, anyway.

daniellittledev commented 10 years ago

This feature will need a method to exclude files or be based off a white list. It's common to have other .config files match this pattern e.g. Web.log4net.config.

PaulStovell commented 10 years ago

Perhaps something like the TeamCity approach of + and -?

+:*.config
-:*.log4net.config
daniellittledev commented 10 years ago

Added Clean-Files PowerShell Step Template OctopusDeploy/Library#37

nblumhardt commented 10 years ago

@Lavinski I think that makes this item closeable, since the solution doesn't directly address what's on this ticket. Let's follow up via the PR.

augustoproiete commented 10 years ago

Hello guys, is there any chance of re-opening this issue? :)

The step template is a great workaround (thanks for that!) and I'm using it, but having to have an extra step on every single deployment process is very annoying.

I'd love to have a checkbox on the "Deploy a NuGet package" step, that matches all .config files that match *.any-of-my-environments.config or *.Release.config

ehjelholt commented 9 years ago

I have very easily achieved this using this script (based on the namespace as @PaulStovell suggests):

Script:

Write-Host 'Preparing to delete config transformation files in $TargetPath:' $TargetPath

function DeleteIfConfigTransformFile($file)
{
    try
    {
        $xdoc = New-Object System.Xml.XmlDocument
        $xdoc.Load($file)

        if($xdoc.DocumentElement.xdt -eq "http://schemas.microsoft.com/XML-Document-Transform")
        {
            Write-Host "Deleting file:" $file
            #Remove-Item $file
        }
        else
        {
            Write-Host "Not deleting config file (doesn't have the correct xdt xml namespace declaration):" $file
        }
    }
    catch
    {
        Write-Host "Could not xml parse file:" $file
    }

}

Get-ChildItem $TargetPath -Recurse | Where-Object { $_.Name -like "*.config" } | ForEach-Object { DeleteIfConfigTransformFile ($_.FullName) }

Note that it requires the files to be named *.config and the root element to be called "configuration". So only config transform files for now. This could be easily changes though.

Export of script template JSON:

{
  "Id": "ActionTemplates-5",
  "Name": "Delete Config Transform Files",
  "Description": "Recursively deletes all files underneath #{TargetPath} which has the extension .config, is parsable xml and has the namespace xmlns:xdt=\"http://schemas.microsoft.com/XML-Document-Transform\" defined.",
  "ActionType": "Octopus.Script",
  "Version": 7,
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "Write-Host 'Preparing to delete config transformation files in $TargetPath:' $TargetPath\r\n\r\nfunction DeleteIfConfigTransformFile($file)\r\n{\r\n    try\r\n    {\r\n        $xdoc = New-Object System.Xml.XmlDocument\r\n        $xdoc.Load($file)\r\n\r\n        if($xdoc.DocumentElement.xdt -eq \"http://schemas.microsoft.com/XML-Document-Transform\")\r\n        {\r\n            Write-Host \"Deleting file:\" $file\r\n            Remove-Item $file\r\n        }\r\n        else\r\n        {\r\n            Write-Host \"Not deleting config file (doesn't have the correct xdt xml namespace declaration):\" $file\r\n        }\r\n    }\r\n    catch\r\n    {\r\n        Write-Host \"Could not xml parse file:\" $file\r\n    }\r\n    \r\n}\r\n\r\nGet-ChildItem $TargetPath -Recurse | Where-Object { $_.Name -like \"*.config\" } | ForEach-Object { DeleteIfConfigTransformFile ($_.FullName) }"
  },
  "SensitiveProperties": {},
  "Parameters": [
    {
      "Name": "TargetPath",
      "Label": "Target path",
      "HelpText": "The path to clean.\n\nUsually you would set this to `Octopus.Action[StepName].Output.Package.InstallationDirectoryPath`.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "LastModifiedOn": "2015-05-05T14:26:52.105+00:00",
  "LastModifiedBy": "epe@dis.dk",
  "$Meta": {
    "ExportedAt": "2015-05-05T14:27:29.530Z",
    "OctopusVersion": "2.6.5.1010",
    "Type": "ActionTemplate"
  }
}
jo3stevens commented 9 years ago

Thanks @donesbon. I'm using Sitecore which has many config files the other step template deleted, but yours did the job.

ehjelholt commented 9 years ago

@jo3stevens I used it wit Sitecore too. Glad it worked for you

johndowns commented 8 years ago

Is there a version of this that would work with an Azure web app deployment?

ehjelholt commented 8 years ago

Hi @johndowns I haven't worked with Octopus or deployment of any kind for a long long time (or Azure for that matter). I won't be of any help :(

aocampocogworks commented 7 years ago

Would be great to implement this as par of the deployment step for IIS websites and Azure webapps, I think this is something we all need. /cc @PaulStovell

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you think you've found a related issue, please contact our support team so we can triage your issue, and make sure it's handled appropriately.