Skip to content
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()
.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