// EnsureHasSource ensure every builder component has source code associated with it. It takes a list of component references // that are builders and have not been associated with source, and a set of source repositories that have not been associated // with a builder func EnsureHasSource(components app.ComponentReferences, repositories app.SourceRepositories, g *GenerationInputs) error { if len(components) == 0 { return nil } switch { case len(repositories) > 1: if len(components) == 1 { component := components[0] suggestions := "" for _, repo := range repositories { suggestions += fmt.Sprintf("%s~%s\n", component, repo) } return fmt.Errorf("there are multiple code locations provided - use one of the following suggestions to declare which code goes with the image:\n%s", suggestions) } return fmt.Errorf("the following images require source code: %s\n"+ " and the following repositories are not used: %s\nUse '[image]~[repo]' to declare which code goes with which image", components, repositories) case len(repositories) == 1: glog.V(2).Infof("Using %q as the source for build", repositories[0]) for _, component := range components { glog.V(2).Infof("Pairing with component %v", component) component.Input().Use(repositories[0]) repositories[0].UsedBy(component) } default: switch { case g.BinaryBuild && g.ExpectToBuild: // create new "fake" binary repos for any component that doesn't already have a repo // TODO: source repository should possibly be refactored to be an interface or a type that better reflects // the different types of inputs for _, component := range components { input := component.Input() if input.Uses != nil { continue } strategy := generate.StrategySource isBuilder := input.ResolvedMatch != nil && input.ResolvedMatch.Builder if g.Strategy == generate.StrategyDocker || (g.Strategy == generate.StrategyUnspecified && !isBuilder) { strategy = generate.StrategyDocker } repo := app.NewBinarySourceRepository(strategy) input.Use(repo) repo.UsedBy(input) input.ExpectToBuild = true } case g.ExpectToBuild: return errors.New("you must specify at least one source repository URL, provide a Dockerfile, or indicate you wish to use binary builds") default: for _, component := range components { component.Input().ExpectToBuild = false } } } return nil }
// ensureHasSource ensure every builder component has source code associated with it. It takes a list of component references // that are builders and have not been associated with source, and a set of source repositories that have not been associated // with a builder func (c *AppConfig) ensureHasSource(components app.ComponentReferences, repositories app.SourceRepositories) error { if len(components) > 0 { switch { case len(repositories) > 1: if len(components) == 1 { component := components[0] suggestions := "" for _, repo := range repositories { suggestions += fmt.Sprintf("%s~%s\n", component, repo) } return fmt.Errorf("there are multiple code locations provided - use one of the following suggestions to declare which code goes with the image:\n%s", suggestions) } return fmt.Errorf("the following images require source code: %s\n"+ " and the following repositories are not used: %s\nUse '[image]~[repo]' to declare which code goes with which image", components, repositories) case len(repositories) == 1: glog.Infof("Using %q as the source for build", repositories[0]) for _, component := range components { component.Input().Use(repositories[0]) repositories[0].UsedBy(component) } default: switch { case c.BinaryBuild && c.ExpectToBuild: // create new "fake" binary repos for any component that doesn't already have a repo // TODO: source repository should possibly be refactored to be an interface or a type that better reflects // the different types of inputs for _, component := range components { input := component.Input() if input.Uses != nil { continue } repo := app.NewBinarySourceRepository() if c.Strategy == "docker" || len(c.Strategy) == 0 { repo.BuildWithDocker() } input.Use(repo) repo.UsedBy(input) input.ExpectToBuild = true } case c.ExpectToBuild: return fmt.Errorf("you must specify at least one source repository URL, provide a Dockerfile, or indicate you wish to use binary builds") default: for _, component := range components { component.Input().ExpectToBuild = false } } } glog.V(4).Infof("ensureHasSource: %#v", components[0]) } return nil }