diff --git a/runner/consts/consts.go b/runner/consts/consts.go index d57faed6c..aa7262ba1 100644 --- a/runner/consts/consts.go +++ b/runner/consts/consts.go @@ -26,10 +26,10 @@ const ( // The current user's homedir (as of 2024-12-28, it's always root) should be used // instead of the hardcoded value RunnerHomeDir = "/root" - // A repo directory and a default working directory for the job - RunnerWorkingDir = "/workflow" ) +const LegacyRepoDir = "/workflow" + const ( RunnerHTTPPort = 10999 RunnerSSHPort = 10022 diff --git a/runner/internal/executor/executor.go b/runner/internal/executor/executor.go index 39999156c..e801b3341 100644 --- a/runner/internal/executor/executor.go +++ b/runner/internal/executor/executor.go @@ -360,7 +360,10 @@ func (ex *RunExecutor) setJobWorkingDir(ctx context.Context) error { return gerrors.Wrap(err) } } else { - ex.jobWorkingDir, err = common.ExpandPath(*ex.jobSpec.WorkingDir, "", ex.jobHomeDir) + // We still support relative paths, as 0.19.27 server uses relative paths when possible + // for compatibility with pre-0.19.27 runners. + // Replace consts.LegacyRepoDir with "" eventually. + ex.jobWorkingDir, err = common.ExpandPath(*ex.jobSpec.WorkingDir, consts.LegacyRepoDir, ex.jobHomeDir) if err != nil { return gerrors.Wrap(err) } diff --git a/src/dstack/_internal/server/services/jobs/configurators/base.py b/src/dstack/_internal/server/services/jobs/configurators/base.py index 7eb469865..e10a3486d 100644 --- a/src/dstack/_internal/server/services/jobs/configurators/base.py +++ b/src/dstack/_internal/server/services/jobs/configurators/base.py @@ -310,14 +310,23 @@ def _repo_dir(self) -> str: def _working_dir(self) -> Optional[str]: """ - Returns absolute path or None + Returns path or None + None means the default working directory taken from the image + + Currently, for compatibility with pre-0.19.27 runners, the path may be relative. + Future versions should return only absolute paths """ working_dir = self.run_spec.configuration.working_dir - if working_dir is None or is_absolute_posix_path(working_dir): + if working_dir is None: return working_dir - # Legacy configuration; relative working_dir is deprecated - return str(PurePosixPath(LEGACY_REPO_DIR) / working_dir) + # Return a relative path if possible + if is_absolute_posix_path(working_dir): + try: + return str(PurePosixPath(working_dir).relative_to(LEGACY_REPO_DIR)) + except ValueError: + pass + return working_dir def _python(self) -> str: if self.run_spec.configuration.python is not None: