Skip to content

Commit

Permalink
machine: support instance size & startup script config (iterative#6537)
Browse files Browse the repository at this point in the history
* machine: install dvc via startup_script by default

* machine: support configuring instance type and startup script

* accept startup_script as a config relpath

* use pushd/popd in default install script
  • Loading branch information
pmrowla authored Sep 7, 2021
1 parent cbd4936 commit f7a82f6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def _map_dirs(conf, func):
"key_path": func,
}
},
"machine": {str: {"startup_script": func}},
}
return Schema(dirs_schema, extra=ALLOW_EXTRA)(conf)

Expand Down
2 changes: 2 additions & 0 deletions dvc/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ class RelPath(str):
"machine": {
str: {
"cloud": All(Lower, Choices("aws", "azure")),
"instance_type": Lower,
"startup_script": str,
},
},
# section for experimental features
Expand Down
18 changes: 18 additions & 0 deletions dvc/machine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@

RESERVED_NAMES = {"local", "localhost"}

DEFAULT_STARTUP_SCRIPT = """#!/bin/bash
sudo apt-get update
sudo apt-get install --yes python3 python3-pip
python3 -m pip install --upgrade pip
pushd /etc/apt/sources.list.d
sudo wget https://dvc.org/deb/dvc.list
sudo apt-get update
sudo apt-get install --yes dvc
popd
"""


def validate_name(name: str):
from dvc.exceptions import InvalidArgumentError
Expand Down Expand Up @@ -168,6 +180,12 @@ def _get_backend(self, cloud: str) -> "BaseMachineBackend":
def create(self, name: Optional[str]):
"""Create and start the specified machine instance."""
config, backend = self.get_config_and_backend(name)
if "startup_script" in config:
with open(config["startup_script"]) as fobj:
startup_script = fobj.read()
else:
startup_script = DEFAULT_STARTUP_SCRIPT
config["startup_script"] = startup_script
return backend.create(**config)

def destroy(self, name: Optional[str]):
Expand Down

0 comments on commit f7a82f6

Please sign in to comment.