(ctx context.Context, client *containerd.Client, options types.BuilderBuildOptions)
| 63 | } |
| 64 | |
| 65 | func Build(ctx context.Context, client *containerd.Client, options types.BuilderBuildOptions) error { |
| 66 | buildctlBinary, buildctlArgs, needsLoading, metaFile, tags, cleanup, err := generateBuildctlArgs(ctx, client, options) |
| 67 | if err != nil { |
| 68 | return err |
| 69 | } |
| 70 | if cleanup != nil { |
| 71 | defer cleanup() |
| 72 | } |
| 73 | |
| 74 | log.L.Debugf("running %s %v", buildctlBinary, buildctlArgs) |
| 75 | buildctlCmd := exec.Command(buildctlBinary, buildctlArgs...) |
| 76 | buildctlCmd.Env = os.Environ() |
| 77 | |
| 78 | var buildctlStdout io.Reader |
| 79 | if needsLoading { |
| 80 | buildctlStdout, err = buildctlCmd.StdoutPipe() |
| 81 | if err != nil { |
| 82 | return err |
| 83 | } |
| 84 | } else { |
| 85 | buildctlCmd.Stdout = options.Stdout |
| 86 | } |
| 87 | if !options.Quiet { |
| 88 | buildctlCmd.Stderr = options.Stderr |
| 89 | } |
| 90 | |
| 91 | if err := buildctlCmd.Start(); err != nil { |
| 92 | return err |
| 93 | } |
| 94 | |
| 95 | if needsLoading { |
| 96 | platMC, err := platformutil.NewMatchComparer(false, options.Platform) |
| 97 | if err != nil { |
| 98 | return err |
| 99 | } |
| 100 | if err = loadImage(ctx, buildctlStdout, options.GOptions.Namespace, options.GOptions.Address, options.GOptions.Snapshotter, options.Stdout, platMC, options.Quiet); err != nil { |
| 101 | return err |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | if err = buildctlCmd.Wait(); err != nil { |
| 106 | return err |
| 107 | } |
| 108 | |
| 109 | if options.IidFile != "" { |
| 110 | id, err := getDigestFromMetaFile(metaFile) |
| 111 | if err != nil { |
| 112 | return err |
| 113 | } |
| 114 | if err := filesystem.WriteFile(options.IidFile, []byte(id), 0644); err != nil { |
| 115 | return err |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | if len(tags) > 1 { |
| 120 | log.L.Debug("Found more than 1 tag") |
| 121 | imageService := client.ImageService() |
| 122 | image, err := imageService.Get(ctx, tags[0]) |
no test coverage detected
searching dependent graphs…