Просмотр исходного кода

c8d/inspect: Fill `Created` time if available

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski 2 лет назад
Родитель
Сommit
b9b8b6597a
1 измененных файлов с 9 добавлено и 5 удалено
  1. 9 5
      daemon/containerd/image.go

+ 9 - 5
daemon/containerd/image.go

@@ -68,14 +68,17 @@ func (i *ImageService) GetImage(ctx context.Context, refOrID string, options ima
 		exposedPorts[nat.Port(k)] = v
 		exposedPorts[nat.Port(k)] = v
 	}
 	}
 
 
+	derefTimeSafely := func(t *time.Time) time.Time {
+		if t != nil {
+			return *t
+		}
+		return time.Time{}
+	}
+
 	var imgHistory []image.History
 	var imgHistory []image.History
 	for _, h := range ociimage.History {
 	for _, h := range ociimage.History {
-		var created time.Time
-		if h.Created != nil {
-			created = *h.Created
-		}
 		imgHistory = append(imgHistory, image.History{
 		imgHistory = append(imgHistory, image.History{
-			Created:    created,
+			Created:    derefTimeSafely(h.Created),
 			Author:     h.Author,
 			Author:     h.Author,
 			CreatedBy:  h.CreatedBy,
 			CreatedBy:  h.CreatedBy,
 			Comment:    h.Comment,
 			Comment:    h.Comment,
@@ -88,6 +91,7 @@ func (i *ImageService) GetImage(ctx context.Context, refOrID string, options ima
 		ID:           string(desc.Digest),
 		ID:           string(desc.Digest),
 		OS:           ociimage.OS,
 		OS:           ociimage.OS,
 		Architecture: ociimage.Architecture,
 		Architecture: ociimage.Architecture,
+		Created:      derefTimeSafely(ociimage.Created),
 		Config: &containertypes.Config{
 		Config: &containertypes.Config{
 			Entrypoint:   ociimage.Config.Entrypoint,
 			Entrypoint:   ociimage.Config.Entrypoint,
 			Env:          ociimage.Config.Env,
 			Env:          ociimage.Config.Env,