diff --git a/builder/googlecompute/template_funcs_test.go b/builder/googlecompute/template_funcs_test.go index 62c57309e..5b37acbd9 100644 --- a/builder/googlecompute/template_funcs_test.go +++ b/builder/googlecompute/template_funcs_test.go @@ -7,18 +7,33 @@ func Test_templateCleanImageName(t *testing.T) { origName string expected string }{ + // test that valid name is unchanged { origName: "abcde-012345xyz", expected: "abcde-012345xyz", }, + + //test that capital letters are converted to lowercase { origName: "ABCDE-012345xyz", expected: "abcde-012345xyz", }, + // test that periods and colons are converted to hyphens { - origName: "abcde-012345v1.0.0", + origName: "abcde-012345v1.0:0", expected: "abcde-012345v1-0-0", }, + // Name starting with number is not valid, but not in scope of this + // function to correct + { + origName: "012345v1.0:0", + expected: "012345v1-0-0", + }, + // Name over 64 chars is not valid, but not corrected by this function. + { + origName: "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong", + expected: "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong", + }, } for _, v := range vals { diff --git a/website/source/docs/templates/engine.html.md b/website/source/docs/templates/engine.html.md index c4fa72e29..3b7c60b24 100644 --- a/website/source/docs/templates/engine.html.md +++ b/website/source/docs/templates/engine.html.md @@ -55,10 +55,22 @@ Here is a full list of the available functions for reference. - `clean_image_name` - 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 usage since ":" is not a legal image name is: `"a-{{isotime | clean_image_name}}"` -> `a-2017-10-18t02-06-30z`. + Example: - Note that image name must be a match of regex `(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)` - but this function won't truncate and replace with valid character such as 'a' except '-'. + `"mybuild-{{isotime | clean_image_name}}"` + will become + `mybuild-2017-10-18t02-06-30z`. + + Note: Valid GCE image names must match the regex + `(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)` + + This engine does not guarantee that the final image name will match the + regex; it will not truncate your name if it exceeds 63 characters, and it + will not valiate that the beginning and end of the engine's output are + valid. For example, + `"image_name": {{isotime | clean_image_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". ## Template variables