File: textplain.go

package info (click to toggle)
docker.io 27.5.1%2Bdfsg4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,384 kB
  • sloc: sh: 5,847; makefile: 1,146; ansic: 664; python: 162; asm: 133
file content (39 lines) | stat: -rw-r--r-- 917 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package specialimage

import (
	"strings"

	"github.com/distribution/reference"
	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

// TextPlain creates an non-container image that only contains a text/plain blob.
func TextPlain(dir string) (*ocispec.Index, error) {
	ref, err := reference.ParseNormalizedNamed("tianon/test:text-plain")
	if err != nil {
		return nil, err
	}

	emptyJsonDesc, err := writeBlob(dir, "text/plain", strings.NewReader("{}"))
	if err != nil {
		return nil, err
	}

	configDesc := emptyJsonDesc
	configDesc.MediaType = "application/vnd.oci.empty.v1+json"

	desc, err := writeJsonBlob(dir, ocispec.MediaTypeImageManifest, ocispec.Manifest{
		Config: configDesc,
		Layers: []ocispec.Descriptor{
			emptyJsonDesc,
		},
	})
	if err != nil {
		return nil, err
	}
	desc.Annotations = map[string]string{
		"io.containerd.image.name": ref.String(),
	}

	return ociImage(dir, nil, desc)
}