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)
| 33 | |
| 34 | // Commit will commit a container’s file changes or settings into a new image. |
| 35 | func 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 | |
| 81 | func parseChanges(userChanges []string) (commit.Changes, error) { |
| 82 | const ( |
no test coverage detected
searching dependent graphs…