Skip to content

Commit cb7d1fd

Browse files
authored
Download runner to a tmp file (#235)
1 parent 22bab0c commit cb7d1fd

File tree

1 file changed

+6
-36
lines changed

1 file changed

+6
-36
lines changed

cli/dstack/backend/local/runners.py

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,10 @@
1414
from tqdm import tqdm
1515

1616
from dstack import version
17-
from dstack.core.job import Job, JobStatus, Requirements
17+
from dstack.core.job import Job
1818
from dstack.core.request import RequestHead, RequestStatus
1919
from dstack.core.runners import Gpu, Resources, Runner
2020

21-
CREATE_INSTANCE_RETRY_RATE_SECS = 3
22-
23-
24-
def _matches(resources: Resources, requirements: Optional[Requirements]) -> bool:
25-
if not requirements:
26-
return True
27-
if requirements.cpus and requirements.cpus > resources.cpus:
28-
return False
29-
if requirements.memory_mib and requirements.memory_mib > resources.memory_mib:
30-
return False
31-
if requirements.gpus:
32-
gpu_count = requirements.gpus.count or 1
33-
if gpu_count > len(resources.gpus or []):
34-
return False
35-
if requirements.gpus.name and gpu_count > len(
36-
list(filter(lambda gpu: gpu.name == requirements.gpus.name, resources.gpus or []))
37-
):
38-
return False
39-
if requirements.gpus.memory_mib and gpu_count > len(
40-
list(
41-
filter(
42-
lambda gpu: gpu.memory_mib >= requirements.gpus.memory_mib,
43-
resources.gpus or [],
44-
)
45-
)
46-
):
47-
return False
48-
if requirements.interruptible and not resources.interruptible:
49-
return False
50-
return True
51-
5221

5322
def start_runner_process(runner_id: str) -> str:
5423
_install_runner_if_necessary()
@@ -114,14 +83,15 @@ def _install_runner_if_necessary():
11483
_download_runner(_runner_url(), runner_path)
11584

11685

117-
def _download_runner(url: str, path: str):
86+
def _download_runner(url: str, path: Path):
87+
runner_download_path = path.parent / "runner-download"
11888
with requests.get(url, stream=True) as r:
11989
total_length = int(r.headers.get("Content-Length"))
120-
12190
with tqdm.wrapattr(r.raw, "read", total=total_length, desc=f"Downloading runner") as raw:
122-
with open(path, "wb") as output:
91+
with open(runner_download_path, "wb") as output:
12392
shutil.copyfileobj(raw, output)
124-
os.chmod(path, 0o755)
93+
shutil.move(runner_download_path, path)
94+
os.chmod(path, 0o755)
12595

12696

12797
def _runner_url() -> str:

0 commit comments

Comments
 (0)