Merge pull request #1473 from NewJorg/40726-addchwonexpand

Expand chown value of ADD command
v0.8
Tõnis Tiigi 2020-05-07 09:12:52 -07:00 committed by GitHub
commit 1e4c221194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 0 deletions

View File

@ -122,6 +122,7 @@ var fileOpTests = []integration.Test{
testWorkdirExists,
testWorkdirCopyIgnoreRelative,
testCopyFollowAllSymlinks,
testDockerfileAddChownExpand,
}
// Tests that depend on the `security.*` entitlements
@ -2258,6 +2259,42 @@ ADD *.tar /dest
require.Equal(t, "content1", string(dt))
}
func testDockerfileAddChownExpand(t *testing.T, sb integration.Sandbox) {
f := getFrontend(t, sb)
isFileOp := getFileOp(t, sb)
dockerfile := []byte(`
FROM busybox
ARG group
ENV owner 1000
ADD --chown=${owner}:${group} foo /
RUN [ "$(stat -c "%u %G" /foo)" == "1000 nogroup" ]
`)
dir, err := tmpdir(
fstest.CreateFile("Dockerfile", dockerfile, 0600),
fstest.CreateFile("foo", []byte(`foo-contents`), 0600),
)
require.NoError(t, err)
defer os.RemoveAll(dir)
c, err := client.New(context.TODO(), sb.Address())
require.NoError(t, err)
defer c.Close()
_, err = f.Solve(context.TODO(), c, client.SolveOpt{
FrontendAttrs: map[string]string{
"build-arg:BUILDKIT_DISABLE_FILEOP": strconv.FormatBool(!isFileOp),
"build-arg:group": "nogroup",
},
LocalDirs: map[string]string{
builder.DefaultLocalNameDockerfile: dir,
builder.DefaultLocalNameContext: dir,
},
}, nil)
require.NoError(t, err)
}
func testSymlinkDestination(t *testing.T, sb integration.Sandbox) {
skipDockerd(t, sb)
f := getFrontend(t, sb)

View File

@ -192,6 +192,11 @@ type AddCommand struct {
// Expand variables
func (c *AddCommand) Expand(expander SingleWordExpander) error {
expandedChown, err := expander(c.Chown)
if err != nil {
return err
}
c.Chown = expandedChown
return expandSliceInPlace(c.SourcesAndDest, expander)
}