diff --git a/pkg/skaffold/initializer/build/resolve.go b/pkg/skaffold/initializer/build/resolve.go index 24cc52536f1..7ee0d7cb8a5 100644 --- a/pkg/skaffold/initializer/build/resolve.go +++ b/pkg/skaffold/initializer/build/resolve.go @@ -19,6 +19,7 @@ package build import ( "fmt" "path/filepath" + "regexp" "sort" "strings" @@ -112,8 +113,20 @@ func getGeneratedBuilderPair(b InitBuilder) GeneratedBuilderImagePair { return GeneratedBuilderImagePair{ BuilderImagePair: BuilderImagePair{ Builder: b, - ImageName: imageName, + ImageName: sanitizeImageName(imageName), }, ManifestPath: filepath.Join(path, "deployment.yaml"), } } + +func sanitizeImageName(imageName string) string { + // Replace unsupported characters with `_` + sanitized := regexp.MustCompile(`[^a-zA-Z0-9-._]`).ReplaceAllString(imageName, `-`) + + // Truncate to 128 characters + if len(sanitized) > 128 { + return sanitized[0:128] + } + + return sanitized +} diff --git a/pkg/skaffold/initializer/build/util.go b/pkg/skaffold/initializer/build/util.go index b20b1e3687b..73e2f73463b 100644 --- a/pkg/skaffold/initializer/build/util.go +++ b/pkg/skaffold/initializer/build/util.go @@ -17,6 +17,8 @@ limitations under the License. package build import ( + "fmt" + "os" "path/filepath" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" @@ -91,6 +93,7 @@ func artifacts(pairs []BuilderImagePair) []*latest.Artifact { workspace := filepath.Dir(pair.Builder.Path()) if workspace != "." { + fmt.Fprintf(os.Stdout, "using non standard workspace: %s\n", workspace) artifact.Workspace = workspace }