| 321 | } |
| 322 | |
| 323 | func validateImages(config *latest.Config) error { |
| 324 | // images lists all the image names in order to check for duplicates |
| 325 | images := map[string]bool{} |
| 326 | for imageConfigName, imageConf := range config.Images { |
| 327 | if encoding.IsUnsafeName(imageConfigName) { |
| 328 | return fmt.Errorf("images.%s has to match the following regex: %v", imageConfigName, encoding.UnsafeNameRegEx.String()) |
| 329 | } |
| 330 | if imageConf == nil { |
| 331 | return errors.Errorf("images.%s is empty and should at least contain an image name", imageConfigName) |
| 332 | } |
| 333 | if imageConf.Image == "" { |
| 334 | return errors.Errorf("images.%s.image is required", imageConfigName) |
| 335 | } |
| 336 | if _, tag, _ := dockerfile.GetStrippedDockerImageName(imageConf.Image); tag != "" { |
| 337 | return errors.Errorf("images.%s.image '%s' can not have tag '%s'", imageConfigName, imageConf.Image, tag) |
| 338 | } |
| 339 | if imageConf.Custom != nil && imageConf.Custom.Command == "" && len(imageConf.Custom.Commands) == 0 { |
| 340 | return errors.Errorf("images.%s.build.custom.command or images.%s.build.custom.commands is required", imageConfigName, imageConfigName) |
| 341 | } |
| 342 | if images[imageConf.Image] { |
| 343 | return errors.Errorf("multiple image definitions with the same image name are not allowed") |
| 344 | } |
| 345 | if imageConf.RebuildStrategy != "" && imageConf.RebuildStrategy != latest.RebuildStrategyDefault && imageConf.RebuildStrategy != latest.RebuildStrategyAlways && imageConf.RebuildStrategy != latest.RebuildStrategyIgnoreContextChanges { |
| 346 | return errors.Errorf("images.%s.rebuildStrategy %s is invalid. Please choose one of %v", imageConfigName, string(imageConf.RebuildStrategy), []latest.RebuildStrategy{latest.RebuildStrategyAlways, latest.RebuildStrategyIgnoreContextChanges}) |
| 347 | } |
| 348 | if imageConf.Kaniko != nil && imageConf.Kaniko.EnvFrom != nil { |
| 349 | for _, v := range imageConf.Kaniko.EnvFrom { |
| 350 | o, err := yaml.Marshal(v) |
| 351 | if err != nil { |
| 352 | return errors.Errorf("images.%s.build.kaniko.envFrom is invalid: %v", imageConfigName, err) |
| 353 | } |
| 354 | |
| 355 | err = jsonyaml.Unmarshal(o, &k8sv1.EnvVarSource{}) |
| 356 | if err != nil { |
| 357 | return errors.Errorf("images.%s.build.kaniko.envFrom is invalid: %v", imageConfigName, err) |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | images[imageConf.Image] = true |
| 362 | } |
| 363 | |
| 364 | return nil |
| 365 | } |
| 366 | |
| 367 | func validateDev(config *latest.Config) error { |
| 368 | for devPodName, devPod := range config.Dev { |