@@ -16,6 +16,7 @@ import (
16
16
"github.com/moby/buildkit/cmd/buildctl/build"
17
17
bccommon "github.com/moby/buildkit/cmd/buildctl/common"
18
18
gateway "github.com/moby/buildkit/frontend/gateway/client"
19
+ "github.com/moby/buildkit/identity"
19
20
"github.com/moby/buildkit/session"
20
21
"github.com/moby/buildkit/session/auth/authprovider"
21
22
"github.com/moby/buildkit/session/sshforward/sshprovider"
@@ -100,6 +101,10 @@ var buildCommand = cli.Command{
100
101
Name : "source-policy-file" ,
101
102
Usage : "Read source policy file from a JSON file" ,
102
103
},
104
+ cli.StringFlag {
105
+ Name : "ref-file" ,
106
+ Usage : "Write build ref to a file" ,
107
+ },
103
108
},
104
109
}
105
110
@@ -209,6 +214,8 @@ func buildAction(clicontext *cli.Context) error {
209
214
210
215
eg , ctx := errgroup .WithContext (bccommon .CommandContext (clicontext ))
211
216
217
+ ref := identity .NewID ()
218
+
212
219
solveOpt := client.SolveOpt {
213
220
Exports : exports ,
214
221
// LocalDirs is set later
@@ -220,6 +227,7 @@ func buildAction(clicontext *cli.Context) error {
220
227
Session : attachable ,
221
228
AllowedEntitlements : allowed ,
222
229
SourcePolicy : srcPol ,
230
+ Ref : ref ,
223
231
}
224
232
225
233
solveOpt .FrontendAttrs , err = build .ParseOpt (clicontext .StringSlice ("opt" ))
@@ -255,6 +263,13 @@ func buildAction(clicontext *cli.Context) error {
255
263
}
256
264
}
257
265
266
+ refFile := clicontext .String ("ref-file" )
267
+ if refFile != "" {
268
+ defer func () {
269
+ continuity .AtomicWriteFile (refFile , []byte (ref ), 0666 )
270
+ }()
271
+ }
272
+
258
273
// not using shared context to not disrupt display but let is finish reporting errors
259
274
pw , err := progresswriter .NewPrinter (context .TODO (), os .Stderr , clicontext .String ("progress" ))
260
275
if err != nil {
0 commit comments