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

Comments

@nblumhardt
Copy link
Contributor

commented Apr 1, 2014

@nblumhardt nblumhardt added this to the 2.4 milestone Apr 1, 2014

@PaulStovell

This comment has been minimized.

Copy link
Member

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?

@PaulStovell PaulStovell modified the milestones: 2.x Backlog, 2.4 Apr 5, 2014

@nblumhardt

This comment has been minimized.

Copy link
Contributor Author

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.

@daniellittledev

This comment has been minimized.

Copy link

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.

@PaulStovell

This comment has been minimized.

Copy link
Member

commented May 27, 2014

Perhaps something like the TeamCity approach of + and -?

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

@daniellittledev daniellittledev self-assigned this May 27, 2014

@daniellittledev

This comment has been minimized.

Copy link

commented May 29, 2014

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

@nblumhardt

This comment has been minimized.

Copy link
Contributor Author

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.

@nblumhardt nblumhardt closed this May 29, 2014

@nblumhardt nblumhardt removed this from the 2.5 milestone May 29, 2014

@nblumhardt nblumhardt added the wontfix label May 29, 2014

@caioproiete

This comment has been minimized.

Copy link

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

@ehjelholt

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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.

@ehjelholt

This comment has been minimized.

Copy link

commented Sep 11, 2015

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

@johndowns

This comment has been minimized.

Copy link

commented May 26, 2016

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

@ehjelholt

This comment has been minimized.

Copy link

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

@aocampocogworks

This comment has been minimized.

Copy link

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

@lock

This comment has been minimized.

Copy link

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.

@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
8 participants
You can’t perform that action at this time.