Skip to content

Commit

Permalink
Set image config created time
Browse files Browse the repository at this point in the history
Before this was just using whatever created time was set on the base
image config which was incorrect.

Example using the `docker buildx bake runc-jammy-container` command:

Before:

docker image ls | grep runc
runc                                          jammy             8d1d42e074f3   25 minutes ago   228MB

After:

  docker image ls | grep runc
  runc                                          jammy             03c24620c8fa   5 seconds ago    228MB

**Note**: how the created time before was 25mins ago (b/c apparently the base
jammy image was recently updated, I've seen this be 2 weeks) compared to
after its 5 seconds ago.

Signed-off-by: Brian Goff <[email protected]>
  • Loading branch information
cpuguy83 committed Nov 23, 2024
1 parent 30d6102 commit da30e53
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions frontend/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"time"

"github.com/Azure/dalec"
"github.com/containerd/platforms"
Expand Down Expand Up @@ -88,6 +89,10 @@ func BuildWithPlatform(ctx context.Context, client gwclient.Client, f PlatformBu
targetKey := GetTargetKey(dc)

ref, cfg, err := f(ctx, client, platform, spec, targetKey)
if cfg != nil {
now := time.Now()
cfg.Created = &now
}
return ref, cfg, nil, err
})
if err != nil {
Expand Down
16 changes: 14 additions & 2 deletions test/azlinux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"

"github.com/Azure/dalec"
"github.com/Azure/dalec/frontend/azlinux"
Expand All @@ -17,6 +18,7 @@ import (
gwclient "github.com/moby/buildkit/frontend/gateway/client"
moby_buildkit_v1_frontend "github.com/moby/buildkit/frontend/gateway/pb"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"golang.org/x/exp/maps"
"gotest.tools/v3/assert"
)

Expand Down Expand Up @@ -528,7 +530,16 @@ echo "$BAR" > bar.txt
)
sr.Evaluate = true

solveT(ctx, t, gwc, sr)
beforeBuild := time.Now()
res := solveT(ctx, t, gwc, sr)

dt, ok := res.Metadata[exptypes.ExporterImageConfigKey]
assert.Assert(t, ok, "result metadata should contain an image config: available metadata: %s", strings.Join(maps.Keys(res.Metadata), ", "))

var cfg dalec.DockerImageSpec
assert.Assert(t, json.Unmarshal(dt, &cfg))
assert.Check(t, cfg.Created.After(beforeBuild))
assert.Check(t, cfg.Created.Before(time.Now()))

// Make sure the test framework was actually executed by the build target.
// This appends a test case so that is expected to fail and as such cause the build to fail.
Expand All @@ -542,7 +553,8 @@ echo "$BAR" > bar.txt
// update the spec in the solve request
withSpec(ctx, t, &spec)(&newSolveRequestConfig{req: &sr})

if _, err := gwc.Solve(ctx, sr); err == nil {
res, err := gwc.Solve(ctx, sr)

Check failure on line 556 in test/azlinux_test.go

View workflow job for this annotation

GitHub Actions / lint

SA4006: this value of `res` is never used (staticcheck)
if err == nil {
t.Fatal("expected test spec to run with error but got none")
}
})
Expand Down

0 comments on commit da30e53

Please sign in to comment.