diff --git a/acceptance/testdata/node_app/mydir/myfile.txt b/acceptance/testdata/node_app/mydir/myfile.txt new file mode 100644 index 000000000..f52de0264 --- /dev/null +++ b/acceptance/testdata/node_app/mydir/myfile.txt @@ -0,0 +1 @@ +file in subdir diff --git a/build.go b/build.go index 706c315e4..a953d6771 100644 --- a/build.go +++ b/build.go @@ -154,6 +154,10 @@ func (b *BuildFlags) Detect() (*lifecycle.BuildpackGroup, error) { return nil, errors.Wrap(err, "copy app to workspace volume") } + if err := b.chownDir("/workspace/app", uid, gid); err != nil { + return nil, errors.Wrap(err, "chown app to workspace volume") + } + if err := b.Cli.RunContainer(ctx, ctr.ID, b.Stdout, b.Stderr); err != nil { return nil, errors.Wrap(err, "run detect container") } @@ -325,6 +329,27 @@ func (b *BuildFlags) packUidGid(builder string) (int, int, error) { return uid, gid, nil } +func (b *BuildFlags) chownDir(path string, uid, gid int) error { + ctx := context.Background() + ctr, err := b.Cli.ContainerCreate(ctx, &container.Config{ + Image: b.Builder, + Cmd: []string{"chown", "-R", fmt.Sprintf("%d:%d", uid, gid), path}, + User: "root", + }, &container.HostConfig{ + Binds: []string{ + b.WorkspaceVolume + ":/workspace", + }, + }, nil, "") + if err != nil { + return err + } + defer b.Cli.ContainerRemove(ctx, ctr.ID, dockertypes.ContainerRemoveOptions{}) + if err := b.Cli.RunContainer(ctx, ctr.ID, b.Stdout, b.Stderr); err != nil { + return err + } + return nil +} + func (b *BuildFlags) exportVolume(image, volName string) (string, func(), error) { ctx := context.Background() ctr, err := b.Cli.ContainerCreate(ctx, &container.Config{ diff --git a/build_test.go b/build_test.go index 292e66a2e..99d7ab9e6 100644 --- a/build_test.go +++ b/build_test.go @@ -59,11 +59,11 @@ func testBuild(t *testing.T, when spec.G, it spec.S) { }) when("#Detect", func() { - it("copies the app in to docker and chowns it", func() { + it("copies the app in to docker and chowns it (including directories)", func() { _, err := subject.Detect() assertNil(t, err) - for _, name := range []string{"/workspace/app", "/workspace/app/app.js"} { + for _, name := range []string{"/workspace/app", "/workspace/app/app.js", "/workspace/app/mydir", "/workspace/app/mydir/myfile.txt"} { txt, err := exec.Command("docker", "run", "-v", subject.WorkspaceVolume+":/workspace", subject.Builder, "ls", "-ld", name).Output() assertNil(t, err) assertContains(t, string(txt), "pack pack")