| 47 | } |
| 48 | |
| 49 | func (cmd *pullCommand) Run(args []string) (err error) { |
| 50 | reexec() |
| 51 | |
| 52 | // Get the specified image. |
| 53 | cmd.image = args[0] |
| 54 | |
| 55 | // Create the client. |
| 56 | c, err := client.New(stateDir, backend, nil) |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | defer c.Close() |
| 61 | |
| 62 | fmt.Printf("Pulling %s...\n", cmd.image) |
| 63 | |
| 64 | var listedImage *client.ListedImage |
| 65 | // Create the context. |
| 66 | ctx := appcontext.Context() |
| 67 | sess, sessDialer, err := c.Session(ctx) |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | ctx = session.NewContext(ctx, sess.ID()) |
| 72 | ctx = namespaces.WithNamespace(ctx, "buildkit") |
| 73 | eg, ctx := errgroup.WithContext(ctx) |
| 74 | |
| 75 | eg.Go(func() error { |
| 76 | return sess.Run(ctx, sessDialer) |
| 77 | }) |
| 78 | eg.Go(func() error { |
| 79 | defer sess.Close() |
| 80 | var err error |
| 81 | listedImage, err = c.Pull(ctx, cmd.image) |
| 82 | return err |
| 83 | }) |
| 84 | if err := eg.Wait(); err != nil { |
| 85 | return err |
| 86 | } |
| 87 | |
| 88 | fmt.Printf("Pulled: %s\n", listedImage.Target.Digest) |
| 89 | fmt.Printf("Size: %s\n", units.BytesSize(float64(listedImage.ContentSize))) |
| 90 | |
| 91 | return nil |
| 92 | } |