Permalink
Browse files

Add step to change permissions of workspace files to current user.

  • Loading branch information...
efritz committed Jan 24, 2019
1 parent cde3633 commit f53df071d103d68ebe8638826e4e0775be184167
Showing with 56 additions and 2 deletions.
  1. +56 −2 runner/runner.go
@@ -2,10 +2,13 @@ package runner

import (
"context"
"fmt"
"os"
"os/signal"
"os/user"
"syscall"

"github.com/efritz/ij/command"
"github.com/efritz/ij/config"
"github.com/efritz/ij/logging"
"github.com/efritz/ij/paths"
@@ -24,6 +27,8 @@ type Runner struct {
env []string
}

const FlashPermissionsImage = "alpine:3.8"

var shutdownSignals = []syscall.Signal{
syscall.SIGINT,
syscall.SIGTERM,
@@ -78,7 +83,10 @@ func (r *Runner) Run(plans []string) bool {
r.logger,
)

r.logger.Info(nil, "Importing files to workspace")
r.logger.Info(
nil,
"Importing files to workspace",
)

importErr := transferer.Import(
r.config.Import.Files,
@@ -117,11 +125,27 @@ func (r *Runner) Run(plans []string) bool {
}
}

r.logger.Info(
nil,
"Flashing workspace permissions",
)

if err := r.flashPermissions(); err != nil {
r.logger.Error(
nil,
"Failed to flash workspace permissions: %s",
err.Error(),
)
}

if failure {
return false
}

r.logger.Info(nil, "Exporting files from workspace")
r.logger.Info(
nil,
"Exporting files from workspace",
)

exportErr := transferer.Export(
r.config.Export.Files,
@@ -158,3 +182,33 @@ func (r *Runner) watchSignals() {
return
}
}

func (r *Runner) flashPermissions() error {
user, err := user.Current()
if err != nil {
return err
}

builder := command.NewBuilder([]string{
"docker",
"run",
"--rm",
}, nil)

builder.AddArgs(FlashPermissionsImage)
builder.AddArgs("chown", fmt.Sprintf("%s:%s", user.Uid, user.Gid), "-R", ".")
builder.AddFlagValue("-w", "/workspace")
builder.AddFlagValue("-v", fmt.Sprintf("%s:/workspace", r.scratch.Workspace()))

args, _, err := builder.Build()
if err != nil {
return err
}

return command.NewRunner(r.logger).Run(
r.ctx,
args,
nil,
nil,
)
}

0 comments on commit f53df07

Please sign in to comment.