Browse code

Allow pulling base image by default in dockerbuild

Michal Fojtik authored on 2016/05/06 21:32:23
Showing 4 changed files
... ...
@@ -8428,6 +8428,7 @@ _oc_ex_dockerbuild()
8428 8428
     flags_with_completion=()
8429 8429
     flags_completion=()
8430 8430
 
8431
+    flags+=("--allow-pull")
8431 8432
     flags+=("--dockerfile=")
8432 8433
     flags_with_completion+=("--dockerfile")
8433 8434
     flags_completion+=("_filedir")
... ...
@@ -12013,6 +12013,7 @@ _openshift_cli_ex_dockerbuild()
12013 12013
     flags_with_completion=()
12014 12014
     flags_completion=()
12015 12015
 
12016
+    flags+=("--allow-pull")
12016 12017
     flags+=("--dockerfile=")
12017 12018
     flags_with_completion+=("--dockerfile")
12018 12019
     flags_completion+=("_filedir")
... ...
@@ -39,6 +39,7 @@ type DockerbuildOptions struct {
39 39
 	Directory      string
40 40
 	Tag            string
41 41
 	DockerfilePath string
42
+	AllowPull      bool
42 43
 	Keyring        credentialprovider.DockerKeyring
43 44
 	Arguments      cmdutil.Environment
44 45
 }
... ...
@@ -67,6 +68,7 @@ func NewCmdDockerbuild(fullName string, f *clientcmd.Factory, out, errOut io.Wri
67 67
 	}
68 68
 
69 69
 	cmd.Flags().StringVar(&options.DockerfilePath, "dockerfile", options.DockerfilePath, "An optional path to a Dockerfile to use.")
70
+	cmd.Flags().BoolVar(&options.AllowPull, "allow-pull", true, "Pull the images that are not present.")
70 71
 	cmd.MarkFlagFilename("dockerfile")
71 72
 
72 73
 	return cmd
... ...
@@ -109,6 +111,7 @@ func (o *DockerbuildOptions) Run() error {
109 109
 	defer f.Close()
110 110
 	e := builder.NewClientExecutor(o.Client)
111 111
 	e.Out, e.ErrOut = o.Out, o.Err
112
+	e.AllowPull = o.AllowPull
112 113
 	e.Directory = o.Directory
113 114
 	e.Tag = o.Tag
114 115
 	e.AuthFn = o.Keyring.Lookup
... ...
@@ -284,7 +284,8 @@ func (e *ClientExecutor) LoadImage(from string) (*docker.Image, error) {
284 284
 	var lastErr error
285 285
 	for _, config := range auth {
286 286
 		// TODO: handle IDs?
287
-		if err = e.Client.PullImage(docker.PullImageOptions{Repository: from}, config); err == nil {
287
+		// TODO: use RawJSONStream:true and handle the output nicely
288
+		if err = e.Client.PullImage(docker.PullImageOptions{Repository: from, OutputStream: e.Out}, config); err == nil {
288 289
 			break
289 290
 		}
290 291
 		lastErr = err