Move actions path outside of workdir (#701)

* feat: add option to specify user for exec

* fix: move actions to static path outside workdir

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Ryan (hackercat)
2021-05-24 17:09:03 +00:00
committed by GitHub
parent 490039975f
commit d794e2fe4c
4 changed files with 19 additions and 17 deletions

View File

@@ -68,7 +68,7 @@ type Container interface {
CopyDir(destPath string, srcPath string, useGitIgnore bool) common.Executor
Pull(forcePull bool) common.Executor
Start(attach bool) common.Executor
Exec(command []string, env map[string]string) common.Executor
Exec(command []string, env map[string]string, user string) common.Executor
UpdateFromEnv(srcPath string, env *map[string]string) common.Executor
UpdateFromPath(env *map[string]string) common.Executor
Remove() common.Executor
@@ -145,9 +145,7 @@ func (cr *containerReference) Copy(destPath string, files ...*FileEntry) common.
func (cr *containerReference) CopyDir(destPath string, srcPath string, useGitIgnore bool) common.Executor {
return common.NewPipelineExecutor(
common.NewInfoExecutor("%sdocker cp src=%s dst=%s", logPrefix, srcPath, destPath),
cr.connect(),
cr.find(),
cr.exec([]string{"mkdir", "-p", destPath}, nil),
cr.Exec([]string{"mkdir", "-p", destPath}, nil, ""),
cr.copyDir(destPath, srcPath, useGitIgnore),
).IfNot(common.Dryrun)
}
@@ -160,11 +158,12 @@ func (cr *containerReference) UpdateFromPath(env *map[string]string) common.Exec
return cr.extractPath(env).IfNot(common.Dryrun)
}
func (cr *containerReference) Exec(command []string, env map[string]string) common.Executor {
func (cr *containerReference) Exec(command []string, env map[string]string, user string) common.Executor {
return common.NewPipelineExecutor(
common.NewInfoExecutor("%sdocker exec cmd=[%s] user=%s", logPrefix, strings.Join(command, " "), user),
cr.connect(),
cr.find(),
cr.exec(command, env),
cr.exec(command, env, user),
).IfNot(common.Dryrun)
}
@@ -407,7 +406,7 @@ func (cr *containerReference) extractPath(env *map[string]string) common.Executo
}
}
func (cr *containerReference) exec(cmd []string, env map[string]string) common.Executor {
func (cr *containerReference) exec(cmd []string, env map[string]string, user string) common.Executor {
return func(ctx context.Context) error {
logger := common.Logger(ctx)
// Fix slashes when running on Windows
@@ -427,6 +426,7 @@ func (cr *containerReference) exec(cmd []string, env map[string]string) common.E
}
idResp, err := cr.cli.ContainerExecCreate(ctx, cr.id, types.ExecConfig{
User: user,
Cmd: cmd,
WorkingDir: cr.input.WorkingDir,
Env: envList,