Exemple #1
0
// RunNewBuild contains all the necessary functionality for the OpenShift cli new-build command
func RunNewBuild(fullName string, f *clientcmd.Factory, out io.Writer, in io.Reader, c *cobra.Command, args []string, config *newcmd.AppConfig) error {
	output := cmdutil.GetFlagString(c, "output")

	if config.Dockerfile == "-" {
		data, err := ioutil.ReadAll(in)
		if err != nil {
			return err
		}
		config.Dockerfile = string(data)
	}

	if err := setupAppConfig(f, out, c, args, config); err != nil {
		return err
	}

	if err := setAppConfigLabels(c, config); err != nil {
		return err
	}
	result, err := config.RunBuilds()
	if err != nil {
		if errs, ok := err.(errors.Aggregate); ok {
			if len(errs.Errors()) == 1 {
				err = errs.Errors()[0]
			}
		}
		if err == newcmd.ErrNoInputs {
			// TODO: suggest things to the user
			return cmdutil.UsageError(c, "You must specify one or more images, image streams and source code locations to create a build configuration.")
		}
		return err
	}
	if err := setLabels(config.Labels, result); err != nil {
		return err
	}
	if err := setAnnotations(map[string]string{newcmd.GeneratedByNamespace: newcmd.GeneratedByNewBuild}, result); err != nil {
		return err
	}
	if len(output) != 0 && output != "name" {
		return f.Factory.PrintObject(c, result.List, out)
	}
	if err := createObjects(f, out, output == "name", result); err != nil {
		return err
	}

	for _, item := range result.List.Items {
		switch t := item.(type) {
		case *buildapi.BuildConfig:
			fmt.Fprintf(c.Out(), "Build configuration %q created and build triggered.\n", t.Name)
		}
	}
	if len(result.List.Items) > 0 {
		fmt.Fprintf(c.Out(), "Run '%s %s' to check the progress.\n", fullName, StatusRecommendedName)
	}

	return nil
}
Exemple #2
0
// RunNewBuild contains all the necessary functionality for the OpenShift cli new-build command
func RunNewBuild(fullName string, f *clientcmd.Factory, out io.Writer, in io.Reader, c *cobra.Command, args []string, config *newcmd.AppConfig) error {
	output := cmdutil.GetFlagString(c, "output")

	if config.Dockerfile == "-" {
		data, err := ioutil.ReadAll(in)
		if err != nil {
			return err
		}
		config.Dockerfile = string(data)
	}

	if err := setupAppConfig(f, out, c, args, config); err != nil {
		return err
	}

	if err := setAppConfigLabels(c, config); err != nil {
		return err
	}
	result, err := config.RunBuilds()
	if err != nil {
		return handleBuildError(c, err, fullName)
	}
	if err := setLabels(config.Labels, result); err != nil {
		return err
	}
	if err := setAnnotations(map[string]string{newcmd.GeneratedByNamespace: newcmd.GeneratedByNewBuild}, result); err != nil {
		return err
	}
	if len(output) != 0 && output != "name" {
		return f.Factory.PrintObject(c, result.List, out)
	}
	if err := createObjects(f, out, c.Out(), output == "name", true, result); err != nil {
		return err
	}

	for _, item := range result.List.Items {
		switch t := item.(type) {
		case *buildapi.BuildConfig:
			fmt.Fprintf(c.Out(), "Build configuration %q created and build triggered.\n", t.Name)
		}
	}
	if len(result.List.Items) > 0 {
		fmt.Fprintf(c.Out(), "Run '%s %s' to check the progress.\n", fullName, StatusRecommendedName)
	}

	return nil
}
Exemple #3
0
// RunNewBuild contains all the necessary functionality for the OpenShift cli new-build command
func RunNewBuild(fullName string, f *clientcmd.Factory, out io.Writer, in io.Reader, c *cobra.Command, args []string, config *newcmd.AppConfig) error {
	output := kcmdutil.GetFlagString(c, "output")
	shortOutput := output == "name"

	if config.Dockerfile == "-" {
		data, err := ioutil.ReadAll(in)
		if err != nil {
			return err
		}
		config.Dockerfile = string(data)
	}

	if err := setupAppConfig(f, out, c, args, config); err != nil {
		return err
	}

	if err := setAppConfigLabels(c, config); err != nil {
		return err
	}
	result, err := config.Run()
	if err != nil {
		return handleBuildError(c, err, fullName)
	}

	if len(config.Labels) == 0 && len(result.Name) > 0 {
		config.Labels = map[string]string{"build": result.Name}
	}

	if err := setLabels(config.Labels, result); err != nil {
		return err
	}
	if err := setAnnotations(map[string]string{newcmd.GeneratedByNamespace: newcmd.GeneratedByNewBuild}, result); err != nil {
		return err
	}

	indent := "    "
	switch {
	case shortOutput:
		indent = ""
	case len(output) != 0:
		result.List.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(c, result.List.Items)
		if err != nil {
			return err
		}

		return f.Factory.PrintObject(c, result.List, out)
	default:
		if len(config.Labels) > 0 {
			fmt.Fprintf(out, "--> Creating resources with label %s ...\n", labels.SelectorFromSet(config.Labels).String())
		} else {
			fmt.Fprintf(out, "--> Creating resources ...\n")
		}
	}
	if config.DryRun {
		fmt.Fprintf(out, "--> Success (DRY RUN)\n")
		return nil
	}

	mapper, _ := f.Object()
	if err := createObjects(f, configcmd.NewPrintNameOrErrorAfterIndent(mapper, shortOutput, "created", out, c.Out(), indent), result); err != nil {
		return err
	}

	if shortOutput {
		return nil
	}

	fmt.Fprintf(out, "--> Success\n")
	for _, item := range result.List.Items {
		switch t := item.(type) {
		case *buildapi.BuildConfig:
			if len(t.Spec.Triggers) > 0 && t.Spec.Source.Binary == nil {
				fmt.Fprintf(out, "%sBuild configuration %q created and build triggered.\n", indent, t.Name)
				fmt.Fprintf(out, "%sRun '%s logs -f bc/%s' to stream the build progress.\n", indent, fullName, t.Name)
			}
		}
	}

	return nil
}