From 844c54722dd389cb17acc64c3e3498fa6bf1fe0e Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Tue, 15 Aug 2023 11:17:02 +0100 Subject: [PATCH 1/2] commands: Allow working directory to be set when not running in chroot Currently Command.Dir is unsed; hook it up such that when commands are not running in a chroot, the working directory can be set. Signed-off-by: Christopher Obbard --- commands.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/commands.go b/commands.go index 201c62aa..502cbb39 100644 --- a/commands.go +++ b/commands.go @@ -254,6 +254,11 @@ func (cmd Command) Run(label string, cmdline ...string) error { exe.Env = append(os.Environ(), cmd.extraEnv...) } + // Allow working directory to be set for commands not running in chroot + if len(cmd.Dir) > 0 && cmd.ChrootMethod == CHROOT_METHOD_NONE { + exe.Dir = cmd.Dir + } + // Disable services start/stop for commands running in chroot if cmd.ChrootMethod != CHROOT_METHOD_NONE { services := ServiceHelper{cmd.Chroot} From c43257e6f9301d52959de0ecfc33720ec5f1d5e6 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Tue, 15 Aug 2023 11:18:02 +0100 Subject: [PATCH 2/2] actions: run: Set postprocess working directory to artifact directory Currently any run action tagged as postprocess will be ran in the recipe directory. The artifacts are stored in this directory by default, unless --artifactdir is passed to Debos to change where the artifacts are stored. The run action documentation states: postprocess -- if set script or command is executed after all other commands and has access to the recipe directory ($RECIPEDIR) and the artifact directory ($ARTIFACTDIR). The working directory will be set to the artifact directory. But this is wrong; currently the working directory of postprocess commands is set to the recipe directory. Set the working directory to the artifact directory instead to allow postprocess commands to be ran in the correct location. Fixes: #345 Signed-off-by: Christopher Obbard --- actions/run_action.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/actions/run_action.go b/actions/run_action.go index c62a028a..1e2ea99b 100644 --- a/actions/run_action.go +++ b/actions/run_action.go @@ -159,6 +159,11 @@ func (run *RunAction) doRun(context debos.DebosContext) error { } } + /* For PostProcess commands, set cwd to artifactdir */ + if run.PostProcess { + cmd.Dir = context.Artifactdir + } + return cmd.Run(label, cmdline...) }