Skip to content

Commit 7b71f53

Browse files
authored
Fix server compatibility with pre-0.19.27 runners (#3054)
Closes: #3048
1 parent 3507180 commit 7b71f53

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

runner/consts/consts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ const (
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"
29-
// A repo directory and a default working directory for the job
30-
RunnerWorkingDir = "/workflow"
3129
)
3230

31+
const LegacyRepoDir = "/workflow"
32+
3333
const (
3434
RunnerHTTPPort = 10999
3535
RunnerSSHPort = 10022

runner/internal/executor/executor.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,10 @@ func (ex *RunExecutor) prepareJobWorkingDir(ctx context.Context) error {
360360
return gerrors.Wrap(err)
361361
}
362362
} else {
363-
ex.jobWorkingDir, err = common.ExpandPath(*ex.jobSpec.WorkingDir, "", ex.jobHomeDir)
363+
// We still support relative paths, as 0.19.27 server uses relative paths when possible
364+
// for compatibility with pre-0.19.27 runners.
365+
// Replace consts.LegacyRepoDir with "" eventually.
366+
ex.jobWorkingDir, err = common.ExpandPath(*ex.jobSpec.WorkingDir, consts.LegacyRepoDir, ex.jobHomeDir)
364367
if err != nil {
365368
return gerrors.Wrap(err)
366369
}

src/dstack/_internal/server/services/jobs/configurators/base.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,23 @@ def _repo_dir(self) -> str:
318318

319319
def _working_dir(self) -> Optional[str]:
320320
"""
321-
Returns absolute path or None
321+
Returns path or None
322+
322323
None means the default working directory taken from the image
324+
325+
Currently, for compatibility with pre-0.19.27 runners, the path may be relative.
326+
Future versions should return only absolute paths
323327
"""
324328
working_dir = self.run_spec.configuration.working_dir
325-
if working_dir is None or is_absolute_posix_path(working_dir):
329+
if working_dir is None:
326330
return working_dir
327-
# Legacy configuration; relative working_dir is deprecated
328-
return str(PurePosixPath(LEGACY_REPO_DIR) / working_dir)
331+
# Return a relative path if possible
332+
if is_absolute_posix_path(working_dir):
333+
try:
334+
return str(PurePosixPath(working_dir).relative_to(LEGACY_REPO_DIR))
335+
except ValueError:
336+
pass
337+
return working_dir
329338

330339
def _python(self) -> str:
331340
if self.run_spec.configuration.python is not None:

0 commit comments

Comments
 (0)