Пример #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
}
Пример #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
}
Пример #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, c *cobra.Command, args []string, config *newcmd.AppConfig) error {
	if err := setupAppConfig(f, c, args, config); err != nil {
		return err
	}

	if err := setAppConfigLabels(c, config); err != nil {
		return err
	}
	result, err := config.RunBuilds(out, c.Out())
	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(cmdutil.GetFlagString(c, "output")) != 0 {
		return f.Factory.PrintObject(c, result.List, out)
	}
	if err := createObjects(f, out, result); err != nil {
		return err
	}

	for _, item := range result.List.Items {
		switch t := item.(type) {
		case *buildapi.BuildConfig:
			fmt.Fprintf(c.Out(), "A build configuration was created - you can run `%s start-build %s` to start it.\n", fullName, t.Name)
		}
	}

	return nil
}