github.com/moby/docker@v26.1.3+incompatible/internal/testutils/specialimage/dangling.go (about) 1 package specialimage 2 3 import ( 4 "os" 5 "path/filepath" 6 "strings" 7 8 ocispec "github.com/opencontainers/image-spec/specs-go/v1" 9 ) 10 11 const danglingImageManifestDigest = "sha256:16d365089e5c10e1673ee82ab5bba38ade9b763296ad918bd24b42a1156c5456" // #nosec G101 -- ignoring: Potential hardcoded credentials (gosec) 12 const danglingImageConfigDigest = "sha256:0df1207206e5288f4a989a2f13d1f5b3c4e70467702c1d5d21dfc9f002b7bd43" // #nosec G101 -- ignoring: Potential hardcoded credentials (gosec) 13 14 // Dangling creates an image with no layers and no tag. 15 // It also has an extra org.mobyproject.test.specialimage=1 label set. 16 // Layout: OCI. 17 func Dangling(dir string) (*ocispec.Index, error) { 18 if err := os.WriteFile(filepath.Join(dir, "index.json"), []byte(`{"schemaVersion":2,"manifests":[{"mediaType":"application/vnd.docker.distribution.manifest.v2+json","digest":"sha256:16d365089e5c10e1673ee82ab5bba38ade9b763296ad918bd24b42a1156c5456","size":264,"annotations":{"org.opencontainers.image.created":"2023-05-19T08:00:44Z"},"platform":{"architecture":"amd64","os":"linux"}}]}`), 0o644); err != nil { 19 return nil, err 20 } 21 22 if err := os.WriteFile(filepath.Join(dir, "manifest.json"), []byte(`[{"Config":"blobs/sha256/0df1207206e5288f4a989a2f13d1f5b3c4e70467702c1d5d21dfc9f002b7bd43","RepoTags":null,"Layers":null}]`), 0o644); err != nil { 23 return nil, err 24 } 25 26 if err := os.Mkdir(filepath.Join(dir, "blobs"), 0o755); err != nil { 27 return nil, err 28 } 29 30 blobsDir := filepath.Join(dir, "blobs", "sha256") 31 if err := os.Mkdir(blobsDir, 0o755); err != nil { 32 return nil, err 33 } 34 35 if err := os.WriteFile(filepath.Join(blobsDir, strings.TrimPrefix(danglingImageManifestDigest, "sha256:")), []byte(`{"schemaVersion":2,"mediaType":"application/vnd.docker.distribution.manifest.v2+json","config":{"mediaType":"application/vnd.docker.container.image.v1+json","digest":"sha256:0df1207206e5288f4a989a2f13d1f5b3c4e70467702c1d5d21dfc9f002b7bd43","size":390},"layers":[]}`), 0o644); err != nil { 36 return nil, err 37 } 38 if err := os.WriteFile(filepath.Join(blobsDir, strings.TrimPrefix(danglingImageConfigDigest, "sha256:")), []byte(`{"architecture":"amd64","config":{"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"WorkingDir":"/","Labels":{"org.mobyproject.test.specialimage":"1"},"OnBuild":null},"created":null,"history":[{"created_by":"LABEL org.mobyproject.test.specialimage=1","comment":"buildkit.dockerfile.v0","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":null}}`), 0o644); err != nil { 39 return nil, err 40 } 41 42 return nil, nil 43 }