[Attempt to improve formatting]
We are currently in the process of considering a migration from our internal deployment scripts to Octopus. We are testing using Octopus 3.0.15.2418. So far, so good, but I am faced with a challenge around my client’s use of configuration files.
We are deploying a mixture of C# and Java based Windows Services, click once apps, web apps and web services.
My client has its own strategy for handling configuration replacement. This is done at the file replacement level (with variable substitution done at runtime). They currently do not want to change this approach.
For any target configuration file foo.config there are a number of rules to determine the name of the file that should be used as the source configuration file candidate. Once located, the source configuration file is copied, using the name of the target configuration file.
As an example, consider the following example source config file names for a target configuration file named foo.config:
1/ foo_MACHINE.config
2/ foo_ENVIRONMENT.config
3/ foo_CATEGORY.config
Where:
MACHINE is the target machine name that the service will run on
ENVIRONMENT is the environment that the component is being deployed to (E.G. dev4)
CATEGORY is the category of the environment being deployed to (E.G. env dev4 => category dev, env uat2 => category uat)
The candidate source configuration file is determined on the existence of such a file and the list of candidates is in the order shown above, with the first file match winning. Thus, assume the following:
MACHINE = JUPITER
ENVIRONMENT = dev4
CATEGORY = dev
File.Exists(“foo_JUPITER.config”) => false
File.Exists(“foo_dev4.config”) => true
File.Exists(“foo_dev.config”) => true
In the above example, the first successful file match is against foo_dev4.config and this would be copied as foo.config (overwriting the existing foo.config file).
I can think of one way that I believe would achieve the above and that is to have a custom powershell step that runs during the “Deploy a NuGet package” action, before the Octopus configuration file replacement step occurs. That custom powershell step would run the rules to determine the name of the source config file and set that config file name as an output variable. This output variable would be used in the configuration file replacement step, allowing Octopus to do the correct config file replacement.
Assuming that the above is a valid approach, I have the following questions:
1/ I am assuming that the powershell script should run as the “Pre-deployment script” part of the NuGet package step
2/ All of the candidate (source) configuration files are stored in a sub-folder of the NuGet package call ConfigurationFiles. Currently, Octopus is copying this folder to the target application directory as a part of the install. Clearly, I need the folder (and its contents) to be present in the NuGet package in order to determine which configuration file to pick as a source. My question is: How do I prevent this folder from being deployed to the final application directory*?
Thanks and looking forward to your reply,
James