From 44f91c9afc1884132f4d4cc69ceb1e04f4e4664c Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 14 Oct 2019 11:35:16 -0700 Subject: [PATCH] Revert "remove clean_ami_name and clean_image_name; complete the deprecation for these functions in favor of clean_resource_name" This reverts commit 0026792d2f60f03abc04239640065e967581310c. --- builder/amazon/common/template_funcs.go | 1 + builder/azure/common/template_funcs.go | 1 + builder/googlecompute/template_funcs.go | 1 + builder/yandex/template_func.go | 12 +++++------- website/source/docs/templates/engine.html.md | 17 +++++++---------- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/builder/amazon/common/template_funcs.go b/builder/amazon/common/template_funcs.go index 14dd65d83..ad5821d6a 100644 --- a/builder/amazon/common/template_funcs.go +++ b/builder/amazon/common/template_funcs.go @@ -37,4 +37,5 @@ func templateCleanAMIName(s string) string { var TemplateFuncs = template.FuncMap{ "clean_resource_name": templateCleanAMIName, + "clean_ami_name": packertpl.DeprecatedTemplateFunc("clean_ami_name", "clean_resource_name", templateCleanAMIName), } diff --git a/builder/azure/common/template_funcs.go b/builder/azure/common/template_funcs.go index faccd4f07..36aadf16e 100644 --- a/builder/azure/common/template_funcs.go +++ b/builder/azure/common/template_funcs.go @@ -37,4 +37,5 @@ func templateCleanImageName(s string) string { var TemplateFuncs = template.FuncMap{ "clean_resource_name": templateCleanImageName, + "clean_image_name": packertpl.DeprecatedTemplateFunc("clean_image_name", "clean_resource_name", templateCleanImageName), } diff --git a/builder/googlecompute/template_funcs.go b/builder/googlecompute/template_funcs.go index 37557180f..9d7f5525a 100644 --- a/builder/googlecompute/template_funcs.go +++ b/builder/googlecompute/template_funcs.go @@ -35,4 +35,5 @@ func templateCleanImageName(s string) string { var TemplateFuncs = template.FuncMap{ "clean_resource_name": templateCleanImageName, + "clean_image_name": packertpl.DeprecatedTemplateFunc("clean_image_name", "clean_resource_name", templateCleanImageName), } diff --git a/builder/yandex/template_func.go b/builder/yandex/template_func.go index 144ed14e3..91f83a9d5 100644 --- a/builder/yandex/template_func.go +++ b/builder/yandex/template_func.go @@ -1,9 +1,7 @@ package yandex -import ( - "strings" - "text/template" -) +import "strings" +import "text/template" func isalphanumeric(b byte) bool { if '0' <= b && b <= '9' { @@ -15,9 +13,9 @@ func isalphanumeric(b byte) bool { return false } -// Clean up resource name by replacing invalid characters with "-" +// Clean up image name by replacing invalid characters with "-" // and converting upper cases to lower cases -func templateCleanResourceName(s string) string { +func templateCleanImageName(s string) string { if reImageFamily.MatchString(s) { return s } @@ -34,5 +32,5 @@ func templateCleanResourceName(s string) string { } var TemplateFuncs = template.FuncMap{ - "clean_resource_name": templateCleanResourceName, + "clean_image_name": templateCleanImageName, } diff --git a/website/source/docs/templates/engine.html.md b/website/source/docs/templates/engine.html.md index 4c7883c88..8859c96e6 100644 --- a/website/source/docs/templates/engine.html.md +++ b/website/source/docs/templates/engine.html.md @@ -41,7 +41,7 @@ Here is a full list of the available functions for reference. will convert upper cases to lower cases and replace illegal characters with a "-" character. Example: - `"mybuild-{{isotime | clean_resource_name}}"` will become + `"mybuild-{{isotime | clean_image_name}}"` will become `mybuild-2017-10-18t02-06-30z`. Note: Valid Azure image names must match the regex @@ -57,9 +57,6 @@ Here is a full list of the available functions for reference. clean_resource_name}}"` will cause your build to fail because the image name will start with a number, which is why in the above example we prepend the isotime with "mybuild". - Exact behavior of `clean_resource_name` will depend on which builder it is - being applied to; refer to build-specific docs below for more detail on how - each function will behave. - `env` - Returns environment variables. See example in [using home variable](/docs/templates/user-variables.html#using-home-variable) - `isotime [FORMAT]` - UTC time, which can be @@ -87,19 +84,19 @@ Here is a full list of the available functions for reference. #### Specific to Amazon builders: -- `clean_resource_name` - AMI names +- `clean_ami_name` - DEPRECATED use `clean_resource_name` instead - AMI names can only contain certain characters. This function will replace illegal characters with a '-" character. Example usage since ":" is not a legal AMI - name is: `{{isotime | clean_resource_name}}`. + name is: `{{isotime | clean_ami_name}}`. #### Specific to Google Compute builders: -- `clean_resource_name` - GCE +- `clean_image_name` - DEPRECATED use `clean_resource_name` instead - GCE image names can only contain certain characters and the maximum length is 63. This function will convert upper cases to lower cases and replace illegal characters with a "-" character. Example: - `"mybuild-{{isotime | clean_resource_name}}"` will become + `"mybuild-{{isotime | clean_image_name}}"` will become `mybuild-2017-10-18t02-06-30z`. Note: Valid GCE image names must match the regex @@ -114,12 +111,12 @@ Here is a full list of the available functions for reference. #### Specific to Azure builders: -- `clean_resource_name` - Azure +- `clean_image_name` - DEPRECATED use `clean_resource_name` instead - Azure managed image names can only contain certain characters and the maximum length is 80. This function will replace illegal characters with a "-" character. Example: - `"mybuild-{{isotime | clean_resource_name}}"` will become + `"mybuild-{{isotime | clean_image_name}}"` will become `mybuild-2017-10-18t02-06-30z`. Note: Valid Azure image names must match the regex