Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal(ir): state based implementation #972

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions docs/proposals/20221007-ir-state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Refactor the IR to use state

Author:
- [kemingy](https://github.com/kemingy/)


## Summary

This proposal is designed to refactor the IR, as we discussed in [envd/#91](https://github.com/tensorchord/envd/issues/91#issuecomment-1239405359).

## Motivation

* Currently, we build the image with hard-coded order and parallelism. It's not flexible enough for some use cases.
* The design of buildkit LLB state is suitable for method chaining implementation. Users can define the dependencies and parallelism easily.

## Goals

* Able to define the order and parallelism.
* Provide low level APIs to build the image from scratch.

## API

```python
def conda_env(root, version="3.10"):
conda = root.env("MAMBA_ROOT_PREFIX", "/opt/conda").run(
[
"curl micro.mamba.pm/install.sh | sh -s -- -y",
"/opt/conda/bin/micromamba create -n envd python={}".format(version),
]
)
return conda


def install_shell(root, sh="bash"):
if sh == "bash":
return root


def install_vscode_ext(ext=()):
root = Source.merge(Source.http("openvsx/{}".format(x), filename=x) for x in ext)
return root


def install_key():
root = (
Source.scratch()
kemingy marked this conversation as resolved.
Show resolved Hide resolved
.mkdir("/var/envd", permission=755)
.file("/var/envd/authorized_keys", data="xxx envd", permission=644)
)
return root


def parallel_build(root):
"""demo for parallel + diff + merge"""
# use `root.state()` to create a copy explicitly
conda = conda_env(install_shell(root.state()))
vscode = install_vscode_ext()
key = config_key()
return Source.merge([root, key, vscode, Diff(root, conda)])


def build():
root = (
Source.image("ubuntu:22.04")
.apt_packages(
["curl", "wget"], update=True, clean=True, without_recommends=True
)
.run(["curl https://starship.rs/install.sh | sh -s -- -y"], mount=None)
.copy(
Source.image("tensorchord/envd-sshd-from-scratch:latest"),
source_path="/usr/bin/envd-sshd",
dest_path="/var/envd/bin/envd-sshd",
)
)
return parallel_build(root)
```

## Risk

* Implementation in Starlark
* VSCode language server