Skip to content

Commit af7887e

Browse files
authored
Fix default working dir in containers (#2449)
The default working dir is supposed to be `/workflow`. However, `dstack-runner` never actually defaulted to `/workflow` and didn't set any working dir if `job_spec.working_dir` is `null`. This issue only wasn't visible prior to 0.19.0 because older CLI versions used to rewrite the working dir from `null` to `.` in the now-deprecated `RunCollection.get_plan` method.
1 parent be6fef5 commit af7887e

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

runner/consts/consts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
// NOTE: RunnerRuntimeDir would be a more appropriate name, but it's called tempDir
2323
// throughout runner's codebase
2424
RunnerTempDir = "/tmp/runner"
25-
// Currently, it's a directory where autorized_keys, git credentials, etc. are placed
25+
// Currently, it's a directory where authorized_keys, git credentials, etc. are placed
2626
// The current user's homedir (as of 2024-12-28, it's always root) should be used
2727
// instead of the hardcoded value
2828
RunnerHomeDir = "/root"

runner/internal/executor/executor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func (ex *RunExecutor) execJob(ctx context.Context, jobLogFile io.Writer) error
261261
}
262262
cmd.WaitDelay = ex.killDelay // kills the process if it doesn't exit in time
263263

264+
cmd.Dir = ex.workingDir
264265
if ex.jobSpec.WorkingDir != nil {
265266
workingDir, err := joinRelPath(ex.workingDir, *ex.jobSpec.WorkingDir)
266267
if err != nil {

runner/internal/executor/executor_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,22 @@ import (
1818

1919
// todo test get history
2020

21-
func TestExecutor_WorkingDir(t *testing.T) {
21+
func TestExecutor_WorkingDir_Current(t *testing.T) {
2222
var b bytes.Buffer
2323
ex := makeTestExecutor(t)
24+
workingDir := "."
25+
ex.jobSpec.WorkingDir = &workingDir
26+
ex.jobSpec.Commands = append(ex.jobSpec.Commands, "pwd")
27+
28+
err := ex.execJob(context.TODO(), io.Writer(&b))
29+
assert.NoError(t, err)
30+
assert.Equal(t, ex.workingDir+"\r\n", b.String())
31+
}
32+
33+
func TestExecutor_WorkingDir_Nil(t *testing.T) {
34+
var b bytes.Buffer
35+
ex := makeTestExecutor(t)
36+
ex.jobSpec.WorkingDir = nil
2437
ex.jobSpec.Commands = append(ex.jobSpec.Commands, "pwd")
2538

2639
err := ex.execJob(context.TODO(), io.Writer(&b))

runner/internal/runner/api/server.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ import (
1616
)
1717

1818
type Server struct {
19-
srv *http.Server
20-
tempDir string
21-
workingDir string
19+
srv *http.Server
20+
tempDir string
2221

2322
shutdownCh chan interface{} // server closes this chan on shutdown
2423
jobBarrierCh chan interface{} // only server listens on this chan
@@ -45,8 +44,7 @@ func NewServer(tempDir string, homeDir string, workingDir string, address string
4544
Addr: address,
4645
Handler: r,
4746
},
48-
tempDir: tempDir,
49-
workingDir: workingDir,
47+
tempDir: tempDir,
5048

5149
shutdownCh: make(chan interface{}),
5250
jobBarrierCh: make(chan interface{}),

0 commit comments

Comments
 (0)