Skip to content

Commit

Permalink
refactor: a little bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Nov 6, 2023
1 parent 4fb4ad3 commit e33c994
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 38 deletions.
35 changes: 5 additions & 30 deletions src/ai/backend/install/common.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from .context import current_os
from .types import OSInfo
from .types import OSInfo, Platform


async def detect_os():
async def detect_os() -> OSInfo:
"""
# Detect distribution
KNOWN_DISTRO="(Debian|Ubuntu|RedHat|CentOS|openSUSE|Amazon|Arista|SUSE)"
Expand All @@ -29,35 +28,11 @@ async def detect_os():
exit 1
fi
"""
current_os.set(
OSInfo(
platform="",
distro="",
)
return OSInfo(
platform=Platform.LINUX_ARM64,
distro="",
)


async def detect_cuda() -> None:
pass


async def check_docker_desktop_mount() -> None:
if current_os.get().distro != "Darwin":
return
"""
echo "validating Docker Desktop mount permissions..."
docker pull alpine:3.8 > /dev/null
docker run --rm -v "$HOME/.pyenv:/root/vol" alpine:3.8 ls /root/vol > /dev/null 2>&1
if [ $? -ne 0 ]; then
# backend.ai-krunner-DISTRO pkgs are installed in pyenv's virtualenv,
# so ~/.pyenv must be mountable.
show_error "You must allow mount of '$HOME/.pyenv' in the File Sharing preference of the Docker Desktop app."
exit 1
fi
docker run --rm -v "$ROOT_PATH:/root/vol" alpine:3.8 ls /root/vol > /dev/null 2>&1
if [ $? -ne 0 ]; then
show_error "You must allow mount of '$ROOT_PATH' in the File Sharing preference of the Docker Desktop app."
exit 1
fi
echo "${REWRITELN}validating Docker Desktop mount permissions: ok"
"""
17 changes: 10 additions & 7 deletions src/ai/backend/install/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@

from textual.widgets import RichLog

from .common import check_docker_desktop_mount, detect_os
from .common import detect_os
from .dev import bootstrap_pants, install_editable_webui, install_git_hooks, install_git_lfs
from .docker import check_docker, get_preferred_pants_local_exec_root
from .docker import check_docker, check_docker_desktop_mount, get_preferred_pants_local_exec_root
from .types import OSInfo

if TYPE_CHECKING:
from .cli import InstallerApp

current_log: ContextVar[RichLog] = ContextVar("current_log")
current_app: ContextVar[InstallerApp] = ContextVar("current_app")
current_os: ContextVar[OSInfo] = ContextVar("current_os")


class PostGuide(enum.Enum):
UPDATE_ETC_HOSTS = 10


class Context:
os_info: OSInfo

_post_guides: list[PostGuide]

def __init__(self) -> None:
Expand Down Expand Up @@ -65,11 +66,12 @@ async def populate_images(self) -> None:

class DevContext(Context):
async def check_prerequisites(self) -> None:
await detect_os()
self.os_info = await detect_os()
await install_git_lfs()
await install_git_hooks()
await check_docker()
await check_docker_desktop_mount()
if self.os_info.distro == "Darwin":
await check_docker_desktop_mount()
local_execution_root_dir = await get_preferred_pants_local_exec_root()
await bootstrap_pants(local_execution_root_dir)

Expand All @@ -94,9 +96,10 @@ async def populate_images(self) -> None:

class PackageContext(Context):
async def check_prerequisites(self) -> None:
await detect_os()
self.os_info = await detect_os()
await check_docker()
await check_docker_desktop_mount()
if self.os_info.distro == "Darwin":
await check_docker_desktop_mount()

async def install(self) -> None:
pass
Expand Down
20 changes: 20 additions & 0 deletions src/ai/backend/install/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,23 @@ async def check_docker() -> None:
log.write(f"Detected docker-compose installation ({compose_version})")
if parse_version(compose_version) < (2, 0, 0):
fail_with_compose_install_request()


async def check_docker_desktop_mount() -> None:
"""
echo "validating Docker Desktop mount permissions..."
docker pull alpine:3.8 > /dev/null
docker run --rm -v "$HOME/.pyenv:/root/vol" alpine:3.8 ls /root/vol > /dev/null 2>&1
if [ $? -ne 0 ]; then
# backend.ai-krunner-DISTRO pkgs are installed in pyenv's virtualenv,
# so ~/.pyenv must be mountable.
show_error "You must allow mount of '$HOME/.pyenv' in the File Sharing preference of the Docker Desktop app."
exit 1
fi
docker run --rm -v "$ROOT_PATH:/root/vol" alpine:3.8 ls /root/vol > /dev/null 2>&1
if [ $? -ne 0 ]; then
show_error "You must allow mount of '$ROOT_PATH' in the File Sharing preference of the Docker Desktop app."
exit 1
fi
echo "${REWRITELN}validating Docker Desktop mount permissions: ok"
"""
9 changes: 8 additions & 1 deletion src/ai/backend/install/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ class InstallModes(enum.StrEnum):
PACKAGE = "PACKAGE"


class Platform(enum.StrEnum):
LINUX_ARM64 = "linux-aarch64"
LINUX_X86_64 = "linux-x86_64"
MACOS_ARM64 = "macos-arm64"
MACOS_X86_64 = "macos-x86_64"


@dataclasses.dataclass()
class OSInfo:
platform: str
platform: Platform
distro: str


Expand Down

0 comments on commit e33c994

Please sign in to comment.