Skip to content

Commit 7e08968

Browse files
committed
Drop legacy working/repo dirs where possible
* `working_dir` now defaults to `image`s WORKDIR * `repos[].path` now defaults to `.` (= `working_dir`) * compatibility code removed Part-of: #3124
1 parent 5f04b6d commit 7e08968

File tree

14 files changed

+24
-122
lines changed

14 files changed

+24
-122
lines changed

runner/cmd/runner/cmd.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ func App() {
4949
Value: consts.RunnerHomeDir,
5050
Destination: &homeDir,
5151
},
52-
// TODO: Not used, left for compatibility with old servers. Remove eventually.
53-
&cli.PathFlag{
54-
Name: "working-dir",
55-
Hidden: true,
56-
Destination: nil,
57-
},
5852
&cli.IntFlag{
5953
Name: "http-port",
6054
Usage: "Set a http port",

runner/consts/consts.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ const (
2828
RunnerHomeDir = "/root"
2929
)
3030

31-
const LegacyRepoDir = "/workflow"
32-
3331
const (
3432
RunnerHTTPPort = 10999
3533
RunnerSSHPort = 10022

runner/internal/executor/executor.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,7 @@ func (ex *RunExecutor) setJobWorkingDir(ctx context.Context) error {
361361
return fmt.Errorf("get working directory: %w", err)
362362
}
363363
} else {
364-
// We still support relative paths, as 0.19.27 server uses relative paths when possible
365-
// for compatibility with pre-0.19.27 runners.
366-
// Replace consts.LegacyRepoDir with "" eventually.
367-
ex.jobWorkingDir, err = common.ExpandPath(*ex.jobSpec.WorkingDir, consts.LegacyRepoDir, ex.jobHomeDir)
364+
ex.jobWorkingDir, err = common.ExpandPath(*ex.jobSpec.WorkingDir, "", ex.jobHomeDir)
368365
if err != nil {
369366
return fmt.Errorf("expand working dir path: %w", err)
370367
}

src/dstack/_internal/cli/services/configurators/run.py

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import subprocess
44
import sys
55
import time
6-
from pathlib import Path, PurePosixPath
6+
from pathlib import Path
77
from typing import Dict, List, Optional, Set, TypeVar
88

99
import gpuhunt
@@ -33,7 +33,6 @@
3333
)
3434
from dstack._internal.core.models.common import ApplyAction, RegistryAuth
3535
from dstack._internal.core.models.configurations import (
36-
LEGACY_REPO_DIR,
3736
AnyRunConfiguration,
3837
ApplyConfigurationType,
3938
ConfigurationWithCommandsParams,
@@ -57,7 +56,6 @@
5756
get_repo_creds_and_default_branch,
5857
load_repo,
5958
)
60-
from dstack._internal.settings import FeatureFlags
6159
from dstack._internal.utils.common import local_time
6260
from dstack._internal.utils.interpolator import InterpolatorError, VariablesInterpolator
6361
from dstack._internal.utils.logging import get_logger
@@ -95,48 +93,8 @@ def apply_configuration(
9593
self.validate_gpu_vendor_and_image(conf)
9694
self.validate_cpu_arch_and_image(conf)
9795

98-
working_dir = conf.working_dir
99-
if working_dir is None:
100-
# Use the default working dir for the image for tasks and services if `commands`
101-
# is not set (emulate pre-0.19.27 JobConfigutor logic), otherwise fall back to
102-
# `/workflow`.
103-
if not FeatureFlags.LEGACY_REPO_DIR_DISABLED and (
104-
isinstance(conf, DevEnvironmentConfiguration) or conf.commands
105-
):
106-
# relative path for compatibility with pre-0.19.27 servers
107-
conf.working_dir = "."
108-
warn(
109-
f'The [code]working_dir[/code] is not set — using legacy default [code]"{LEGACY_REPO_DIR}"[/code].'
110-
" Future versions will default to the [code]image[/code]'s working directory."
111-
)
112-
elif not is_absolute_posix_path(working_dir):
113-
if FeatureFlags.LEGACY_REPO_DIR_DISABLED:
114-
raise ConfigurationError("`working_dir` must be absolute")
115-
legacy_working_dir = PurePosixPath(LEGACY_REPO_DIR) / working_dir
116-
warn(
117-
"[code]working_dir[/code] is relative."
118-
f" Using legacy working directory [code]{legacy_working_dir}[/code]\n\n"
119-
"Future versions will require absolute path\n"
120-
f"To keep using legacy working directory, set"
121-
f" [code]working_dir[/code] to [code]{legacy_working_dir}[/code]\n"
122-
)
123-
else:
124-
# relative path for compatibility with pre-0.19.27 servers
125-
try:
126-
conf.working_dir = str(PurePosixPath(working_dir).relative_to(LEGACY_REPO_DIR))
127-
except ValueError:
128-
pass
129-
130-
if conf.repos and conf.repos[0].path is None:
131-
if FeatureFlags.LEGACY_REPO_DIR_DISABLED:
132-
raise ConfigurationError("`repos[0].path` is not set")
133-
warn(
134-
"[code]repos[0].path[/code] is not set,"
135-
f" using legacy repo path [code]{LEGACY_REPO_DIR}[/code]\n\n"
136-
"In a future version the default value will be changed."
137-
f" To keep using [code]{LEGACY_REPO_DIR}[/code], explicitly set"
138-
f" [code]repos[0].path[/code] to [code]{LEGACY_REPO_DIR}[/code]\n"
139-
)
96+
if conf.working_dir is not None and not is_absolute_posix_path(conf.working_dir):
97+
raise ConfigurationError("working_dir must be absolute")
14098

14199
config_manager = ConfigManager()
142100
repo = self.get_repo(conf, configuration_path, configurator_args, config_manager)

src/dstack/_internal/core/backends/base/compute.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
)
2727
from dstack._internal.core.models.backends.base import BackendType
2828
from dstack._internal.core.models.compute_groups import ComputeGroup, ComputeGroupProvisioningData
29-
from dstack._internal.core.models.configurations import LEGACY_REPO_DIR
3029
from dstack._internal.core.models.gateways import (
3130
GatewayComputeConfiguration,
3231
GatewayProvisioningData,
@@ -971,8 +970,6 @@ def get_docker_commands(
971970
f" --ssh-port {DSTACK_RUNNER_SSH_PORT}"
972971
" --temp-dir /tmp/runner"
973972
" --home-dir /root"
974-
# TODO: Not used, left for compatibility with old runners. Remove eventually.
975-
f" --working-dir {LEGACY_REPO_DIR}"
976973
),
977974
]
978975

src/dstack/_internal/core/models/configurations.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ class RepoSpec(CoreModel):
131131
Field(description="The commit hash"),
132132
] = None
133133
path: Annotated[
134-
Optional[str],
134+
str,
135135
Field(
136136
description=(
137137
"The repo path inside the run container. Relative paths are resolved"
138-
f" relative to the working directory. Defaults to `{LEGACY_REPO_DIR}`"
138+
" relative to the working directory"
139139
)
140140
),
141-
] = None
141+
] = "."
142142
if_exists: Annotated[
143143
RepoExistsAction,
144144
Field(
@@ -447,8 +447,8 @@ class BaseRunConfiguration(CoreModel):
447447
Field(
448448
description=(
449449
"The absolute path to the working directory inside the container."
450-
f" Defaults to `{LEGACY_REPO_DIR}`"
451-
)
450+
" Defaults to the `image`'s default working directory"
451+
),
452452
),
453453
] = None
454454
# deprecated since 0.18.31; has no effect

src/dstack/_internal/core/models/runs.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ class JobSpec(CoreModel):
269269
retry: Optional[Retry]
270270
volumes: Optional[List[MountPoint]] = None
271271
ssh_key: Optional[JobSSHKey] = None
272-
# `working_dir` is always absolute (if not None) since 0.19.27
273272
working_dir: Optional[str]
274273
# `repo_data` is optional for client compatibility with pre-0.19.17 servers and for compatibility
275274
# with jobs submitted before 0.19.17. All new jobs are expected to have non-None `repo_data`.
@@ -405,7 +404,7 @@ def schema_extra(schema: Dict[str, Any]):
405404

406405

407406
class RunSpec(generate_dual_core_model(RunSpecConfig)):
408-
# TODO: run_name, working_dir are redundant here since they already passed in configuration
407+
# TODO: run_name is redundant here since they already passed in configuration
409408
run_name: Annotated[
410409
Optional[str],
411410
Field(description="The run name. If not set, the run name is generated automatically."),
@@ -436,25 +435,14 @@ class RunSpec(generate_dual_core_model(RunSpecConfig)):
436435
Field(
437436
description=(
438437
"The repo path inside the container. Relative paths are resolved"
439-
f" relative to the working directory. Defaults to `{LEGACY_REPO_DIR}`."
438+
" relative to the working directory."
440439
)
441440
),
442441
] = None
443442
file_archives: Annotated[
444443
list[FileArchiveMapping],
445444
Field(description="The list of file archive ID to container path mappings."),
446445
] = []
447-
# Server uses configuration.working_dir instead of this field since 0.19.27, but
448-
# the field still exists for compatibility with older servers
449-
working_dir: Annotated[
450-
Optional[str],
451-
Field(
452-
description=(
453-
"The absolute path to the working directory inside the container."
454-
" Defaults to the default working directory from the `image`."
455-
)
456-
),
457-
] = None
458446
configuration_path: Annotated[
459447
Optional[str],
460448
Field(

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,12 @@ def _repo_dir(self) -> str:
314314
"""
315315
Returns absolute or relative path
316316
"""
317+
if repos := self.run_spec.configuration.repos:
318+
return repos[0].path
319+
# `repo_dir` may be set while `repos` is empty if the RunSpec was submitted before 0.20.0
317320
repo_dir = self.run_spec.repo_dir
318321
# We need this fallback indefinitely, as there may be RunSpecs submitted before
319-
# repos[].path became required, and JobSpec is regenerated from RunSpec on each retry
322+
# `repos[].path` was added, and JobSpec is regenerated from RunSpec on each retry
320323
# and in-place update.
321324
if repo_dir is None:
322325
return LEGACY_REPO_DIR
@@ -335,23 +338,15 @@ def _repo_exists_action(self) -> Optional[RepoExistsAction]:
335338

336339
def _working_dir(self) -> Optional[str]:
337340
"""
338-
Returns path or None
341+
Returns absolute path or None
339342
340343
None means the default working directory taken from the image
341-
342-
Currently, for compatibility with pre-0.19.27 runners, the path may be relative.
343-
Future versions should return only absolute paths
344344
"""
345345
working_dir = self.run_spec.configuration.working_dir
346-
if working_dir is None:
346+
if working_dir is None or is_absolute_posix_path(working_dir):
347347
return working_dir
348-
# Return a relative path if possible
349-
if is_absolute_posix_path(working_dir):
350-
try:
351-
return str(PurePosixPath(working_dir).relative_to(LEGACY_REPO_DIR))
352-
except ValueError:
353-
pass
354-
return working_dir
348+
# Support for pre-0.20.0 configurations
349+
return str(PurePosixPath(LEGACY_REPO_DIR) / working_dir)
355350

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

src/dstack/_internal/server/services/runs/spec.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from dstack._internal.server.models import UserModel
1010
from dstack._internal.server.services.docker import is_valid_docker_volume_target
1111
from dstack._internal.server.services.resources import set_resources_defaults
12-
from dstack._internal.settings import FeatureFlags
1312
from dstack._internal.utils.logging import get_logger
1413

1514
logger = get_logger(__name__)
@@ -114,13 +113,6 @@ def validate_run_spec_and_set_defaults(
114113
raise ServerClientError("ssh_key_pub must be set if the user has no ssh_public_key")
115114
if run_spec.configuration.working_dir is None and legacy_repo_dir:
116115
run_spec.configuration.working_dir = LEGACY_REPO_DIR
117-
if (
118-
run_spec.configuration.repos
119-
and run_spec.repo_dir is None
120-
and FeatureFlags.LEGACY_REPO_DIR_DISABLED
121-
and not legacy_repo_dir
122-
):
123-
raise ServerClientError("Repo path is not set")
124116

125117

126118
def check_can_update_run_spec(current_run_spec: RunSpec, new_run_spec: RunSpec):

src/dstack/_internal/server/testing/common.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ def get_run_spec(
285285
repo_id=repo_id,
286286
repo_data=LocalRunRepoData(repo_dir="/"),
287287
repo_code_hash=None,
288-
working_dir=None,
289288
configuration_path=configuration_path,
290289
configuration=configuration or DevEnvironmentConfiguration(ide="vscode"),
291290
profile=profile,

0 commit comments

Comments
 (0)