dockerfile: fix quoting of meta args

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-18.09
Tonis Tiigi 2018-08-24 16:41:51 -07:00
parent 277037a77f
commit 4963ed7ea4
2 changed files with 52 additions and 4 deletions

View File

@ -81,12 +81,15 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
return nil, nil, err return nil, nil, err
} }
shlex := shell.NewLex(dockerfile.EscapeToken)
for _, metaArg := range metaArgs { for _, metaArg := range metaArgs {
if metaArg.Value != nil {
*metaArg.Value, _ = shlex.ProcessWordWithMap(*metaArg.Value, metaArgsToMap(optMetaArgs))
}
optMetaArgs = append(optMetaArgs, setKVValue(metaArg.KeyValuePairOptional, opt.BuildArgs)) optMetaArgs = append(optMetaArgs, setKVValue(metaArg.KeyValuePairOptional, opt.BuildArgs))
} }
shlex := shell.NewLex(dockerfile.EscapeToken)
metaResolver := opt.MetaResolver metaResolver := opt.MetaResolver
if metaResolver == nil { if metaResolver == nil {
metaResolver = imagemetaresolver.Default() metaResolver = imagemetaresolver.Default()

View File

@ -74,11 +74,52 @@ func TestIntegration(t *testing.T) {
testPlatformArgsImplicit, testPlatformArgsImplicit,
testPlatformArgsExplicit, testPlatformArgsExplicit,
testExportMultiPlatform, testExportMultiPlatform,
testQuotedMetaArgs,
}) })
} }
func newContainerd(cdAddress string) (*containerd.Client, error) { func testQuotedMetaArgs(t *testing.T, sb integration.Sandbox) {
return containerd.New(cdAddress, containerd.WithTimeout(60*time.Second)) t.Parallel()
dockerfile := []byte(`
ARG a1="box"
ARG a2="$a1-foo"
FROM busy$a1 AS build
ARG a2
ARG a3="bar-$a2"
RUN echo -n $a3 > /out
FROM scratch
COPY --from=build /out .
`)
dir, err := tmpdir(
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)
require.NoError(t, err)
defer os.RemoveAll(dir)
c, err := client.New(context.TODO(), sb.Address())
require.NoError(t, err)
defer c.Close()
destDir, err := ioutil.TempDir("", "buildkit")
require.NoError(t, err)
defer os.RemoveAll(destDir)
_, err = c.Solve(context.TODO(), nil, client.SolveOpt{
Frontend: "dockerfile.v0",
LocalDirs: map[string]string{
builder.LocalNameDockerfile: dir,
builder.LocalNameContext: dir,
},
Exporter: client.ExporterLocal,
ExporterOutputDir: destDir,
}, nil)
require.NoError(t, err)
dt, err := ioutil.ReadFile(filepath.Join(destDir, "out"))
require.NoError(t, err)
require.Equal(t, "bar-box-foo", string(dt))
} }
func testExportMultiPlatform(t *testing.T, sb integration.Sandbox) { func testExportMultiPlatform(t *testing.T, sb integration.Sandbox) {
@ -2666,3 +2707,7 @@ func checkAllRemoved(t *testing.T, c *client.Client, sb integration.Sandbox) {
break break
} }
} }
func newContainerd(cdAddress string) (*containerd.Client, error) {
return containerd.New(cdAddress, containerd.WithTimeout(60*time.Second))
}