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 CREATED field when listing image if date is not specified #2107

Merged
merged 1 commit into from
Nov 5, 2019
Merged

Fix CREATED field when listing image if date is not specified #2107

merged 1 commit into from
Nov 5, 2019

Conversation

jonatasbaldin
Copy link
Contributor

Signed-off-by: Jonatas Baldin jonatas.baldin@gmail.com

Fixes #2047.

- What I did
When listing images with the docker images command, returns <none> in the CREATED field if the date is not specified during the image build. Without this fix, a 292 years ago string was displayed.

- How I did it
Added a special case in the CLI formatter.

- How to verify it

  • Get an image that has no created date docker pull nixery.dev/hello

Before the fix:

  • Run docker images
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
nixery.dev/hello                     latest              866a9896ca80        292 years ago             28.1MB

After the fix:

REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
nixery.dev/hello                     latest              866a9896ca80        <none>              28.1MB

- Description for the changelog
Fix CREATED field when listing image if date is not specified.

- A picture of a cute animal (not mandatory but encouraged)
an alpaca an me
2019-09-14 17 53 24

@jonatasbaldin
Copy link
Contributor Author

hey there, any comments on this? 🌱

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! And apologies for the long delay; maintainers have been quite busy, and there's a bit of a backlog in reviewing pull requests. Left a comment; suggestion following 🤗

@@ -235,6 +235,11 @@ func (c *imageContext) Digest() string {

func (c *imageContext) CreatedSince() string {
createdAt := time.Unix(c.i.Created, 0)

if createdAt.IsZero() {
return "<none>"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking of a slightly different approach; I'll write down a comment / suggestion

@thaJeztah
Copy link
Member

I'm thinking if we should use this special format, or instead to return an empty string. I realise we already have some of the "special" values that we return, and have not been really consistent in that matter (unfortunately; bad choices in the past), e.g. here's an example of docker image ls --format '{{ json . }}' where it's clear we're not really consistent.

{
  "Containers": "N/A",
  "CreatedAt": "2019-08-20 22:19:55 +0200 CEST",
  "CreatedSince": "2 months ago",
  "Digest": "<none>",
  "ID": "961769676411",
  "Repository": "alpine",
  "SharedSize": "N/A",
  "Size": "5.58MB",
  "Tag": "3.10",
  "UniqueSize": "N/A",
  "VirtualSize": "5.582MB"
}

I'm thinking of using an empty string instead. That way, the json output would be closer to what the API returns (and reduce the amount of "presentation" in that format. This would keep the flexibility for users to format it to their liking. For example;

docker image ls -a --format "table {{.ID}}\t{{if .CreatedSince }}{{.CreatedSince}}{{else}}Prehistoric image, may contain dragons{{end}}"

IMAGE ID            CREATED
dc2fed1afb2c        19 hours ago
8c75c34169e5        2 days ago
48479b5deffa        2 days ago
75fed645a5a0        Prehistoric image, may contain dragons
87b2dd3fa15d        3 days ago
3a3b77f619aa        3 days ago
1544ad69a5d2        Prehistoric image, may contain dragons
9614462fec5e        3 days ago
1f61a4270ed5        4 days ago

If we go for this option, I'd be ok with changing the default table format to print <none> or N/A;

defaultImageTableFormat = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedSince}}\t{{.Size}}"
defaultImageTableFormatWithDigest = "table {{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.ID}}\t{{.CreatedSince}}\t{{.Size}}"

I'm slightly leaning towards N/A, but as mentioned, we're already inconsistent, and <none> is also used (for images without tag or digest), so I'm open to suggestions there.

These would then look something like;

	defaultImageTableFormat           = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{if .CreatedSince }}{{.CreatedSince}}{{else}}N/A{{end}}\t{{.Size}}"
	defaultImageTableFormatWithDigest = "table {{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.ID}}\t{{if .CreatedSince }}{{.CreatedSince}}{{else}}N/A{{end}}\t{{.Size}}"

Note: Perhaps as a follow-up, we should consider taking a similar approach for existing fields, but we may need to discuss that, as there could be people relying on the format, even though the cli output format is not a formal API.

@thaJeztah
Copy link
Member

Happy to hear your thoughts! If you agree with my suggestions, could you update the pull request?

As to the empty values themselves; I think this was a bug in BuildKit (not 100% sure), which should be resolved, but I agree that there may still be images with that issue, so it's nice to take those into account

@jonatasbaldin
Copy link
Contributor Author

Hey there! I don't have strong opinions on this, so I'm good going with an empty string return and N/A.

Will make the changes!

@jonatasbaldin
Copy link
Contributor Author

Did the changes ✨ Here's the outputs:

$ ./build/docker-darwin-amd64  images -f reference='nixery.dev/hello'
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nixery.dev/hello    latest              866a9896ca80        N/A                 28.1MB
$ ./build/docker-darwin-amd64 images -f reference='nixery.dev/hello' --format '{{ json .}}'      
{
  "Containers": "N/A",
  "CreatedAt": "0000-12-31 20:53:32 -0306 LMT",
  "CreatedSince": "N/A",
  "Digest": "<none>",
  "ID": "866a9896ca80",
  "Repository": "nixery.dev/hello",
  "SharedSize": "N/A",
  "Size": "28.1MB",
  "Tag": "latest",
  "UniqueSize": "N/A",
  "VirtualSize": "28.13MB"
}

@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "2047-fix-image-createdsince-without-value" git@github.com:jonatasbaldin/cli.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842354553256
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

@@ -235,6 +235,11 @@ func (c *imageContext) Digest() string {

func (c *imageContext) CreatedSince() string {
createdAt := time.Unix(c.i.Created, 0)

if createdAt.IsZero() {
return "N/A"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Could you change this to return an empty string, so that the --format '{{ json .}}' output will show the empty value as-is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man, I'm so sorry, shouldn't do any PRs when I'm waking up hahaha Fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL no worries! 😂

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes look good! erm (my bad, forgot to ask); could you squash your commits down to one? (Let me know if you need a hand on that)

@jonatasbaldin
Copy link
Contributor Author

Squashed ✨!

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@thaJeztah
Copy link
Member

ping @vdemeester @silvin-lubecki PTAL

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @jonatasbaldin ! Just a small change requested 😅

Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
@jonatasbaldin
Copy link
Contributor Author

Hey there, just a gentle nudge on this! @silvin-lubecki answered your comment in the thread ✨

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@silvin-lubecki silvin-lubecki merged commit 9e041dd into docker:master Nov 5, 2019
@silvin-lubecki
Copy link
Contributor

Thank you @jonatasbaldin !!

@thaJeztah thaJeztah added this to the 19.03.6 milestone Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display sensible values if image creation date is unspecified
4 participants