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

Function ExtractDockerArchive

cmd/nerdctl/helpers/testing.go:38–73  ·  view source on GitHub ↗
(archiveTarPath, rootfsPath string)

Source from the content-addressed store, hash-verified

36}
37
38func ExtractDockerArchive(archiveTarPath, rootfsPath string) error {
39 if err := os.MkdirAll(rootfsPath, 0755); err != nil {
40 return err
41 }
42 workDir, err := os.MkdirTemp("", "extract-docker-archive")
43 if err != nil {
44 return err
45 }
46 defer os.RemoveAll(workDir)
47 if err := ExtractTarFile(workDir, archiveTarPath); err != nil {
48 return err
49 }
50 manifestJSONPath := filepath.Join(workDir, "manifest.json")
51 manifestJSONBytes, err := os.ReadFile(manifestJSONPath)
52 if err != nil {
53 return err
54 }
55 var mani DockerArchiveManifestJSON
56 if err := json.Unmarshal(manifestJSONBytes, &mani); err != nil {
57 return err
58 }
59 if len(mani) > 1 {
60 return fmt.Errorf("multi-image archive cannot be extracted: contains %d images", len(mani))
61 }
62 if len(mani) < 1 {
63 return errors.New("invalid archive")
64 }
65 ent := mani[0]
66 for _, l := range ent.Layers {
67 layerTarPath := filepath.Join(workDir, l)
68 if err := ExtractTarFile(rootfsPath, layerTarPath); err != nil {
69 return err
70 }
71 }
72 return nil
73}
74
75type DockerArchiveManifestJSON []DockerArchiveManifestJSONEntry
76

Callers 1

prepareCustomRootfsFunction · 0.92

Calls 2

ExtractTarFileFunction · 0.85
UnmarshalMethod · 0.80

Tested by 1

prepareCustomRootfsFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…