Skip to content

The Usage of Absolute and Relative paths in Units ΒΆ

As Cluster.dev is a code-generation utility, applying or destroying units involves executing commands in temporary directories. Accordingly, referencing files or directories from the template or config stack poses challenges. In templates, it's recommended to use relative paths. Given that units are executed in dynamically generated temporary directories, absolute paths may not be relevant. To address this issue, we introduced special functions: workDir and templatePath.

The functions return the absolute path to the project/template's working directory. While this addresses part of the issue, other difficulties arise due to the absolute path potentially changing in different environments (such as different users on their workstations, pipelines, etc.). If a path is used as input to a unit, such changes are treated as modifications in the unit state, triggering the apply command even when the actual content of the unit has not changed. Although not critical, this error incurs additional time and inconvenience.

We recommend avoiding the use of paths as unit parameters. Instead, consider using the readFile function to directly include the file's content in the unit. This approach ensures that changes in the path do not impact the unit's state since the function reads the content of the file, making the path irrelevant to state changes.