Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(image): parse image.inspect.Created field only for non-empty values #6948

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions pkg/fanal/image/daemon/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,25 @@ func (img *image) ConfigFile() (*v1.ConfigFile, error) {
return nil, xerrors.Errorf("unable to get diff IDs: %w", err)
}

created, err := time.Parse(time.RFC3339Nano, img.inspect.Created)
if err != nil {
return nil, xerrors.Errorf("failed parsing created %s: %w", img.inspect.Created, err)
var created v1.Time
// `Created` field can be empty. Skip parsing to avoid error.
// cf. https://github.com/moby/moby/blob/8e96db1c328d0467b015768e42a62c0f834970bb/api/types/types.go#L76-L77
if img.inspect.Created != "" {
var t time.Time
t, err = time.Parse(time.RFC3339Nano, img.inspect.Created)
if err != nil {
return nil, xerrors.Errorf("failed parsing created %s: %w", img.inspect.Created, err)
}
created = v1.Time{
Time: t,
}
}

return &v1.ConfigFile{
Architecture: img.inspect.Architecture,
Author: img.inspect.Author,
Container: img.inspect.Container,
Created: v1.Time{Time: created},
Created: created,
DockerVersion: img.inspect.DockerVersion,
Config: img.imageConfig(img.inspect.Config),
History: img.history,
Expand Down