# Template Registries DM lets configurations instantiate [templates](../design/design.md#templates) using both [imports](../design/design.md#template-imports) and [references](../design/design.md#template-references). Because template references can use any public HTTP endpoint, they provide a way to share templates. While you can store templates anywhere you want and organize them any way you want, you may not be able to share them effectively without some organizing principles. This document defines conventions for template registries that store templates in Github and organize them by name and by version to make sharing easier. For a working example of a template registry, please see the [Kubernetes Template Registry](https://github.com/kubernetes/application-dm-templates). ## Template Versions Since templates referenced by configurations and by other templates may change over time, we need a versioning scheme, so that template references can be reliably resolved to specific template versions. Every template must therefore carry a version based on the [Semantic Versioning](http://semver.org/) specification. A template version consists of a MAJOR version, a MINOR version and a PATCH version, and can be represented as a three part string starting with the letter `v` and using dot delimiters between the parts. For example `v1.1.0`. Parts may be omitted from right to left, up to but not include the MAJOR version. All omitted parts default to zero. So, for example: * `v1.1` is equivalent to `v1.1.0`, and * `v2` is equivalent to `v2.0.0` As required by Semantic Versioning: * The MAJOR version must be incremented for incompatible changes * The MINOR version must be incremented functionality is added in a backwards-compatible manner, and * The PATCH version must be incremented for backwards-compatible bug fixes. When resolving a template reference, DM will attempt to fetch the template with the highest available PATCH version that has the same MAJOR and MINOR versions as the referenced version. However, it will not automatically substitute a higher MINOR version for a requested MINOR version with the same MAJOR version, since although it would be backward compatible, it would not have the same feature set. You must therefore explicitly request the higher MINOR version in this situation to obtain the additional features. ## Template Validation Every template version should include a configuration named `example.yaml` that can be used to deploy an instance of the template. This file, along with any supporting files it requires, may be used automatically in the future by a template testing framework to validate the template, and should therefore be well formed. ## Template Organization Technically, all you need to reference a template is a directory at a public HTTP endpoint that contains a template file named either `.py` or `.jinja`, depending on the implementation language, along with any supporting files it might require, such as an optional schema file named `.py.schema` or `.jinja.schema`, respectively, helper files used by the implementation, files imported by the schema, and so on. ### Basic structure These constraints impose a basic level of organization on the template definition by ensuring that the template and all of its supporting files at least live in the same directory, and that the template and schema files follow well-defined naming conventions. They do not, however, provide any encapsulation. Without additional constraints, there is nothing to prevent template publishers from putting multiple templates, or multiple versions of the same template, in the same directory. While there might be some benefits in allowing templates to share a directory, such as avoiding the duplication of helper files, the cost of discovering and maintaining templates would quickly outweigh them as the number of templates in the directory increased. Also, since it may reduce management overhead to store many different templates, and/or many versions of the same template, in a single repository, we need a way to organize templates within a repository. Therefore: * Every template version must live in its own directory named for the version. * The version directory must contain exactly one top-level template file and supporting files for exactly one template version. * All of the versions of a given template must live under a directory named for the template without extensions. For example: ``` templateA/ v1/ example.yaml templateA.py templateA.py.schema v1.0.1/ example.yaml templateA.py templateA.py.schema v1.1/ example.yaml templateA.py templateA.py.schema helper.py ``` In this example, `templateA` is a template directory, and `v1`, `v1.01`, and `v1.1` are template version directories that hold the versions of `templateA`. ### Registry based template references In general, [templates references](https://github.com/kubernetes/deployment-manager/blob/master/docs/design/design.md#template-references) are just URLs to HTTP endpoints. However, because a template registry follows the conventions outlined above, references to templates in a template registry can be shorter and simpler than generalized template references. In a registry based template reference, the scheme part of the URL and the name of the top level template file are omitted, and the version number is delimited by a colon. So for example, instead of ``` https://raw.githubusercontent.com/ownerA/repository2/master/templateA/v1/templateA.py ``` you can simply write ``` github.com/ownerA/repository2/templateA:v1 ``` The general pattern for a registry based template reference is as follows: ``` github.com////