From 38198bd5c3e020f0133a5b64b8181ce57b891d07 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Sat, 29 Sep 2018 19:00:08 +0000 Subject: [PATCH] dockerfile: substitute build args in addition to env vars in RUN's CustomName Example Dockerfile: FROM busybox ARG foo=abc ENV bar=def RUN echo $foo $bar $baz Output without fix: #5 [2/2] RUN echo def #5 digest: sha256:647df948c9689163efaf92b24b38779bc9f8b350482ecc3de3533f86a544c196 #5 name: "[2/2] RUN echo def " #5 started: 2018-09-29 19:01:11.376665368 +0000 UTC #5 0.764 abc def #5 completed: 2018-09-29 19:01:12.320141054 +0000 UTC #5 duration: 943.475686ms Output with fix: #5 [2/2] RUN echo abc def #5 digest: sha256:647df948c9689163efaf92b24b38779bc9f8b350482ecc3de3533f86a544c196 #5 name: "[2/2] RUN echo abc def " #5 started: 2018-09-29 19:01:11.376665368 +0000 UTC #5 0.764 abc def #5 completed: 2018-09-29 19:01:12.320141054 +0000 UTC #5 duration: 943.475686ms Signed-off-by: Tibor Vass --- frontend/dockerfile/dockerfile2llb/convert.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/dockerfile/dockerfile2llb/convert.go b/frontend/dockerfile/dockerfile2llb/convert.go index f32316b2..e6a52d8c 100644 --- a/frontend/dockerfile/dockerfile2llb/convert.go +++ b/frontend/dockerfile/dockerfile2llb/convert.go @@ -608,8 +608,10 @@ func dispatchRun(d *dispatchState, c *instructions.RunCommand, proxy *llb.ProxyE if c.PrependShell { args = withShell(d.image, args) } + env := d.state.Env() opt := []llb.RunOption{llb.Args(args)} for _, arg := range d.buildArgs { + env = append(env, fmt.Sprintf("%s=%s", arg.Key, arg.ValueString())) opt = append(opt, llb.AddEnv(arg.Key, arg.ValueString())) } opt = append(opt, dfCmd(c)) @@ -625,7 +627,7 @@ func dispatchRun(d *dispatchState, c *instructions.RunCommand, proxy *llb.ProxyE return err } opt = append(opt, runMounts...) - opt = append(opt, llb.WithCustomName(prefixCommand(d, uppercaseCmd(processCmdEnv(dopt.shlex, c.String(), d.state.Run(opt...).Env())), d.prefixPlatform, d.state.GetPlatform()))) + opt = append(opt, llb.WithCustomName(prefixCommand(d, uppercaseCmd(processCmdEnv(dopt.shlex, c.String(), env)), d.prefixPlatform, d.state.GetPlatform()))) for _, h := range dopt.extraHosts { opt = append(opt, llb.AddExtraHost(h.Host, h.IP)) }