Skip to content

Commit

Permalink
refactor: Make install steps clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Nov 6, 2023
1 parent a002d74 commit 4fb4ad3
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 26 deletions.
36 changes: 15 additions & 21 deletions src/ai/backend/install/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
from ai.backend.plugin.entrypoint import find_build_root

from . import __version__
from .common import detect_os
from .context import Context, current_app, current_log
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 .context import DevContext, PackageContext, current_app, current_log
from .types import InstallModes

top_tasks: WeakSet[asyncio.Task] = WeakSet()
Expand All @@ -48,23 +45,18 @@ async def begin_install(self) -> None:
async def install(self) -> None:
_log: RichLog = cast(RichLog, self.query_one(".log"))
_log_token = current_log.set(_log)
ctx = DevContext()
try:
# prerequisites
await detect_os()
await install_git_lfs()
await install_git_hooks()
await check_docker()
local_execution_root_dir = await get_preferred_pants_local_exec_root()
await bootstrap_pants(local_execution_root_dir)
await ctx.check_prerequisites()
# install
await install_editable_webui()
# TODO: install agent-watcher
# TODO: install storage-agent
# TODO: install storage-watcher
ctx = Context()
await ctx.install_halfstack(ha_setup=False)
await ctx.install()
# configure
# TODO: ...
await ctx.configure()
await ctx.load_fixtures()
# post-setup
await ctx.dump_etcd_config()
except asyncio.CancelledError:
_log.write(Text.from_markup("[red]Interrupted!"))
await asyncio.sleep(1)
Expand All @@ -87,16 +79,18 @@ async def begin_install(self) -> None:

async def install(self) -> None:
log: RichLog = cast(RichLog, self.query_one(".log"))
ctx = PackageContext()
try:
# prerequisites
await detect_os()
await check_docker()
await ctx.check_prerequisites()
# install
# TODO: download packages
ctx = Context()
await ctx.install_halfstack(ha_setup=False)
await ctx.install()
# configure
# TODO: ...
await ctx.configure()
await ctx.load_fixtures()
# post-setup
await ctx.dump_etcd_config()
except asyncio.CancelledError:
log.write(Text.from_markup("[red]Interrupted!"))
await asyncio.sleep(1)
Expand Down
2 changes: 2 additions & 0 deletions src/ai/backend/install/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ async def detect_cuda() -> None:


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
Expand Down
63 changes: 58 additions & 5 deletions src/ai/backend/install/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

from textual.widgets import RichLog

from .common import check_docker_desktop_mount, 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 .types import OSInfo

if TYPE_CHECKING:
Expand Down Expand Up @@ -38,9 +41,6 @@ async def install_halfstack(self, ha_setup: bool) -> None:
async def load_fixtures(self) -> None:
pass

async def configure_services(self) -> None:
pass

async def configure_manager(self) -> None:
pass

Expand All @@ -59,8 +59,61 @@ async def configure_webui(self) -> None:
async def dump_etcd_config(self) -> None:
pass

async def populate_bundled_images(self) -> None:
async def populate_images(self) -> None:
pass


class DevContext(Context):
async def check_prerequisites(self) -> None:
await detect_os()
await install_git_lfs()
await install_git_hooks()
await check_docker()
await check_docker_desktop_mount()
local_execution_root_dir = await get_preferred_pants_local_exec_root()
await bootstrap_pants(local_execution_root_dir)

async def install(self) -> None:
await install_editable_webui()
# TODO: install agent-watcher
# TODO: install storage-agent
# TODO: install storage-watcher
# TODO: install webserver

async def configure(self) -> None:
await self.configure_manager()
await self.configure_agent()
await self.configure_storage_proxy()
await self.configure_webserver()
await self.configure_webui()

async def populate_images(self) -> None:
# TODO: docker pull
pass

async def pull_image(self) -> None:

class PackageContext(Context):
async def check_prerequisites(self) -> None:
await detect_os()
await check_docker()
await check_docker_desktop_mount()

async def install(self) -> None:
pass
# TODO: install agent-watcher
# TODO: install storage-agent
# TODO: install storage-watcher
# TODO: install webserver
# TODO: install static wsproxy

async def configure(self) -> None:
await self.configure_manager()
await self.configure_agent()
await self.configure_storage_proxy()
await self.configure_webserver()
await self.configure_webui()
# TODO: install as systemd services?

async def populate_images(self) -> None:
# TODO: docker load
pass
2 changes: 2 additions & 0 deletions src/ai/backend/install/pkg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
async def fetch_binaries() -> None:
pass
7 changes: 7 additions & 0 deletions src/ai/backend/install/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ async def request_unix(
async with aiohttp.ClientSession(connector=connector) as s:
async with s.request(method, url, **kwargs) as r:
yield r


async def wget(url: str) -> None:
chunk_size = 16384
async with request("GET", url) as r:
# TODO: implement
await r.content.read(chunk_size)

0 comments on commit 4fb4ad3

Please sign in to comment.