Skip to content

Commit 64cdc0a

Browse files
committed
buildctl: add ref-file to get history record for a build
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent e7ff7ea commit 64cdc0a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cmd/buildctl/build.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/moby/buildkit/cmd/buildctl/build"
1717
bccommon "github.com/moby/buildkit/cmd/buildctl/common"
1818
gateway "github.com/moby/buildkit/frontend/gateway/client"
19+
"github.com/moby/buildkit/identity"
1920
"github.com/moby/buildkit/session"
2021
"github.com/moby/buildkit/session/auth/authprovider"
2122
"github.com/moby/buildkit/session/sshforward/sshprovider"
@@ -100,6 +101,10 @@ var buildCommand = cli.Command{
100101
Name: "source-policy-file",
101102
Usage: "Read source policy file from a JSON file",
102103
},
104+
cli.StringFlag{
105+
Name: "ref-file",
106+
Usage: "Write build ref to a file",
107+
},
103108
},
104109
}
105110

@@ -209,6 +214,8 @@ func buildAction(clicontext *cli.Context) error {
209214

210215
eg, ctx := errgroup.WithContext(bccommon.CommandContext(clicontext))
211216

217+
ref := identity.NewID()
218+
212219
solveOpt := client.SolveOpt{
213220
Exports: exports,
214221
// LocalDirs is set later
@@ -220,6 +227,7 @@ func buildAction(clicontext *cli.Context) error {
220227
Session: attachable,
221228
AllowedEntitlements: allowed,
222229
SourcePolicy: srcPol,
230+
Ref: ref,
223231
}
224232

225233
solveOpt.FrontendAttrs, err = build.ParseOpt(clicontext.StringSlice("opt"))
@@ -255,6 +263,13 @@ func buildAction(clicontext *cli.Context) error {
255263
}
256264
}
257265

266+
refFile := clicontext.String("ref-file")
267+
if refFile != "" {
268+
defer func() {
269+
continuity.AtomicWriteFile(refFile, []byte(ref), 0666)
270+
}()
271+
}
272+
258273
// not using shared context to not disrupt display but let is finish reporting errors
259274
pw, err := progresswriter.NewPrinter(context.TODO(), os.Stderr, clicontext.String("progress"))
260275
if err != nil {

0 commit comments

Comments
 (0)