From ed52e8b7ce8771e036bafb0f25023b94997a4f0d Mon Sep 17 00:00:00 2001 From: Dave Goddard Date: Mon, 24 Sep 2018 11:15:20 -0300 Subject: [PATCH] chown app directory after upload Due to setting the uid,gid on upload this was fixed for files, but NOT directories. We now force a "chown" after the upload [buildpack/pack#31] --- acceptance/testdata/node_app/mydir/myfile.txt | 1 + build.go | 25 +++++++++++++++++++ build_test.go | 4 +-- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 acceptance/testdata/node_app/mydir/myfile.txt diff --git a/acceptance/testdata/node_app/mydir/myfile.txt b/acceptance/testdata/node_app/mydir/myfile.txt new file mode 100644 index 0000000000..f52de02641 --- /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 706c315e4c..a953d6771d 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 292e66a2e9..99d7ab9e6c 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")