-
Notifications
You must be signed in to change notification settings - Fork 199
/
manifest_only_image.go
88 lines (72 loc) · 1.91 KB
/
manifest_only_image.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package container_registry_extensions
import (
"fmt"
"time"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/google/go-containerregistry/pkg/v1/partial"
"github.com/google/go-containerregistry/pkg/v1/types"
)
type manifestOnlyImage struct {
CreatedAt time.Time
Labels map[string]string
}
func NewManifestOnlyImage(labels map[string]string) v1.Image {
img, err := newManifestOnlyImage(labels)
if err != nil {
panic(fmt.Sprintf("unable to create new ManifestOnlyImage: %s", err))
}
return img
}
func newManifestOnlyImage(labels map[string]string) (v1.Image, error) {
t := time.Now()
img, err := partial.UncompressedToImage(manifestOnlyImage{
CreatedAt: t,
Labels: labels,
})
if err != nil {
return nil, err
}
img, err = mutate.CreatedAt(img, v1.Time{Time: t})
if err != nil {
return nil, err
}
cfg, err := img.ConfigFile()
if err != nil {
return nil, err
}
layers, err := img.Layers()
if err != nil {
return nil, err
}
cfg.History = make([]v1.History, len(layers))
img, err = mutate.ConfigFile(img, cfg)
if err != nil {
return nil, err
}
return img, nil
}
// MediaType implements partial.UncompressedImageCore.
func (i manifestOnlyImage) MediaType() (types.MediaType, error) {
return types.DockerManifestSchema2, nil
}
// RawConfigFile implements partial.UncompressedImageCore.
func (i manifestOnlyImage) RawConfigFile() ([]byte, error) {
return partial.RawConfigFile(i)
}
// ConfigFile implements v1.Image.
func (i manifestOnlyImage) ConfigFile() (*v1.ConfigFile, error) {
return &v1.ConfigFile{
Created: v1.Time{i.CreatedAt},
Config: v1.Config{
Labels: i.Labels,
},
RootFS: v1.RootFS{
Type: "layers",
DiffIDs: []v1.Hash{EmptyUncompressedLayer.diffID},
},
}, nil
}
func (i manifestOnlyImage) LayerByDiffID(h v1.Hash) (partial.UncompressedLayer, error) {
return EmptyUncompressedLayer, nil
}