Externalize targets configuration
As the number of deployment targets grows, the size of the deployment configuration file might become unwieldy. You can externalize the deployment target configurations outside the deployment configuration file to make the deployment configuration file more manageable. To do this, you need to define the deployment target repository in a takomo.yml file located in your project's root directory.
Load deployment targets from the filesystem
Currently, there is one target repository implementation. It loads deployment target configurations from a specified directory. To enable it, you need to add the following configuration to the takomo.yml file.
The type
property specifies that the target repository of type filesystem should be used to load the external targets configuration. The dir
property specifies the file path to the directory from where to load the configurations. The file path can be absolute or relative to the project's root directory. Finally, the inferDeploymentGroupPathFromDirName
property instructs Takomo to infer the target's deployment group from the name of the directory where the target's configuration file is located.
Takomo will look for .yml files from the specified directory and its subdirectories. You can name the files as you wish. Each file must contain a valid configuration for one deployment target. The configuration format is the same as if the target's configuration was given in the deployment configuration file. The only difference is that unless you set inferDeploymentGroupPathFromDirName
to true, you need to specify the target's deployment group with a deploymentGroupPath
property. All deployment groups referred in the external configuration files must be defined in the deployment configuration file, too.
Example
Let's continue with our example and see how to externalize the deployment targets to a separate directory.
First, we specify that we want to load configuration for our deployment targets from a my-targets directory located in our project's root directory.
Next, we extract the configuration for each of our target to separate files located in the my-targets directory.
As you can see, each deployment target specifies the deployment group where the target belongs to.
After our changes, the deployment configuration file looks like this:
And this is how our file system looks like:
Infer deployment group from a directory name
As mentioned earlier, you can use the inferDeploymentGroupPathFromDirName
property to instruct Takomo to infer the target's deployment group from the name of the directory where the target's configuration file is located. If you choose to use this option, you need to have a directory structure that mirrors your deployment group hierarchy. As a benefit, you can omit the deploymentGroupPath
property from the target files.
Example
Alright, let's convert our example to use the inferDeploymentGroupPathFromDirName
property.
The deployment configuration file deployment/targets.yml stays the same but we need to create a directory structure that mirrors our deployment groups under the my-targets directory and move the target files to correct subdirectories.
We can then remove the deploymentGroupPath
property from the target files.
Infer deployment targets' names from names of their config files
You can use the inferDeploymentTargetNameFromFileName
property to instruct Takomo to infer targets' names from the names of their configuration files. You can then omit the name
property from the target files.
The target name is inferred by removing the .yml file extension from the target's configuration file name.
Example
Let's add inferDeploymentTargetNameFromFileName
to our example.
Then just remove the name
property from configuration files of our targets.
Last updated