Skip to content

Commit

Permalink
add sanitization for image name
Browse files Browse the repository at this point in the history
  • Loading branch information
nkubala committed Feb 28, 2020
1 parent efccc62 commit 42846ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/skaffold/initializer/build/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package build
import (
"fmt"
"path/filepath"
"regexp"
"sort"
"strings"

Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions pkg/skaffold/initializer/build/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package build

import (
"fmt"
"os"
"path/filepath"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 42846ba

Please sign in to comment.