MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / cacheExportCmd

Function cacheExportCmd

src/cmd/linuxkit/cache_export.go:18–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16)
17
18func cacheExportCmd() *cobra.Command {
19 var (
20 platform string
21 outputFile string
22 format string
23 tagName string
24 )
25 cmd := &cobra.Command{
26 Use: "export",
27 Short: "export individual images from the linuxkit cache",
28 Long: `Export individual images from the linuxkit cache. Supports exporting into multiple formats.`,
29 Args: cobra.MinimumNArgs(1),
30 RunE: func(cmd *cobra.Command, args []string) error {
31 names := args
32 name := names[0]
33 fullname := util.ReferenceExpand(name)
34
35 p, err := cachepkg.NewProvider(cacheDir)
36 if err != nil {
37 log.Fatalf("unable to read a local cache: %v", err)
38 }
39 ref, err := reference.Parse(fullname)
40 if err != nil {
41 log.Fatalf("invalid image name %s: %v", name, err)
42 }
43 desc, err := p.FindDescriptor(&ref)
44 if err != nil {
45 log.Fatalf("unable to find image named %s: %v", name, err)
46 }
47
48 plat, err := v1.ParsePlatform(platform)
49 if err != nil {
50 log.Fatalf("invalid platform %s: %v", platform, err)
51 }
52 platspec := imagespec.Platform{
53 Architecture: plat.Architecture,
54 OS: plat.OS,
55 Variant: plat.Variant,
56 }
57 src := p.NewSource(&ref, &platspec, desc)
58 var reader io.ReadCloser
59 switch format {
60 case "docker":
61 fullTagName := fullname
62 if tagName != "" {
63 fullTagName = util.ReferenceExpand(tagName)
64 }
65 reader, err = src.V1TarReader(fullTagName)
66 case "oci":
67 fullTagName := fullname
68 if tagName != "" {
69 fullTagName = util.ReferenceExpand(tagName)
70 }
71 reader, err = src.OCITarReader(fullTagName)
72 case "filesystem":
73 reader, err = src.TarReader()
74 default:
75 log.Fatalf("requested unknown format %s: %v", name, err)

Callers 1

cacheCmdFunction · 0.85

Calls 6

FindDescriptorMethod · 0.95
NewSourceMethod · 0.95
V1TarReaderMethod · 0.65
OCITarReaderMethod · 0.65
TarReaderMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected