Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Added created date to app images #735

Merged
merged 1 commit into from
Nov 12, 2019

Conversation

zappy-shu
Copy link
Contributor

- What I did

Added a created date field to the custom payload of the bundle.json which is used to display the time since the app image was built in human readable format on docker app image ls as the CREATED column.

- How I did it

Created a v1.0 struct for the custom payload in bundle.json that stores the creation date at build time. A constant is used to track which version of the custom payload is to be deserialized rather than using the docker app version. This is to make it easier to check which struct matches which versions.

As the entire bundle.json is deserialized at once the custom payload needs to be re-serialized before deserializing into the concrete type as it is stored as a simple map[string]interface{}.

The human readable output is done using the github.com/docker/go-units package, same as with docker image ls.

- How to verify it

Run a docker app build. The resulting bundle.json should have a custom section similar to the following:


	"custom": {
		"com.docker.app": {
			"payload": {
				"created": "2019-11-07T14:18:41.9539586Z"
			},
			"version": "1.0.0"
		}
	},

Note that the created field should be in UTC.

Running docker app image ls should print a CREATED column showing the amount of time since the app image was built or blank if the image was built using an older version of docker app.

Example output:

REPOSITORY TAG    APP IMAGE ID APP NAME    CREATED
test1      latest acb44aed7b77 hello-world 4 days ago
test2      latest acb44aed7b77 hello-world Less than a second ago
rumpl/nick <none> 1d1a57daebbf voting-app

- Description for the changelog

Added the creation date to the App bundle and prints the time since creation in the docker app image ls output

- A picture of a cute animal (not mandatory)

kitten-2019-11-12

Added a created date field to the custom payload of the bundle.json.
This is packaged as part of the app image at build time.

The CREATED column has been added to the `app image ls` output. This
displays the time since the app image was built in the same human
readable format as `image ls`.

As the creation date is dynamic the app image ID will be unique for each
build even if nothing else has changed. To adjust the tests for this the
golden bundle.json is now checked using regex matching instead of string
matching.

Simalarly, the e2e tests for `app image ls` are checked with regexes for
the CREATED column as the exact value will depend on how long the tests
take to run.

Signed-off-by: Nick Adcock <nick.adcock@docker.com>
Copy link
Member

@eunomie eunomie left a comment

Choose a reason for hiding this comment

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

LGTM

@zappy-shu zappy-shu changed the title Added created date to app images WIP Added created date to app images Nov 12, 2019
@codecov
Copy link

codecov bot commented Nov 12, 2019

Codecov Report

Merging #735 into master will increase coverage by 0.73%.
The diff coverage is 41.17%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #735      +/-   ##
==========================================
+ Coverage    69.3%   70.03%   +0.73%     
==========================================
  Files          63       64       +1     
  Lines        3388     3651     +263     
==========================================
+ Hits         2348     2557     +209     
- Misses        731      747      +16     
- Partials      309      347      +38
Impacted Files Coverage Δ
internal/commands/root.go 63.95% <0%> (-8.42%) ⬇️
internal/commands/run.go 61.95% <100%> (+0.41%) ⬆️
internal/commands/validate.go 75% <100%> (+0.8%) ⬆️
internal/cliopts/installerContext.go 27.58% <100%> (+2.58%) ⬆️
internal/commands/inspect.go 16.66% <0%> (-0.62%) ⬇️
internal/packager/cnab.go 97.67% <0%> (-0.28%) ⬇️
internal/packager/custom.go 61.29% <0%> (ø)
internal/commands/image/rm.go 65.21% <0%> (+2.71%) ⬆️
internal/commands/image/list.go 87.67% <0%> (+3.99%) ⬆️
internal/commands/image/tag.go 91.07% <0%> (+6.07%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e0989c...9fb9b2d. Read the comment docs.

@zappy-shu zappy-shu changed the title WIP Added created date to app images Added created date to app images Nov 12, 2019
@zappy-shu zappy-shu merged commit 7fc0612 into docker:master Nov 12, 2019
@@ -23,7 +24,11 @@ func insertBundles(t *testing.T, cmd icmd.Cmd) {

func assertImageListOutput(t *testing.T, cmd icmd.Cmd, expected string) {
result := icmd.RunCmd(cmd).Assert(t, icmd.Success)
match, _ := regexp.MatchString(expected, result.Stdout())
stdout := result.Stdout()
match, _ := regexp.MatchString(expected, stdout)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the error could be asserted here.

match, _ := regexp.MatchString(expected, stdout)
if !match {
fmt.Println(stdout)
}
assert.Assert(t, match)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can add a third argument here, instead of checking match before assertion.
assert.Assert(t, match, stdout)

@@ -46,6 +51,7 @@ func verifyImageIDListOutput(t *testing.T, cmd icmd.Cmd, count int, distinct int
for scanner.Scan() {
lines = append(lines, scanner.Text())
counter[scanner.Text()]++
fmt.Println(scanner.Text())
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we really print here?

if createdPayload, ok := payload.(packager.CustomPayloadCreated); ok {
return units.HumanDuration(time.Now().UTC().Sub(createdPayload.CreatedTime())) + " ago"
}
return ""
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it should be empty "" or "N/A" ? @thaJeztah WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Ideally, would use a go template, which would allow setting N/A in the template (separating presentation from the value); see docker/cli#2107

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep right, we're fixing it in a follow-up, thanks @thaJeztah 😸

This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants