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

Function Commit

pkg/cmd/container/commit.go:35–79  ·  view source on GitHub ↗

Commit will commit a container’s file changes or settings into a new image.

(ctx context.Context, client *containerd.Client, rawRef string, req string, options types.ContainerCommitOptions)

Source from the content-addressed store, hash-verified

33
34// Commit will commit a container’s file changes or settings into a new image.
35func Commit(ctx context.Context, client *containerd.Client, rawRef string, req string, options types.ContainerCommitOptions) error {
36 parsedReference, err := referenceutil.Parse(rawRef)
37 if err != nil {
38 return err
39 }
40
41 changes, err := parseChanges(options.Change)
42 if err != nil {
43 return err
44 }
45
46 opts := &commit.Opts{
47 Author: options.Author,
48 Message: options.Message,
49 Ref: parsedReference.String(),
50 Pause: options.Pause,
51 Changes: changes,
52 Compression: options.Compression,
53 Format: options.Format,
54 EstargzOptions: options.EstargzOptions,
55 ZstdChunkedOptions: options.ZstdChunkedOptions,
56 }
57
58 walker := &containerwalker.ContainerWalker{
59 Client: client,
60 OnFound: func(ctx context.Context, found containerwalker.Found) error {
61 if found.MatchCount > 1 {
62 return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
63 }
64 imageID, err := commit.Commit(ctx, client, found.Container, opts, options.GOptions)
65 if err != nil {
66 return err
67 }
68 _, err = fmt.Fprintln(options.Stdout, imageID)
69 return err
70 },
71 }
72 n, err := walker.Walk(ctx, req)
73 if err != nil {
74 return err
75 } else if n == 0 {
76 return fmt.Errorf("no such container %s", req)
77 }
78 return nil
79}
80
81func parseChanges(userChanges []string) (commit.Changes, error) {
82 const (

Callers 1

commitActionFunction · 0.92

Calls 5

WalkMethod · 0.95
ParseFunction · 0.92
CommitFunction · 0.92
parseChangesFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…