Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to delete XML config transforms after applying #834

Closed
nblumhardt opened this issue Apr 1, 2014 · 14 comments
Closed

Option to delete XML config transforms after applying #834

nblumhardt opened this issue Apr 1, 2014 · 14 comments

Comments

@nblumhardt
Copy link
Contributor

@nblumhardt nblumhardt commented Apr 1, 2014

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

Lingering .config files cause issues for some applications.

@nblumhardt nblumhardt added this to the 2.4 milestone Apr 1, 2014
@PaulStovell
Copy link
Member

@PaulStovell PaulStovell commented Apr 1, 2014

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?

Loading

@PaulStovell PaulStovell added this to the 2.x Backlog milestone Apr 5, 2014
@PaulStovell PaulStovell removed this from the 2.4 milestone Apr 5, 2014
@nblumhardt
Copy link
Contributor Author

@nblumhardt nblumhardt commented Apr 10, 2014

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.

Loading

@daniellittledev
Copy link

@daniellittledev daniellittledev commented May 27, 2014

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.

Loading

@PaulStovell
Copy link
Member

@PaulStovell PaulStovell commented May 27, 2014

Perhaps something like the TeamCity approach of + and -?

+:*.config
-:*.log4net.config

Loading

@daniellittledev daniellittledev self-assigned this May 27, 2014
@daniellittledev
Copy link

@daniellittledev daniellittledev commented May 29, 2014

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

Loading

@nblumhardt
Copy link
Contributor Author

@nblumhardt nblumhardt commented May 29, 2014

@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.

Loading

@nblumhardt nblumhardt closed this May 29, 2014
@nblumhardt nblumhardt removed this from the 2.5 milestone May 29, 2014
@augustoproiete
Copy link

@augustoproiete augustoproiete commented Sep 3, 2014

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

Loading

@ehjelholt
Copy link

@ehjelholt ehjelholt commented May 5, 2015

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"
  }
}

Loading

@jo3stevens
Copy link

@jo3stevens jo3stevens commented Sep 11, 2015

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

Loading

@ehjelholt
Copy link

@ehjelholt ehjelholt commented Sep 11, 2015

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

Loading

@johndowns
Copy link

@johndowns johndowns commented May 26, 2016

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

Loading

@ehjelholt
Copy link

@ehjelholt ehjelholt commented May 26, 2016

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 :(

Loading

@aocampocogworks
Copy link

@aocampocogworks aocampocogworks commented Mar 21, 2017

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

Loading

@lock
Copy link

@lock lock bot commented Nov 25, 2018

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.

Loading

@lock lock bot locked as resolved and limited conversation to collaborators Nov 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants