Skip to content

Commit

Permalink
chown app directory after upload
Browse files Browse the repository at this point in the history
Due to setting the uid,gid on upload this was fixed for files, but NOT
directories. We now force a "chown" after the upload

[#31]
  • Loading branch information
dgodd committed Sep 24, 2018
1 parent ed0932a commit ed52e8b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions acceptance/testdata/node_app/mydir/myfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file in subdir
25 changes: 25 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit ed52e8b

Please sign in to comment.