func AddImageSourceRepository(sourceRepos app.SourceRepositories, r app.Resolver, g *GenerationInputs) (app.ComponentReference, app.SourceRepositories, error) { if len(g.SourceImage) == 0 { return nil, sourceRepos, nil } paths := strings.SplitN(g.SourceImagePath, ":", 2) var sourcePath, destPath string switch len(paths) { case 1: sourcePath = paths[0] case 2: sourcePath = paths[0] destPath = paths[1] } compRef, _, err := app.NewComponentInput(g.SourceImage) if err != nil { return nil, nil, err } compRef.Resolver = r switch len(sourceRepos) { case 0: sourceRepos = append(sourceRepos, app.NewImageSourceRepository(compRef, sourcePath, destPath)) case 1: sourceRepos[0].SetSourceImage(compRef) sourceRepos[0].SetSourceImagePath(sourcePath, destPath) default: return nil, nil, errors.New("--image-source cannot be used with multiple source repositories") } return compRef, sourceRepos, nil }
func (c *AppConfig) addImageSource(sourceRepos app.SourceRepositories) (app.ComponentReference, app.SourceRepositories, error) { if len(c.SourceImage) == 0 { return nil, sourceRepos, nil } paths := strings.SplitN(c.SourceImagePath, ":", 2) var sourcePath, destPath string switch len(paths) { case 1: sourcePath = paths[0] case 2: sourcePath = paths[0] destPath = paths[1] } compRef, _, err := app.NewComponentInput(c.SourceImage) if err != nil { return nil, nil, err } resolver := app.PerfectMatchWeightedResolver{} if c.ImageStreamByAnnotationSearcher != nil { resolver = append(resolver, app.WeightedResolver{Searcher: c.ImageStreamByAnnotationSearcher, Weight: 0.0}) } if c.ImageStreamSearcher != nil { resolver = append(resolver, app.WeightedResolver{Searcher: c.ImageStreamSearcher, Weight: 1.0}) } if c.DockerSearcher != nil { resolver = append(resolver, app.WeightedResolver{Searcher: c.DockerSearcher, Weight: 2.0}) } compRef.Resolver = resolver switch len(sourceRepos) { case 0: sourceRepos = append(sourceRepos, app.NewImageSourceRepository(compRef, sourcePath, destPath)) case 1: sourceRepos[0].SetSourceImage(compRef) sourceRepos[0].SetSourceImagePath(sourcePath, destPath) default: return nil, nil, fmt.Errorf("--image-source cannot be used with multiple source repositories") } return compRef, sourceRepos, nil }