Skip to content

Commit

Permalink
enhance skopeo inspect
Browse files Browse the repository at this point in the history
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
  • Loading branch information
ningmingxiao committed Jul 19, 2022
1 parent 2bb3f3e commit d913113
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 10 deletions.
2 changes: 1 addition & 1 deletion internal/image/docker_schema2.go
Expand Up @@ -326,7 +326,7 @@ func (m *manifestSchema2) convertToManifestSchema1(ctx context.Context, options
ID: v1ID,
Parent: parentV1ID,
Comment: historyEntry.Comment,
Created: historyEntry.Created,
Created: *historyEntry.Created,
Author: historyEntry.Author,
ThrowAway: historyEntry.EmptyLayer,
}
Expand Down
18 changes: 16 additions & 2 deletions manifest/docker_schema1.go
Expand Up @@ -228,10 +228,24 @@ func (m *Schema1) Inspect(_ func(types.BlobInfo) ([]byte, error)) (*types.ImageI
Architecture: s1.Architecture,
Os: s1.OS,
Layers: layerInfosToStrings(m.LayerInfos()),
LayersDetail: imgInspectLayersFromLayerInfos(m.LayerInfos()),
History: nil,
Author: s1.Author,
Size: s1.Size,
}
if s1.Config != nil {
i.Labels = s1.Config.Labels
i.Env = s1.Config.Env
i.Config.Env = s1.Config.Env
i.Config.Labels = s1.Config.Labels
i.Config.User = s1.Config.User
i.Config.Volumes = s1.Config.Volumes
i.Config.Entrypoint = s1.Config.Entrypoint
for key, value := range s1.Config.ExposedPorts {
exposedPorts := make(map[string]struct{})
exposedPorts[string(key)] = value
i.Config.ExposedPorts = exposedPorts
}
i.Config.StopSignal = s1.Config.StopSignal
i.Config.WorkingDir = s1.Config.WorkingDir
}
return i, nil
}
Expand Down
42 changes: 35 additions & 7 deletions manifest/docker_schema2.go
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/containers/image/v5/pkg/strslice"
"github.com/containers/image/v5/types"
"github.com/opencontainers/go-digest"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
)

// Schema2Descriptor is a “descriptor” in docker/distribution schema 2.
Expand Down Expand Up @@ -151,11 +152,11 @@ type Schema2History struct {
// Schema2Image is an Image in docker/docker/image.
type Schema2Image struct {
Schema2V1Image
Parent digest.Digest `json:"parent,omitempty"`
RootFS *Schema2RootFS `json:"rootfs,omitempty"`
History []Schema2History `json:"history,omitempty"`
OSVersion string `json:"os.version,omitempty"`
OSFeatures []string `json:"os.features,omitempty"`
Parent digest.Digest `json:"parent,omitempty"`
RootFS *Schema2RootFS `json:"rootfs,omitempty"`
History []imgspecv1.History `json:"history,omitempty"`
OSVersion string `json:"os.version,omitempty"`
OSFeatures []string `json:"os.features,omitempty"`
}

// Schema2FromManifest creates a Schema2 manifest instance from a manifest blob.
Expand Down Expand Up @@ -215,6 +216,19 @@ func (m *Schema2) LayerInfos() []LayerInfo {
return blobs
}

// imgInspectLayersFromLayerInfos converts a list of layer infos, presumably obtained from a Manifest.LayerInfos()
// method call, into a format suitable for inclusion in a types.ImageInspectInfo structure.
func imgInspectLayersFromLayerInfos(infos []LayerInfo) []types.LayerDetail {
layers := make([]types.LayerDetail, len(infos))
for i, info := range infos {
layers[i].MIMEType = info.MediaType
layers[i].Digest = info.Digest
layers[i].Size = info.Size
layers[i].Annotations = info.Annotations
}
return layers
}

var schema2CompressionMIMETypeSets = []compressionMIMETypeSet{
{
mtsUncompressed: DockerV2Schema2ForeignLayerMediaType,
Expand Down Expand Up @@ -279,10 +293,24 @@ func (m *Schema2) Inspect(configGetter func(types.BlobInfo) ([]byte, error)) (*t
Variant: s2.Variant,
Os: s2.OS,
Layers: layerInfosToStrings(m.LayerInfos()),
LayersDetail: imgInspectLayersFromLayerInfos(m.LayerInfos()),
History: s2.History,
Author: s2.Author,
Size: s2.Size,
}
if s2.Config != nil {
i.Labels = s2.Config.Labels
i.Env = s2.Config.Env
i.Config.Env = s2.Config.Env
i.Config.Labels = s2.Config.Labels
i.Config.User = s2.Config.User
i.Config.Volumes = s2.Config.Volumes
i.Config.Entrypoint = s2.Config.Entrypoint
for key, value := range s2.Config.ExposedPorts {
exposedPorts := make(map[string]struct{})
exposedPorts[string(key)] = value
i.Config.ExposedPorts = exposedPorts
}
i.Config.StopSignal = s2.Config.StopSignal
i.Config.WorkingDir = s2.Config.WorkingDir
}
return i, nil
}
Expand Down
5 changes: 5 additions & 0 deletions manifest/oci.go
Expand Up @@ -220,7 +220,12 @@ func (m *OCI1) Inspect(configGetter func(types.BlobInfo) ([]byte, error)) (*type
Architecture: v1.Architecture,
Os: v1.OS,
Layers: layerInfosToStrings(m.LayerInfos()),
LayersDetail: imgInspectLayersFromLayerInfos(m.LayerInfos()),
Env: v1.Config.Env,
History: v1.History,
Author: v1.Author,
Size: d1.Size,
Config: v1.Config,
}
return i, nil
}
Expand Down
12 changes: 12 additions & 0 deletions types/types.go
Expand Up @@ -466,6 +466,18 @@ type ImageInspectInfo struct {
Os string
Layers []string
Env []string
LayersDetail []LayerDetail
History []v1.History
Author string
Size int64
Config v1.ImageConfig
}

type LayerDetail struct {
MIMEType string
Digest digest.Digest
Size int64
Annotations map[string]string
}

// DockerAuthConfig contains authorization information for connecting to a registry.
Expand Down

0 comments on commit d913113

Please sign in to comment.