Environment as code using Deployfile

XL Deploy 7.1.0 introduces the environment-as-code feature, which enables you to store information about your infrastructure and environments in a Deployfile, a Groovy file that you can store in source control. This feature allows you to maintain and update environment and infrastructure information outside of the XL Deploy repository, where it can be updated by multiple teams or automatically updated by infrastructure automation tools.

The Deployfile

The Deployfile is a Groovy file that describes the desired state of infrastructure, environment and/or application configuration items (CIs) in the XL Deploy repository. When an application is included, the configuration item will be created and the application will be deployed to the target environment.
In the Deployfile, you define the CIs that should exist, their properties, and their relationships with other CIs; when you apply the Deployfile using the REST API or command-line interface (CLI), XL Deploy determines whether CIs need to be created, deleted, or modified to achieve the state described in the Deployfile.

Every CI or set of CIs must be defined in the Deployfile using the define syntax, which creates the directory where CIs are created or modified, or from where CIs can be deleted. The define syntax ensures that you do not inadvertently change or delete CIs that are not related to the Deployfile. The Deployfile also supports setting or changing local permissions on the directory or directories that are defined.

The Deployfile determines whether a CI or set of CIs should be created under the Environments or Infrastructure parent node in the repository, as identified by the forEnvironments and forInfrastructure keywords.

Note: At this time, the Deployfile cannot be used to define CIs under Configuration.

Sample Deployfile

This is a sample Deployfile that defines a docker.SwarmManager CI, an environment, and a dictionary.

Generate a Deployfile

An easy way to get started with the Deployfile format is to generate Deployfiles from the directories that are already defined in your XL Deploy repository. You can use the XL Deploy REST API, the command-line interface (CLI), or the default graphical user interface to generate Deployfiles. To generate a Deployfile, you must have the generate#dsllocal permission.

Note that:

You can only generate a Deployfile from a directory or directories, not from the Environments or Infrastructure parent node.

Nested directories are defined as separate structures within the Deployfile.

When you generate a Deployfile that contains an enum CI property, the property value will contain the full Java name. For example, you can specify the value unix for the os property on an overthere.SshHost CI, but when the Deployfile is generated, the value will be com.xebialabs.overthere.OperatingSystemFamily.UNIX. You can also use the full Java name when applying a Deployfile.

Generate a Deployfile using the user interface

Hover over a folder, click , and then select Generate Example Deployfile. A .groovy file is generated and saved on your local machine.

Apply a Deployfile

You can use the XL Deploy REST API or the command-line interface (CLI) to apply Deployfiles to the XL Deploy repository. To apply a Deployfile, you must have the repo#editlocal permission in the parts of the repository affected by the Deployfile.

Note: For security reasons, Deployfiles are applied in a sandbox that does not have access to XL Deploy APIs.

Apply a Deployfile using the Lightweight CLI

To apply a Deployfile, open a command terminal and execute this command: