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

Function generateBuildctlArgs

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

Source from the content-addressed store, hash-verified

205}
206
207func generateBuildctlArgs(ctx context.Context, client *containerd.Client, options types.BuilderBuildOptions) (buildCtlBinary string,
208 buildctlArgs []string, needsLoading bool, metaFile string, tags []string, cleanup func(), err error) {
209
210 buildctlBinary, err := buildkitutil.BuildctlBinary()
211 if err != nil {
212 return "", nil, false, "", nil, nil, err
213 }
214
215 output := options.Output
216 if output == "" {
217 info, err := client.Server(ctx)
218 if err != nil {
219 return "", nil, false, "", nil, nil, err
220 }
221 sharable, err := isImageSharable(options.BuildKitHost, options.GOptions.Namespace, info.UUID, options.GOptions.Snapshotter, options.Platform)
222 if err != nil {
223 return "", nil, false, "", nil, nil, err
224 }
225 if sharable {
226 output = "type=image,unpack=true" // ensure the target stage is unlazied (needed for any snapshotters)
227 } else {
228 output = "type=docker"
229 if len(options.Platform) > 1 {
230 // For avoiding `error: failed to solve: docker exporter does not currently support exporting manifest lists`
231 // TODO: consider using type=oci for single-options.Platform build too
232 output = "type=oci"
233 }
234 needsLoading = true
235 }
236 } else {
237 if !strings.Contains(output, "type=") {
238 // should accept --output <DIR> as an alias of --output
239 // type=local,dest=<DIR>
240 output = fmt.Sprintf("type=local,dest=%s", output)
241 }
242 if strings.Contains(output, "type=docker") || strings.Contains(output, "type=oci") {
243 if !strings.Contains(output, "dest=") {
244 needsLoading = true
245 }
246 }
247 }
248 if tags = strutil.DedupeStrSlice(options.Tag); len(tags) > 0 {
249 ref := tags[0]
250 parsedReference, err := referenceutil.Parse(ref)
251 if err != nil {
252 return "", nil, false, "", nil, nil, err
253 }
254 output += ",name=" + parsedReference.String()
255
256 // pick the first tag and add it to output
257 for idx, tag := range tags {
258 parsedReference, err = referenceutil.Parse(tag)
259 if err != nil {
260 return "", nil, false, "", nil, nil, err
261 }
262 tags[idx] = parsedReference.String()
263 }
264 } else if len(tags) == 0 {

Callers 1

BuildFunction · 0.85

Calls 14

BuildctlBinaryFunction · 0.92
DedupeStrSliceFunction · 0.92
ParseFunction · 0.92
BuildctlBaseArgsFunction · 0.92
WriteTempDockerfileFunction · 0.92
BuildKitFileFunction · 0.92
ParseExtraHostsFunction · 0.92
isImageSharableFunction · 0.85
parseContextNamesFunction · 0.85
NameMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…