MCPcopy Create free account
hub / github.com/containerd/nerdctl / Build

Function Build

pkg/cmd/builder/build.go:65–145  ·  view source on GitHub ↗
(ctx context.Context, client *containerd.Client, options types.BuilderBuildOptions)

Source from the content-addressed store, hash-verified

63}
64
65func 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])

Callers 1

buildActionFunction · 0.92

Calls 11

NewMatchComparerFunction · 0.92
WriteFileFunction · 0.92
generateBuildctlArgsFunction · 0.85
loadImageFunction · 0.85
getDigestFromMetaFileFunction · 0.85
StartMethod · 0.80
CommandMethod · 0.65
GetMethod · 0.65
CreateMethod · 0.65
DeleteMethod · 0.65
WaitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…