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