forked from LaconicNetwork/kompose
Merge pull request #1147 from hangyan/push-image-flag
Add flag to turn off push image when kompose up
This commit is contained in:
commit
ab111b5d88
@ -37,6 +37,8 @@ var (
|
|||||||
UpBuildBranch string
|
UpBuildBranch string
|
||||||
UpBuildRepo string
|
UpBuildRepo string
|
||||||
UpController string
|
UpController string
|
||||||
|
// UpPushImage decides if we should push the docker image
|
||||||
|
UpPushImage bool
|
||||||
)
|
)
|
||||||
|
|
||||||
var upCmd = &cobra.Command{
|
var upCmd = &cobra.Command{
|
||||||
@ -53,6 +55,7 @@ var upCmd = &cobra.Command{
|
|||||||
// Create the Convert options.
|
// Create the Convert options.
|
||||||
UpOpt = kobject.ConvertOptions{
|
UpOpt = kobject.ConvertOptions{
|
||||||
Build: UpBuild,
|
Build: UpBuild,
|
||||||
|
PushImage: UpPushImage,
|
||||||
Replicas: UpReplicas,
|
Replicas: UpReplicas,
|
||||||
InputFiles: GlobalFiles,
|
InputFiles: GlobalFiles,
|
||||||
Provider: GlobalProvider,
|
Provider: GlobalProvider,
|
||||||
@ -82,6 +85,7 @@ func init() {
|
|||||||
upCmd.Flags().StringVar(&UpBuild, "build", "local", `Set the type of build ("local"|"build-config" (OpenShift only)|"none")`)
|
upCmd.Flags().StringVar(&UpBuild, "build", "local", `Set the type of build ("local"|"build-config" (OpenShift only)|"none")`)
|
||||||
upCmd.Flags().StringVar(&UpBuildRepo, "build-repo", "", "Specify source repository for buildconfig (default remote origin)")
|
upCmd.Flags().StringVar(&UpBuildRepo, "build-repo", "", "Specify source repository for buildconfig (default remote origin)")
|
||||||
upCmd.Flags().StringVar(&UpBuildBranch, "build-branch", "", "Specify repository branch to use for buildconfig (default master)")
|
upCmd.Flags().StringVar(&UpBuildBranch, "build-branch", "", "Specify repository branch to use for buildconfig (default master)")
|
||||||
|
upCmd.Flags().BoolVar(&UpPushImage, "push-image", true, "If we should push the docker image we built")
|
||||||
upCmd.Flags().StringVar(&UpController, "controller", "", `Set the output controller ("deployment"|"daemonSet"|"replicationController")`)
|
upCmd.Flags().StringVar(&UpController, "controller", "", `Set the output controller ("deployment"|"daemonSet"|"replicationController")`)
|
||||||
upCmd.Flags().MarkHidden("insecure-repository")
|
upCmd.Flags().MarkHidden("insecure-repository")
|
||||||
upCmd.Flags().MarkHidden("build-repo")
|
upCmd.Flags().MarkHidden("build-repo")
|
||||||
|
|||||||
@ -41,6 +41,7 @@ type ConvertOptions struct {
|
|||||||
BuildRepo string
|
BuildRepo string
|
||||||
BuildBranch string
|
BuildBranch string
|
||||||
Build string
|
Build string
|
||||||
|
PushImage bool
|
||||||
CreateChart bool
|
CreateChart bool
|
||||||
GenerateYaml bool
|
GenerateYaml bool
|
||||||
GenerateJSON bool
|
GenerateJSON bool
|
||||||
|
|||||||
@ -846,7 +846,7 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
|
|||||||
return nil, fmt.Errorf("image key required within build parameters in order to build and push service '%s'", name)
|
return nil, fmt.Errorf("image key required within build parameters in order to build and push service '%s'", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Build key detected. Attempting to build and push image '%s'", service.Image)
|
log.Infof("Build key detected. Attempting to build image '%s'", service.Image)
|
||||||
|
|
||||||
// Get the directory where the compose file is
|
// Get the directory where the compose file is
|
||||||
composeFileDir, err := transformer.GetComposeFileDir(opt.InputFiles)
|
composeFileDir, err := transformer.GetComposeFileDir(opt.InputFiles)
|
||||||
@ -861,11 +861,13 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Push the built image to the repo!
|
// Push the built image to the repo!
|
||||||
err = transformer.PushDockerImage(service, name)
|
if opt.PushImage {
|
||||||
if err != nil {
|
log.Infof("Push image enabled. Attempting to push image '%s'", service.Image)
|
||||||
return nil, errors.Wrapf(err, "Unable to push Docker image for service %v", name)
|
err = transformer.PushDockerImage(service, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "Unable to push Docker image for service %v", name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's no "image" key, use the name of the container that's built
|
// If there's no "image" key, use the name of the container that's built
|
||||||
|
|||||||
@ -316,9 +316,11 @@ func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Push the built container to the repo!
|
// Push the built container to the repo!
|
||||||
err = transformer.PushDockerImage(service, name)
|
if opt.PushImage {
|
||||||
if err != nil {
|
err = transformer.PushDockerImage(service, name)
|
||||||
log.Fatalf("Unable to push Docker image for service %v: %v", name, err)
|
if err != nil {
|
||||||
|
log.Fatalf("Unable to push Docker image for service %v: %v", name, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user