@@ -27,6 +27,7 @@ import (
27
27
"github.com/moby/buildkit/frontend/dockerfile/parser"
28
28
"github.com/moby/buildkit/frontend/dockerfile/shell"
29
29
"github.com/moby/buildkit/frontend/dockerui"
30
+ "github.com/moby/buildkit/frontend/dockerui/types"
30
31
"github.com/moby/buildkit/frontend/subrequests/lint"
31
32
"github.com/moby/buildkit/frontend/subrequests/outline"
32
33
"github.com/moby/buildkit/frontend/subrequests/targets"
@@ -146,7 +147,7 @@ func ListTargets(ctx context.Context, dt []byte) (*targets.List, error) {
146
147
return nil , err
147
148
}
148
149
149
- stages , _ , err := instructions .Parse (dockerfile .AST , nil )
150
+ stages , _ , err := instructions .Parse (dockerfile .AST , nil , instructions. ParseOpts {} )
150
151
if err != nil {
151
152
return nil , err
152
153
}
@@ -288,7 +289,10 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
288
289
289
290
proxyEnv := proxyEnvFromBuildArgs (opt .BuildArgs )
290
291
291
- stages , metaArgs , err := instructions .Parse (dockerfile .AST , lint )
292
+ parseOpts := instructions.ParseOpts {
293
+ InstructionHook : opt .InstructionHook ,
294
+ }
295
+ stages , metaArgs , err := instructions .Parse (dockerfile .AST , lint , parseOpts )
292
296
if err != nil {
293
297
return nil , err
294
298
}
@@ -688,6 +692,7 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
688
692
llbCaps : opt .LLBCaps ,
689
693
sourceMap : opt .SourceMap ,
690
694
lint : lint ,
695
+ instHook : opt .InstructionHook ,
691
696
}
692
697
693
698
if err = dispatchOnBuildTriggers (d , d .image .Config .OnBuild , opt ); err != nil {
@@ -838,6 +843,7 @@ type dispatchOpt struct {
838
843
llbCaps * apicaps.CapSet
839
844
sourceMap * llb.SourceMap
840
845
lint * linter.Linter
846
+ instHook * types.InstructionHook
841
847
}
842
848
843
849
func dispatch (d * dispatchState , cmd command , opt dispatchOpt ) error {
@@ -1081,6 +1087,9 @@ type command struct {
1081
1087
}
1082
1088
1083
1089
func dispatchOnBuildTriggers (d * dispatchState , triggers []string , opt dispatchOpt ) error {
1090
+ parseOpts := instructions.ParseOpts {
1091
+ InstructionHook : opt .instHook ,
1092
+ }
1084
1093
for _ , trigger := range triggers {
1085
1094
ast , err := parser .Parse (strings .NewReader (trigger ))
1086
1095
if err != nil {
@@ -1089,7 +1098,7 @@ func dispatchOnBuildTriggers(d *dispatchState, triggers []string, opt dispatchOp
1089
1098
if len (ast .AST .Children ) != 1 {
1090
1099
return errors .New ("onbuild trigger should be a single expression" )
1091
1100
}
1092
- ic , err := instructions .ParseCommand (ast .AST .Children [0 ])
1101
+ ic , err := instructions .ParseCommand (ast .AST .Children [0 ], parseOpts )
1093
1102
if err != nil {
1094
1103
return err
1095
1104
}
@@ -1185,6 +1194,12 @@ func dispatchRun(d *dispatchState, c *instructions.RunCommand, proxy *llb.ProxyE
1185
1194
args = withShell (d .image , args )
1186
1195
}
1187
1196
1197
+ argsForHistory := args
1198
+ if dopt .instHook != nil && dopt .instHook .Run != nil {
1199
+ args = append (dopt .instHook .Run .Entrypoint , args ... )
1200
+ // leave argsForHistory unmodified
1201
+ }
1202
+
1188
1203
env , err := d .state .Env (context .TODO ())
1189
1204
if err != nil {
1190
1205
return err
@@ -1251,7 +1266,7 @@ func dispatchRun(d *dispatchState, c *instructions.RunCommand, proxy *llb.ProxyE
1251
1266
}
1252
1267
1253
1268
d .state = d .state .Run (opt ... ).Root ()
1254
- return commitToHistory (& d .image , "RUN " + runCommandString (args , d .buildArgs , shell .BuildEnvs (env )), true , & d .state , d .epoch )
1269
+ return commitToHistory (& d .image , "RUN " + runCommandString (argsForHistory , d .buildArgs , shell .BuildEnvs (env )), true , & d .state , d .epoch )
1255
1270
}
1256
1271
1257
1272
func dispatchWorkdir (d * dispatchState , c * instructions.WorkdirCommand , commit bool , opt * dispatchOpt ) error {
0 commit comments