Пример #1
0
func describeBuilderImage(config *api.Config, image string, out io.Writer) {
	c := &api.Config{
		DockerConfig:       config.DockerConfig,
		PullAuthentication: config.PullAuthentication,
		BuilderImage:       config.BuilderImage,
		BuilderPullPolicy:  config.BuilderPullPolicy,
		Tag:                config.Tag,
		IncrementalAuthentication: config.IncrementalAuthentication,
	}
	pr, err := docker.GetBuilderImage(c)
	if err == nil {
		build.GenerateConfigFromLabels(c, pr)
		if len(c.DisplayName) > 0 {
			fmt.Fprintf(out, "Builder Name:\t%s\n", c.DisplayName)
		}
		fmt.Fprintf(out, "Builder Image:\t%s\n", config.BuilderImage)
		if len(c.BuilderImageVersion) > 0 {
			fmt.Fprintf(out, "Builder Image Version:\t%s\n", c.BuilderImageVersion)
		}
		if len(c.BuilderBaseImageVersion) > 0 {
			fmt.Fprintf(out, "Builder Base Version:\t%s\n", c.BuilderBaseImageVersion)
		}
	} else {
		fmt.Fprintf(out, "Error describing image:\t%s\n", err.Error())
	}
}
Пример #2
0
func newCmdRebuild(cfg *api.Config) *cobra.Command {
	buildCmd := &cobra.Command{
		Use:   "rebuild <image> [<new-tag>]",
		Short: "Rebuild an existing image",
		Long:  "Rebuild an existing application image that was built by S2I previously.",
		Run: func(cmd *cobra.Command, args []string) {
			// If user specifies the arguments, then we override the stored ones
			if len(args) >= 1 {
				cfg.Tag = args[0]
			} else {
				cmd.Help()
				os.Exit(1)
			}

			if r, err := os.Open(cfg.DockerCfgPath); err == nil {
				defer r.Close()
				cfg.PullAuthentication = docker.LoadAndGetImageRegistryAuth(r, cfg.Tag)
			}

			pr, err := docker.GetRebuildImage(cfg)
			checkErr(err)
			err = build.GenerateConfigFromLabels(cfg, pr)
			checkErr(err)

			if len(args) >= 2 {
				cfg.Tag = args[1]
			}

			// Attempt to read the .dockercfg and extract the authentication for
			// docker pull
			if r, err := os.Open(cfg.DockerCfgPath); err == nil {
				defer r.Close()
				cfg.PullAuthentication = docker.LoadAndGetImageRegistryAuth(r, cfg.BuilderImage)
			}

			if len(cfg.BuilderPullPolicy) == 0 {
				cfg.BuilderPullPolicy = api.DefaultBuilderPullPolicy
			}
			if len(cfg.PreviousImagePullPolicy) == 0 {
				cfg.PreviousImagePullPolicy = api.DefaultPreviousImagePullPolicy
			}

			glog.V(2).Infof("\n%s\n", describe.Config(cfg))

			builder, _, err := strategies.GetStrategy(cfg)
			checkErr(err)
			result, err := builder.Build(cfg)
			checkErr(err)

			for _, message := range result.Messages {
				glog.V(1).Infof(message)
			}

		},
	}

	cmdutil.AddCommonFlags(buildCmd, cfg)
	return buildCmd
}
Пример #3
0
func newCmdRebuild(cfg *api.Config) *cobra.Command {
	buildCmd := &cobra.Command{
		Use:   "rebuild <image> [<new-tag>]",
		Short: "Rebuild an existing image",
		Long:  "Rebuild an existing application image that was build by S2I previously.",
		Run: func(cmd *cobra.Command, args []string) {
			// If user specifies the arguments, then we override the stored ones
			if len(args) >= 0 {
				cfg.Tag = args[0]
			} else {
				cmd.Help()
				os.Exit(1)
			}

			if r, err := os.Open(cfg.DockerCfgPath); err == nil {
				cfg.PullAuthentication = docker.GetImageRegistryAuth(r, cfg.Tag)
			}

			err := build.GenerateConfigFromLabels(cfg.Tag, cfg)
			checkErr(err)

			if len(args) >= 2 {
				cfg.Tag = args[1]
			}

			// Attempt to read the .dockercfg and extract the authentication for
			// docker pull
			if r, err := os.Open(cfg.DockerCfgPath); err == nil {
				cfg.PullAuthentication = docker.GetImageRegistryAuth(r, cfg.BuilderImage)
			}

			if glog.V(2) {
				fmt.Printf("\n%s\n", describe.DescribeConfig(cfg))
			}

			builder, err := strategies.GetStrategy(cfg)
			checkErr(err)
			result, err := builder.Build(cfg)
			checkErr(err)

			for _, message := range result.Messages {
				glog.V(1).Infof(message)
			}

		},
	}

	buildCmd.Flags().BoolVarP(&(cfg.Quiet), "quiet", "q", false, "Operate quietly. Suppress all non-error output.")
	buildCmd.Flags().BoolVar(&(cfg.Incremental), "incremental", true, "Perform an incremental build")
	buildCmd.Flags().BoolVar(&(cfg.RemovePreviousImage), "rm", false, "Remove the previous image during incremental builds")
	buildCmd.Flags().StringVar(&(cfg.CallbackURL), "callback-url", "", "Specify a URL to invoke via HTTP POST upon build completion")
	buildCmd.Flags().BoolVar(&(cfg.ForcePull), "force-pull", true, "Always pull the builder image even if it is present locally")
	buildCmd.Flags().BoolVar(&(cfg.PreserveWorkingDir), "save-temp-dir", false, "Save the temporary directory used by STI instead of deleting it")
	buildCmd.Flags().StringVarP(&(cfg.DockerCfgPath), "dockercfg-path", "", filepath.Join(os.Getenv("HOME"), ".dockercfg"), "Specify the path to the Docker configuration file")
	return buildCmd
}
Пример #4
0
func describeBuilderImage(config *api.Config, image string, out io.Writer) {
	c := &api.Config{
		DockerConfig:       config.DockerConfig,
		PullAuthentication: config.PullAuthentication,
		BuilderImage:       config.BuilderImage,
		ForcePull:          config.ForcePull,
		Tag:                config.Tag,
	}
	build.GenerateConfigFromLabels(image, c)
	if len(c.DisplayName) > 0 {
		fmt.Fprintf(out, "Builder Name:\t%s\n", c.DisplayName)
	}
	fmt.Fprintf(out, "Builder Image:\t%s\n", config.BuilderImage)
	if len(c.BuilderImageVersion) > 0 {
		fmt.Fprintf(out, "Builder Image Version:\t%s\n", c.BuilderImageVersion)
	}
	if len(c.BuilderBaseImageVersion) > 0 {
		fmt.Fprintf(out, "Builder Base Version:\t%s\n", c.BuilderBaseImageVersion)
	}
}