本文整理汇总了Golang中github.com/openshift/source-to-image/pkg/api/validation.ValidateConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang ValidateConfig函数的具体用法?Golang ValidateConfig怎么用?Golang ValidateConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ValidateConfig函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: newCmdBuild
func newCmdBuild(cfg *api.Config) *cobra.Command {
useConfig := false
oldScriptsFlag := ""
oldDestination := ""
buildCmd := &cobra.Command{
Use: "build <source> <image> [<tag>]",
Short: "Build a new image",
Long: "Build a new Docker image named <tag> (if provided) from a source repository and base image.",
Example: `
# Build an application Docker image from a Git repository
$ s2i build git://github.com/openshift/ruby-hello-world centos/ruby-22-centos7 hello-world-app
# Build from a local directory
$ s2i build . centos/ruby-22-centos7 hello-world-app
`,
Run: func(cmd *cobra.Command, args []string) {
glog.V(1).Infof("Running S2I version %q\n", version.Get())
// Attempt to restore the build command from the configuration file
if useConfig {
config.Restore(cfg, cmd)
}
// If user specifies the arguments, then we override the stored ones
if len(args) >= 2 {
cfg.Source = args[0]
cfg.BuilderImage = args[1]
if len(args) >= 3 {
cfg.Tag = args[2]
}
}
if cfg.Incremental && len(cfg.RuntimeImage) > 0 {
fmt.Fprintln(os.Stderr, "ERROR: Incremental build with runtime image isn't supported")
os.Exit(1)
}
if cfg.ForcePull {
glog.Warning("DEPRECATED: The '--force-pull' option is deprecated. Use '--pull-policy' instead")
}
if len(cfg.BuilderPullPolicy) == 0 {
cfg.BuilderPullPolicy = api.DefaultBuilderPullPolicy
}
if len(cfg.PreviousImagePullPolicy) == 0 {
cfg.PreviousImagePullPolicy = api.DefaultPreviousImagePullPolicy
}
if errs := validation.ValidateConfig(cfg); len(errs) > 0 {
for _, e := range errs {
fmt.Fprintf(os.Stderr, "ERROR: %s\n", e)
}
fmt.Println()
cmd.Help()
os.Exit(1)
}
// Persists the current command line options and config into .s2ifile
if useConfig {
config.Save(cfg, cmd)
}
// Attempt to read the .dockercfg and extract the authentication for
// docker pull
if r, err := os.Open(cfg.DockerCfgPath); err == nil {
defer r.Close()
auths := docker.LoadImageRegistryAuth(r)
cfg.PullAuthentication = docker.GetImageRegistryAuth(auths, cfg.BuilderImage)
if cfg.Incremental {
cfg.IncrementalAuthentication = docker.GetImageRegistryAuth(auths, cfg.Tag)
}
if len(cfg.RuntimeImage) > 0 {
cfg.RuntimeAuthentication = docker.GetImageRegistryAuth(auths, cfg.RuntimeImage)
}
}
if len(cfg.EnvironmentFile) > 0 {
result, err := util.ReadEnvironmentFile(cfg.EnvironmentFile)
if err != nil {
glog.Warningf("Unable to read environment file %q: %v", cfg.EnvironmentFile, err)
} else {
for name, value := range result {
cfg.Environment = append(cfg.Environment, api.EnvironmentSpec{Name: name, Value: value})
}
}
}
if len(oldScriptsFlag) != 0 {
glog.Warning("DEPRECATED: Flag --scripts is deprecated, use --scripts-url instead")
cfg.ScriptsURL = oldScriptsFlag
}
if len(oldDestination) != 0 {
glog.Warning("DEPRECATED: Flag --location is deprecated, use --destination instead")
cfg.Destination = oldDestination
}
glog.V(2).Infof("\n%s\n", describe.Config(cfg))
err := docker.CheckReachable(cfg)
if err != nil {
//.........这里部分代码省略.........
开发者ID:php-coder,项目名称:source-to-image,代码行数:101,代码来源:main.go
示例2: ValidateConfig
// default implementation of stiConfigValidator.ValidateConfig method. Just delegates to S2I-specific code
func (_ runtimeConfigValidator) ValidateConfig(config *stiapi.Config) []validation.ValidationError {
return validation.ValidateConfig(config)
}
开发者ID:redlocal,项目名称:origin,代码行数:4,代码来源:sti.go
示例3: newCmdBuild
func newCmdBuild(cfg *api.Config) *cobra.Command {
useConfig := false
oldScriptsFlag := ""
oldDestination := ""
buildCmd := &cobra.Command{
Use: "build <source> <image> [<tag>]",
Short: "Build a new image",
Long: "Build a new Docker image named <tag> (if provided) from a source repository and base image.",
Example: `
# Build an application Docker image from a Git repository
$ s2i build git://github.com/openshift/ruby-hello-world centos/ruby-22-centos7 hello-world-app
# Build from a local directory
$ s2i build . centos/ruby-22-centos7 hello-world-app
`,
Run: func(cmd *cobra.Command, args []string) {
go cmdutil.InstallDumpOnSignal()
// Attempt to restore the build command from the configuration file
if useConfig {
config.Restore(cfg, cmd)
}
// If user specifies the arguments, then we override the stored ones
if len(args) >= 2 {
cfg.Source = args[0]
cfg.BuilderImage = args[1]
if len(args) >= 3 {
cfg.Tag = args[2]
}
}
if cfg.ForcePull {
glog.Warning("DEPRECATED: The '--force-pull' option is deprecated. Use '--pull-policy' instead")
}
if len(cfg.BuilderPullPolicy) == 0 {
cfg.BuilderPullPolicy = api.DefaultBuilderPullPolicy
}
if errs := validation.ValidateConfig(cfg); len(errs) > 0 {
for _, e := range errs {
fmt.Fprintf(os.Stderr, "ERROR: %s\n", e)
}
fmt.Println()
cmd.Help()
os.Exit(1)
}
// Persists the current command line options and config into .stifile
if useConfig {
config.Save(cfg, cmd)
}
// Attempt to read the .dockercfg and extract the authentication for
// docker pull
if r, err := os.Open(cfg.DockerCfgPath); err == nil {
auths := docker.LoadImageRegistryAuth(r)
cfg.PullAuthentication = docker.GetImageRegistryAuth(auths, cfg.BuilderImage)
if cfg.Incremental {
cfg.IncrementalAuthentication = docker.GetImageRegistryAuth(auths, cfg.Tag)
}
}
cfg.Environment = map[string]string{}
if len(cfg.EnvironmentFile) > 0 {
result, err := util.ReadEnvironmentFile(cfg.EnvironmentFile)
if err != nil {
glog.Warningf("Unable to read environment file %q: %v", cfg.EnvironmentFile, err)
} else {
cfg.Environment = result
}
}
envs, err := cmdutil.ParseEnvs(cmd, "env")
checkErr(err)
for k, v := range envs {
cfg.Environment[k] = v
}
if len(oldScriptsFlag) != 0 {
glog.Warning("DEPRECATED: Flag --scripts is deprecated, use --scripts-url instead")
cfg.ScriptsURL = oldScriptsFlag
}
if len(oldDestination) != 0 {
glog.Warning("DEPRECATED: Flag --location is deprecated, use --destination instead")
cfg.Destination = oldDestination
}
if glog.V(2) {
fmt.Printf("\n%s\n", describe.DescribeConfig(cfg))
}
if !docker.IsReachable(cfg) {
glog.Fatalf("Unable to connect to Docker daemon. Please set the DOCKER_HOST or make sure the Docker socket %q exists", cfg.DockerConfig.Endpoint)
}
builder, err := strategies.GetStrategy(cfg)
checkErr(err)
//.........这里部分代码省略.........
开发者ID:paralin,项目名称:source-to-image,代码行数:101,代码来源:main.go
示例4: newCmdBuild
func newCmdBuild(cfg *api.Config) *cobra.Command {
useConfig := false
oldScriptsFlag := ""
oldDestination := ""
buildCmd := &cobra.Command{
Use: "build <source> <image> [<tag>]",
Short: "Build a new image",
Long: "Build a new Docker image named <tag> (if provided) from a source repository and base image.",
Run: func(cmd *cobra.Command, args []string) {
go func() {
for {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGQUIT)
buf := make([]byte, 1<<20)
for {
<-sigs
runtime.Stack(buf, true)
if file, err := ioutil.TempFile(os.TempDir(), "sti_dump"); err == nil {
defer file.Close()
file.Write(buf)
}
glog.Infof("=== received SIGQUIT ===\n*** goroutine dump...\n%s\n*** end\n", buf)
}
}
}()
// Attempt to restore the build command from the configuration file
if useConfig {
config.Restore(cfg, cmd)
}
// If user specifies the arguments, then we override the stored ones
if len(args) >= 2 {
cfg.Source = args[0]
cfg.BuilderImage = args[1]
if len(args) >= 3 {
cfg.Tag = args[2]
}
}
if len(validation.ValidateConfig(cfg)) != 0 {
cmd.Help()
os.Exit(1)
}
// Persists the current command line options and config into .stifile
if useConfig {
config.Save(cfg, cmd)
}
// 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)
}
cfg.Environment = map[string]string{}
if len(cfg.EnvironmentFile) > 0 {
result, err := util.ReadEnvironmentFile(cfg.EnvironmentFile)
if err != nil {
glog.Warningf("Unable to read %s: %v", cfg.EnvironmentFile, err)
} else {
cfg.Environment = result
}
}
envs, err := parseEnvs(cmd, "env")
checkErr(err)
for k, v := range envs {
cfg.Environment[k] = v
}
if len(oldScriptsFlag) != 0 {
glog.Warning("Flag --scripts is deprecated, use --scripts-url instead")
cfg.ScriptsURL = oldScriptsFlag
}
if len(oldDestination) != 0 {
glog.Warning("Flag --location is deprecated, use --destination instead")
cfg.Destination = oldDestination
}
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", false, "Perform an incremental build")
buildCmd.Flags().BoolVar(&(cfg.RemovePreviousImage), "rm", false, "Remove the previous image during incremental builds")
//.........这里部分代码省略.........
开发者ID:rimolive,项目名称:source-to-image,代码行数:101,代码来源:main.go
示例5: Build
// Build executes the STI build
func (s *STIBuilder) Build() error {
tag := s.build.Parameters.Output.DockerImageReference
config := &stiapi.Config{
BuilderImage: s.build.Parameters.Strategy.SourceStrategy.From.Name,
DockerConfig: &stiapi.DockerConfig{Endpoint: s.dockerSocket},
Source: s.build.Parameters.Source.Git.URI,
ContextDir: s.build.Parameters.Source.ContextDir,
DockerCfgPath: os.Getenv(dockercfg.PullAuthType),
Tag: tag,
ScriptsURL: s.build.Parameters.Strategy.SourceStrategy.Scripts,
Environment: getBuildEnvVars(s.build),
Incremental: s.build.Parameters.Strategy.SourceStrategy.Incremental,
}
if s.build.Parameters.Revision != nil && s.build.Parameters.Revision.Git != nil &&
s.build.Parameters.Revision.Git.Commit != "" {
config.Ref = s.build.Parameters.Revision.Git.Commit
} else if s.build.Parameters.Source.Git.Ref != "" {
config.Ref = s.build.Parameters.Source.Git.Ref
}
if errs := validation.ValidateConfig(config); len(errs) != 0 {
var buffer bytes.Buffer
for _, ve := range errs {
buffer.WriteString(ve.Error())
buffer.WriteString(", ")
}
return errors.New(buffer.String())
}
// If DockerCfgPath is provided in api.Config, then attempt to read the the
// dockercfg file and get the authentication for pulling the builder image.
if r, err := os.Open(config.DockerCfgPath); err == nil {
config.PullAuthentication = stidocker.GetImageRegistryAuth(r, config.BuilderImage)
glog.Infof("Using provided pull secret for pulling %s image", config.BuilderImage)
}
glog.V(2).Infof("Creating a new S2I builder with build config: %#v\n", describe.DescribeConfig(config))
builder, err := sti.GetStrategy(config)
if err != nil {
return err
}
defer removeImage(s.dockerClient, tag)
glog.V(4).Infof("Starting S2I build from %s/%s BuildConfig ...", s.build.Namespace, s.build.Name)
if _, err = builder.Build(config); err != nil {
return err
}
dockerImageRef := s.build.Parameters.Output.DockerImageReference
if len(dockerImageRef) != 0 {
// Get the Docker push authentication
pushAuthConfig, authPresent := dockercfg.NewHelper().GetDockerAuth(
dockerImageRef,
dockercfg.PushAuthType,
)
if authPresent {
glog.Infof("Using provided push secret for pushing %s image", dockerImageRef)
s.auth = pushAuthConfig
}
glog.Infof("Pushing %s image ...", dockerImageRef)
if err := pushImage(s.dockerClient, tag, s.auth); err != nil {
return fmt.Errorf("Failed to push image: %v", err)
}
glog.Infof("Successfully pushed %s", dockerImageRef)
glog.Flush()
}
return nil
}
开发者ID:mignev,项目名称:origin,代码行数:67,代码来源:sti.go
示例6: Build
// Build executes the STI build
func (s *STIBuilder) Build() error {
var push bool
// if there is no output target, set one up so the docker build logic
// will still work, but we won't push it at the end.
if s.build.Spec.Output.To == nil || len(s.build.Spec.Output.To.Name) == 0 {
s.build.Spec.Output.To = &kapi.ObjectReference{
Kind: "DockerImage",
Name: noOutputDefaultTag,
}
push = false
} else {
push = true
}
tag := s.build.Spec.Output.To.Name
config := &stiapi.Config{
BuilderImage: s.build.Spec.Strategy.SourceStrategy.From.Name,
DockerConfig: &stiapi.DockerConfig{Endpoint: s.dockerSocket},
Source: s.build.Spec.Source.Git.URI,
ContextDir: s.build.Spec.Source.ContextDir,
DockerCfgPath: os.Getenv(dockercfg.PullAuthType),
Tag: tag,
ScriptsURL: s.build.Spec.Strategy.SourceStrategy.Scripts,
Environment: getBuildEnvVars(s.build),
Incremental: s.build.Spec.Strategy.SourceStrategy.Incremental,
ForcePull: s.build.Spec.Strategy.SourceStrategy.ForcePull,
}
if s.build.Spec.Revision != nil && s.build.Spec.Revision.Git != nil &&
s.build.Spec.Revision.Git.Commit != "" {
config.Ref = s.build.Spec.Revision.Git.Commit
} else if s.build.Spec.Source.Git.Ref != "" {
config.Ref = s.build.Spec.Source.Git.Ref
}
if errs := validation.ValidateConfig(config); len(errs) != 0 {
var buffer bytes.Buffer
for _, ve := range errs {
buffer.WriteString(ve.Error())
buffer.WriteString(", ")
}
return errors.New(buffer.String())
}
// If DockerCfgPath is provided in api.Config, then attempt to read the the
// dockercfg file and get the authentication for pulling the builder image.
if r, err := os.Open(config.DockerCfgPath); err == nil {
config.PullAuthentication = stidocker.GetImageRegistryAuth(r, config.BuilderImage)
glog.Infof("Using provided pull secret for pulling %s image", config.BuilderImage)
}
glog.V(2).Infof("Creating a new S2I builder with build config: %#v\n", describe.DescribeConfig(config))
builder, err := sti.GetStrategy(config)
if err != nil {
return err
}
glog.V(4).Infof("Starting S2I build from %s/%s BuildConfig ...", s.build.Namespace, s.build.Name)
origProxy := make(map[string]string)
var setHttp, setHttps bool
// set the http proxy to be used by the git clone performed by S2I
if len(s.build.Spec.Source.Git.HTTPSProxy) != 0 {
glog.V(2).Infof("Setting https proxy variables for Git to %s", s.build.Spec.Source.Git.HTTPSProxy)
origProxy["HTTPS_PROXY"] = os.Getenv("HTTPS_PROXY")
origProxy["https_proxy"] = os.Getenv("https_proxy")
os.Setenv("HTTPS_PROXY", s.build.Spec.Source.Git.HTTPSProxy)
os.Setenv("https_proxy", s.build.Spec.Source.Git.HTTPSProxy)
setHttps = true
}
if len(s.build.Spec.Source.Git.HTTPProxy) != 0 {
glog.V(2).Infof("Setting http proxy variables for Git to %s", s.build.Spec.Source.Git.HTTPSProxy)
origProxy["HTTP_PROXY"] = os.Getenv("HTTP_PROXY")
origProxy["http_proxy"] = os.Getenv("http_proxy")
os.Setenv("HTTP_PROXY", s.build.Spec.Source.Git.HTTPProxy)
os.Setenv("http_proxy", s.build.Spec.Source.Git.HTTPProxy)
setHttp = true
}
if _, err = builder.Build(config); err != nil {
return err
}
// reset http proxy env variables to original value
if setHttps {
glog.V(4).Infof("Resetting HTTPS_PROXY variable for Git to %s", origProxy["HTTPS_PROXY"])
os.Setenv("HTTPS_PROXY", origProxy["HTTPS_PROXY"])
glog.V(4).Infof("Resetting https_proxy variable for Git to %s", origProxy["https_proxy"])
os.Setenv("https_proxy", origProxy["https_proxy"])
}
if setHttp {
glog.V(4).Infof("Resetting HTTP_PROXY variable for Git to %s", origProxy["HTTP_PROXY"])
os.Setenv("HTTP_PROXY", origProxy["HTTP_PROXY"])
glog.V(4).Infof("Resetting http_proxy variable for Git to %s", origProxy["http_proxy"])
os.Setenv("http_proxy", origProxy["http_proxy"])
}
if push {
// Get the Docker push authentication
pushAuthConfig, authPresent := dockercfg.NewHelper().GetDockerAuth(
//.........这里部分代码省略.........
开发者ID:Tlacenka,项目名称:origin,代码行数:101,代码来源:sti.go
示例7: Build
// Build executes the STI build
func (s *STIBuilder) Build() error {
var push bool
// if there is no output target, set one up so the docker build logic
// (which requires a tag) will still work, but we won't push it at the end.
if s.build.Spec.Output.To == nil || len(s.build.Spec.Output.To.Name) == 0 {
s.build.Spec.Output.To = &kapi.ObjectReference{
Kind: "DockerImage",
Name: noOutputDefaultTag,
}
push = false
} else {
push = true
}
tag := s.build.Spec.Output.To.Name
config := &stiapi.Config{
BuilderImage: s.build.Spec.Strategy.SourceStrategy.From.Name,
DockerConfig: &stiapi.DockerConfig{Endpoint: s.dockerSocket},
Source: s.build.Spec.Source.Git.URI,
ContextDir: s.build.Spec.Source.ContextDir,
DockerCfgPath: os.Getenv(dockercfg.PullAuthType),
Tag: tag,
ScriptsURL: s.build.Spec.Strategy.SourceStrategy.Scripts,
Environment: buildEnvVars(s.build),
LabelNamespace: api.DefaultDockerLabelNamespace,
Incremental: s.build.Spec.Strategy.SourceStrategy.Incremental,
ForcePull: s.build.Spec.Strategy.SourceStrategy.ForcePull,
}
if s.build.Spec.Revision != nil && s.build.Spec.Revision.Git != nil &&
s.build.Spec.Revision.Git.Commit != "" {
config.Ref = s.build.Spec.Revision.Git.Commit
} else if s.build.Spec.Source.Git.Ref != "" {
config.Ref = s.build.Spec.Source.Git.Ref
}
allowedUIDs := os.Getenv("ALLOWED_UIDS")
glog.V(2).Infof("The value of ALLOWED_UIDS is [%s]", allowedUIDs)
if len(allowedUIDs) > 0 {
err := config.AllowedUIDs.Set(allowedUIDs)
if err != nil {
return err
}
}
if errs := validation.ValidateConfig(config); len(errs) != 0 {
var buffer bytes.Buffer
for _, ve := range errs {
buffer.WriteString(ve.Error())
buffer.WriteString(", ")
}
return errors.New(buffer.String())
}
// If DockerCfgPath is provided in api.Config, then attempt to read the the
// dockercfg file and get the authentication for pulling the builder image.
config.PullAuthentication, _ = dockercfg.NewHelper().GetDockerAuth(config.BuilderImage, dockercfg.PullAuthType)
config.IncrementalAuthentication, _ = dockercfg.NewHelper().GetDockerAuth(tag, dockercfg.PushAuthType)
glog.V(2).Infof("Creating a new S2I builder with build config: %#v\n", describe.DescribeConfig(config))
builder, err := sti.GetStrategy(config)
if err != nil {
return err
}
glog.V(4).Infof("Starting S2I build from %s/%s BuildConfig ...", s.build.Namespace, s.build.Name)
// Set the HTTP and HTTPS proxies to be used by the S2I build.
originalProxies := setHTTPProxy(s.build.Spec.Source.Git.HTTPProxy, s.build.Spec.Source.Git.HTTPSProxy)
if _, err = builder.Build(config); err != nil {
return err
}
// Reset proxies back to their original value.
resetHTTPProxy(originalProxies)
if push {
// Get the Docker push authentication
pushAuthConfig, authPresent := dockercfg.NewHelper().GetDockerAuth(
tag,
dockercfg.PushAuthType,
)
if authPresent {
glog.Infof("Using provided push secret for pushing %s image", tag)
}
glog.Infof("Pushing %s image ...", tag)
if err := pushImage(s.dockerClient, tag, pushAuthConfig); err != nil {
return fmt.Errorf("Failed to push image: %v", err)
}
glog.Infof("Successfully pushed %s", tag)
glog.Flush()
}
return nil
}
开发者ID:rusenask,项目名称:origin,代码行数:96,代码来源:sti.go
注:本文中的github.com/openshift/source-to-image/pkg/api/validation.ValidateConfig函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论