Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 79189e7

Browse files
committed
Remove CREATED from bundle.json
Removes the created date from the bundle.json and the image ls output This has been done to make builds more reproducable as the current solution means the App Image ID will change on each build We will look at re-adding the created date once the underlying bundle store has been updated. Signed-off-by: Nick Adcock <[email protected]>
1 parent d198096 commit 79189e7

File tree

8 files changed

+71
-142
lines changed

8 files changed

+71
-142
lines changed

e2e/images_test.go

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ func TestImageList(t *testing.T) {
6565

6666
insertBundles(t, cmd)
6767

68-
expected := `REPOSITORY TAG APP IMAGE ID APP NAME CREATED
69-
a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
70-
b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
71-
my.registry:5000/c-myapp latest [a-f0-9]{12} push-pull [La-z0-9 ]+ ago[ ]*
68+
expected := `REPOSITORY TAG APP IMAGE ID APP NAME
69+
a-simple-app latest [a-f0-9]{12} simple
70+
b-simple-app latest [a-f0-9]{12} simple
71+
my.registry:5000/c-myapp latest [a-f0-9]{12} push-pull
7272
`
7373

7474
expectImageListOutput(t, cmd, expected)
@@ -87,10 +87,10 @@ func TestImageListDigests(t *testing.T) {
8787
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
8888
cmd := info.configuredCmd
8989
insertBundles(t, cmd)
90-
expected := `REPOSITORY TAG DIGEST APP IMAGE ID APP NAME CREATED
91-
a-simple-app latest <none> [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
92-
b-simple-app latest <none> [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
93-
my.registry:5000/c-myapp latest <none> [a-f0-9]{12} push-pull [La-z0-9 ]+ ago[ ]*
90+
expected := `REPOSITORY TAG DIGEST APP IMAGE ID APP NAME
91+
a-simple-app latest <none> [a-f0-9]{12} simple
92+
b-simple-app latest <none> [a-f0-9]{12} simple
93+
my.registry:5000/c-myapp latest <none> [a-f0-9]{12} push-pull
9494
`
9595
expectImageListDigestsOutput(t, cmd, expected)
9696
})
@@ -121,7 +121,7 @@ func TestImageRmForce(t *testing.T) {
121121
cmd.Command = dockerCli.Command("app", "image", "rm", "--force", imageID)
122122
icmd.RunCmd(cmd).Assert(t, icmd.Success)
123123

124-
expectedOutput := "REPOSITORY TAG APP IMAGE ID APP NAME CREATED \n"
124+
expectedOutput := "REPOSITORY TAG APP IMAGE ID APP NAME \n"
125125
expectImageListOutput(t, cmd, expectedOutput)
126126
})
127127
}
@@ -151,7 +151,7 @@ Deleted: b-simple-app:latest`,
151151
Err: `b-simple-app:latest: reference not found`,
152152
})
153153

154-
expectedOutput := "REPOSITORY TAG APP IMAGE ID APP NAME CREATED \n"
154+
expectedOutput := "REPOSITORY TAG APP IMAGE ID APP NAME \n"
155155
expectImageListOutput(t, cmd, expectedOutput)
156156
})
157157
}
@@ -169,8 +169,8 @@ func TestImageTag(t *testing.T) {
169169
cmd.Command = dockerCli.Command("app", "build", "--tag", "a-simple-app", filepath.Join("testdata", "simple"))
170170
icmd.RunCmd(cmd).Assert(t, icmd.Success)
171171

172-
singleImageExpectation := `REPOSITORY TAG APP IMAGE ID APP NAME CREATED[ ]*
173-
a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
172+
singleImageExpectation := `REPOSITORY TAG APP IMAGE ID APP NAME
173+
a-simple-app latest [a-f0-9]{12} simple
174174
`
175175
expectImageListOutput(t, cmd, singleImageExpectation)
176176

@@ -219,63 +219,63 @@ a-simple-app latest [a-f0-9]{12} simple
219219
// tag image with only names
220220
dockerAppImageTag("a-simple-app", "b-simple-app")
221221
icmd.RunCmd(cmd).Assert(t, icmd.Success)
222-
expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED[ ]*
223-
a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
224-
b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
222+
expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME
223+
a-simple-app latest [a-f0-9]{12} simple
224+
b-simple-app latest [a-f0-9]{12} simple
225225
`)
226226

227227
// target tag
228228
dockerAppImageTag("a-simple-app", "a-simple-app:0.1")
229229
icmd.RunCmd(cmd).Assert(t, icmd.Success)
230-
expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED[ ]*
231-
a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
232-
a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
233-
b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
230+
expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME
231+
a-simple-app 0.1 [a-f0-9]{12} simple
232+
a-simple-app latest [a-f0-9]{12} simple
233+
b-simple-app latest [a-f0-9]{12} simple
234234
`)
235235

236236
// source tag
237237
dockerAppImageTag("a-simple-app:0.1", "c-simple-app")
238238
icmd.RunCmd(cmd).Assert(t, icmd.Success)
239-
expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED[ ]*
240-
a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
241-
a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
242-
b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
243-
c-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
239+
expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME
240+
a-simple-app 0.1 [a-f0-9]{12} simple
241+
a-simple-app latest [a-f0-9]{12} simple
242+
b-simple-app latest [a-f0-9]{12} simple
243+
c-simple-app latest [a-f0-9]{12} simple
244244
`)
245245

246246
// source and target tags
247247
dockerAppImageTag("a-simple-app:0.1", "b-simple-app:0.2")
248248
icmd.RunCmd(cmd).Assert(t, icmd.Success)
249-
expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED[ ]*
250-
a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
251-
a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
252-
b-simple-app 0.2 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
253-
b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
254-
c-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
249+
expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME
250+
a-simple-app 0.1 [a-f0-9]{12} simple
251+
a-simple-app latest [a-f0-9]{12} simple
252+
b-simple-app 0.2 [a-f0-9]{12} simple
253+
b-simple-app latest [a-f0-9]{12} simple
254+
c-simple-app latest [a-f0-9]{12} simple
255255
`)
256256

257257
// given a new application
258258
cmd.Command = dockerCli.Command("app", "build", "--tag", "push-pull", filepath.Join("testdata", "push-pull"))
259259
icmd.RunCmd(cmd).Assert(t, icmd.Success)
260-
expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED[ ]*
261-
push-pull latest [a-f0-9]{12} push-pull [La-z0-9 ]+ ago[ ]*
262-
a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
263-
a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
264-
b-simple-app 0.2 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
265-
b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
266-
c-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
260+
expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME
261+
a-simple-app 0.1 [a-f0-9]{12} simple
262+
a-simple-app latest [a-f0-9]{12} simple
263+
b-simple-app 0.2 [a-f0-9]{12} simple
264+
b-simple-app latest [a-f0-9]{12} simple
265+
c-simple-app latest [a-f0-9]{12} simple
266+
push-pull latest [a-f0-9]{12} push-pull
267267
`)
268268

269269
// can be tagged to an existing tag
270270
dockerAppImageTag("push-pull", "b-simple-app:0.2")
271271
icmd.RunCmd(cmd).Assert(t, icmd.Success)
272-
expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED[ ]*
273-
b-simple-app 0.2 [a-f0-9]{12} push-pull [La-z0-9 ]+ ago[ ]*
274-
push-pull latest [a-f0-9]{12} push-pull [La-z0-9 ]+ ago[ ]*
275-
a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
276-
a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
277-
b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
278-
c-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]*
272+
expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME
273+
a-simple-app 0.1 [a-f0-9]{12} simple
274+
a-simple-app latest [a-f0-9]{12} simple
275+
b-simple-app 0.2 [a-f0-9]{12} push-pull
276+
b-simple-app latest [a-f0-9]{12} simple
277+
c-simple-app latest [a-f0-9]{12} simple
278+
push-pull latest [a-f0-9]{12} push-pull
279279
`)
280280
})
281281
}

internal/commands/image/formatter.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package image
22

33
import (
4-
"time"
5-
64
"github.com/docker/cli/cli/command/formatter"
75
"github.com/docker/docker/pkg/stringid"
8-
"github.com/docker/go-units"
96
)
107

118
const (
12-
defaultImageTableFormat = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.Name}}\t{{if .CreatedSince }}{{.CreatedSince}}{{else}}N/A{{end}}\t"
13-
defaultImageTableFormatWithDigest = "table {{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.ID}}\t{{.Name}}\t\t{{if .CreatedSince }}{{.CreatedSince}}{{else}}N/A{{end}}\t"
9+
defaultImageTableFormat = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.Name}}\t"
10+
defaultImageTableFormatWithDigest = "table {{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.ID}}\t{{.Name}}\t\t"
1411

1512
imageIDHeader = "APP IMAGE ID"
1613
repositoryHeader = "REPOSITORY"
@@ -69,12 +66,11 @@ type imageContext struct {
6966
func newImageContext() *imageContext {
7067
imageCtx := imageContext{}
7168
imageCtx.Header = formatter.SubHeaderContext{
72-
"ID": imageIDHeader,
73-
"Name": imageNameHeader,
74-
"Repository": repositoryHeader,
75-
"Tag": tagHeader,
76-
"Digest": digestHeader,
77-
"CreatedSince": formatter.CreatedSinceHeader,
69+
"ID": imageIDHeader,
70+
"Name": imageNameHeader,
71+
"Repository": repositoryHeader,
72+
"Tag": tagHeader,
73+
"Digest": digestHeader,
7874
}
7975
return &imageCtx
8076
}
@@ -117,10 +113,3 @@ func (c *imageContext) Digest() string {
117113
}
118114
return c.i.Digest
119115
}
120-
121-
func (c *imageContext) CreatedSince() string {
122-
if c.i.Created.IsZero() {
123-
return ""
124-
}
125-
return units.HumanDuration(time.Now().UTC().Sub(c.i.Created)) + " ago"
126-
}

internal/commands/image/list.go

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package image
22

33
import (
4-
"sort"
5-
"time"
6-
7-
"github.com/docker/app/internal/packager"
84
"github.com/docker/app/internal/relocated"
95
"github.com/docker/app/internal/store"
106
"github.com/docker/cli/cli/command"
@@ -61,7 +57,6 @@ func runList(dockerCli command.Cli, options imageListOption, bundleStore store.B
6157
Format: NewImageFormat(options.format, options.quiet, options.digests),
6258
}
6359

64-
sortImages(images)
6560
return Write(ctx, images)
6661
}
6762

@@ -94,25 +89,12 @@ func getImageID(bundle *relocated.Bundle, ref reference.Reference) (string, erro
9489
return stringid.TruncateID(id.String()), nil
9590
}
9691

97-
func sortImages(images []imageDesc) {
98-
sort.SliceStable(images, func(i, j int) bool {
99-
if images[i].Created.IsZero() {
100-
return false
101-
}
102-
if images[j].Created.IsZero() {
103-
return true
104-
}
105-
return images[i].Created.After(images[j].Created)
106-
})
107-
}
108-
10992
type imageDesc struct {
110-
ID string `json:"id,omitempty"`
111-
Name string `json:"name,omitempty"`
112-
Repository string `json:"repository,omitempty"`
113-
Tag string `json:"tag,omitempty"`
114-
Digest string `json:"digest,omitempty"`
115-
Created time.Time `json:"created,omitempty"`
93+
ID string `json:"id,omitempty"`
94+
Name string `json:"name,omitempty"`
95+
Repository string `json:"repository,omitempty"`
96+
Tag string `json:"tag,omitempty"`
97+
Digest string `json:"digest,omitempty"`
11698
}
11799

118100
func getImageDesc(bundle *relocated.Bundle, ref reference.Reference) imageDesc {
@@ -130,18 +112,11 @@ func getImageDesc(bundle *relocated.Bundle, ref reference.Reference) imageDesc {
130112
if t, ok := ref.(reference.Digested); ok {
131113
digest = t.Digest().String()
132114
}
133-
var created time.Time
134-
if payload, err := packager.CustomPayload(bundle.Bundle); err == nil {
135-
if createdPayload, ok := payload.(packager.CustomPayloadCreated); ok {
136-
created = createdPayload.CreatedTime()
137-
}
138-
}
139115
return imageDesc{
140116
ID: id,
141117
Name: bundle.Name,
142118
Repository: repository,
143119
Tag: tag,
144120
Digest: digest,
145-
Created: created,
146121
}
147122
}

internal/commands/image/list_test.go

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bytes"
66
"fmt"
77
"testing"
8-
"time"
98

109
"github.com/docker/app/internal/relocated"
1110

@@ -84,10 +83,10 @@ func TestListCmd(t *testing.T) {
8483
}{
8584
{
8685
name: "TestList",
87-
expectedOutput: `REPOSITORY TAG APP IMAGE ID APP NAME CREATED
88-
foo/bar <none> 3f825b2d0657 Digested App N/A
89-
foo/bar 1.0 9aae408ee04f Foo App N/A
90-
<none> <none> a855ac937f2e Quiet App N/A
86+
expectedOutput: `REPOSITORY TAG APP IMAGE ID APP NAME
87+
foo/bar <none> 3f825b2d0657 Digested App
88+
foo/bar 1.0 9aae408ee04f Foo App
89+
<none> <none> a855ac937f2e Quiet App
9190
`,
9291
options: imageListOption{format: "table"},
9392
},
@@ -103,10 +102,10 @@ a855ac937f2e sha256:a855ac937f2ed375ba4396bbc49c4093e124da933acd2713fb9bc
103102
{
104103
name: "TestListWithDigests",
105104
//nolint:lll
106-
expectedOutput: `REPOSITORY TAG DIGEST APP IMAGE ID APP NAME CREATED
107-
foo/bar <none> sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865 3f825b2d0657 Digested App N/A
108-
foo/bar 1.0 <none> 9aae408ee04f Foo App N/A
109-
<none> <none> sha256:a855ac937f2ed375ba4396bbc49c4093e124da933acd2713fb9bc17d7562a087 a855ac937f2e Quiet App N/A
105+
expectedOutput: `REPOSITORY TAG DIGEST APP IMAGE ID APP NAME
106+
foo/bar <none> sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865 3f825b2d0657 Digested App
107+
foo/bar 1.0 <none> 9aae408ee04f Foo App
108+
<none> <none> sha256:a855ac937f2ed375ba4396bbc49c4093e124da933acd2713fb9bc17d7562a087 a855ac937f2e Quiet App
110109
`,
111110
options: imageListOption{format: "table", digests: true},
112111
},
@@ -127,22 +126,6 @@ a855ac937f2e
127126
}
128127
}
129128

130-
func TestSortImages(t *testing.T) {
131-
images := []imageDesc{
132-
{ID: "1", Created: time.Date(2016, time.August, 15, 0, 0, 0, 0, time.UTC)},
133-
{ID: "2"},
134-
{ID: "3"},
135-
{ID: "4", Created: time.Date(2018, time.August, 15, 0, 0, 0, 0, time.UTC)},
136-
{ID: "5", Created: time.Date(2017, time.August, 15, 0, 0, 0, 0, time.UTC)},
137-
}
138-
sortImages(images)
139-
assert.Equal(t, "4", images[0].ID)
140-
assert.Equal(t, "5", images[1].ID)
141-
assert.Equal(t, "1", images[2].ID)
142-
assert.Equal(t, "2", images[3].ID)
143-
assert.Equal(t, "3", images[4].ID)
144-
}
145-
146129
func parseReference(t *testing.T, s string) reference.Reference {
147130
ref, err := reference.Parse(s)
148131
assert.NilError(t, err)

internal/packager/cnab_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestToCNAB(t *testing.T) {
2222
assert.NilError(t, err)
2323
s := golden.Get(t, "bundle-json.golden")
2424
expectedLiteral := regexp.QuoteMeta(string(s))
25-
expected := fmt.Sprintf(expectedLiteral, DockerAppPayloadVersionCurrent, internal.Version, `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d+Z`)
25+
expected := fmt.Sprintf(expectedLiteral, DockerAppPayloadVersionCurrent, internal.Version)
2626
matches, err := regexp.Match(expected, actualJSON)
2727
assert.NilError(t, err)
2828
assert.Assert(t, matches)

internal/packager/custom.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66
"io"
7-
"time"
87

98
"github.com/deislabs/cnab-go/bundle"
109
"github.com/docker/app/internal"
@@ -28,39 +27,29 @@ type DockerAppCustom struct {
2827
Payload json.RawMessage `json:"payload,omitempty"`
2928
}
3029

31-
// CustomPayloadCreated is a custom payload with a created time
32-
type CustomPayloadCreated interface {
33-
CreatedTime() time.Time
34-
}
35-
3630
// CustomPayloadAppVersion is a custom payload with a docker app version
3731
type CustomPayloadAppVersion interface {
3832
AppVersion() string
3933
}
4034

4135
type payloadV1_0 struct {
42-
Version string `json:"app-version"`
43-
Created time.Time `json:"created"`
44-
}
45-
46-
func (p payloadV1_0) CreatedTime() time.Time {
47-
return p.Created
36+
Version string `json:"app-version"`
4837
}
4938

5039
func (p payloadV1_0) AppVersion() string {
5140
return p.Version
5241
}
5342

5443
func newCustomPayload() (json.RawMessage, error) {
55-
p := payloadV1_0{Created: time.Now().UTC(), Version: internal.Version}
44+
p := payloadV1_0{Version: internal.Version}
5645
j, err := json.Marshal(&p)
5746
if err != nil {
5847
return nil, err
5948
}
6049
return j, nil
6150
}
6251

63-
// CheckAppVersion
52+
// CheckAppVersion prints a warning if the bundle was built with a different version of docker app
6453
func CheckAppVersion(stderr io.Writer, bndl *bundle.Bundle) error {
6554
payload, err := CustomPayload(bndl)
6655
if err != nil {

0 commit comments

Comments
 (0)