Push pushes an image specified by `rawRef`.
(ctx context.Context, client *containerd.Client, rawRef string, options types.ImagePushOptions)
| 59 | |
| 60 | // Push pushes an image specified by `rawRef`. |
| 61 | func Push(ctx context.Context, client *containerd.Client, rawRef string, options types.ImagePushOptions) error { |
| 62 | parsedReference, err := referenceutil.Parse(rawRef) |
| 63 | if err != nil { |
| 64 | return err |
| 65 | } |
| 66 | |
| 67 | if parsedReference.Protocol != "" { |
| 68 | if parsedReference.Protocol != referenceutil.IPFSProtocol { |
| 69 | return fmt.Errorf("ipfs scheme is only supported but got %q", parsedReference.Protocol) |
| 70 | } |
| 71 | log.G(ctx).Infof("pushing image %q to IPFS", parsedReference) |
| 72 | |
| 73 | // Ensure all the layers are here: https://github.com/containerd/nerdctl/issues/3489 |
| 74 | // XXX what if the image is a CID, or only otherwise available on ipfs? |
| 75 | platMC, err := platformutil.NewMatchComparer(options.AllPlatforms, options.Platforms) |
| 76 | if err != nil { |
| 77 | return err |
| 78 | } |
| 79 | |
| 80 | err = EnsureAllContent(ctx, client, parsedReference.String(), platMC, options.GOptions) |
| 81 | if err != nil { |
| 82 | return err |
| 83 | } |
| 84 | |
| 85 | var ipfsPath string |
| 86 | if options.IpfsAddress != "" { |
| 87 | dir, err := os.MkdirTemp("", "apidirtmp") |
| 88 | if err != nil { |
| 89 | return err |
| 90 | } |
| 91 | defer os.RemoveAll(dir) |
| 92 | if err := filesystem.WriteFile(filepath.Join(dir, "api"), []byte(options.IpfsAddress), 0600); err != nil { |
| 93 | return err |
| 94 | } |
| 95 | ipfsPath = dir |
| 96 | } |
| 97 | |
| 98 | var layerConvert converter.ConvertFunc |
| 99 | if options.Estargz { |
| 100 | layerConvert = eStargzConvertFunc() |
| 101 | } |
| 102 | c, err := ipfs.Push(ctx, client, parsedReference.String(), layerConvert, options.AllPlatforms, options.Platforms, options.IpfsEnsureImage, ipfsPath) |
| 103 | if err != nil { |
| 104 | log.G(ctx).WithError(err).Warnf("ipfs push failed") |
| 105 | return err |
| 106 | } |
| 107 | fmt.Fprintln(options.Stdout, c) |
| 108 | return nil |
| 109 | } |
| 110 | |
| 111 | parsedReference, err = referenceutil.Parse(rawRef) |
| 112 | if err != nil { |
| 113 | return err |
| 114 | } |
| 115 | ref := parsedReference.String() |
| 116 | |
| 117 | platMC, err := platformutil.NewMatchComparer(options.AllPlatforms, options.Platforms) |
| 118 | if err != nil { |
no test coverage detected
searching dependent graphs…