Skip to content

Commit

Permalink
feat: add config.repo in envd (#1101)
Browse files Browse the repository at this point in the history
* add

Signed-off-by: Jinjing.Zhou <allenzhou@tensorchord.ai>

* fix lint

Signed-off-by: Jinjing.Zhou <allenzhou@tensorchord.ai>

* fix

Signed-off-by: Jinjing.Zhou <allenzhou@tensorchord.ai>

Signed-off-by: Jinjing.Zhou <allenzhou@tensorchord.ai>
  • Loading branch information
VoVAllen committed Oct 27, 2022
1 parent 4429bae commit 356a707
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions envd/api/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,12 @@ def rstudio_server():
"""
Enable the RStudio Server (only work for `base(os="ubuntu20.04", language="r")`)
"""


def repo(url: str, description: str):
"""Setup repo related information. Will save to the image labels.
Args:
url (str): repo URL
description (str): repo description
"""
14 changes: 14 additions & 0 deletions pkg/lang/frontend/starlark/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var Module = &starlarkstruct.Module{
ruleJuliaPackageServer, ruleFuncJuliaPackageServer),
"rstudio_server": starlark.NewBuiltin(ruleRStudioServer, ruleFuncRStudioServer),
"entrypoint": starlark.NewBuiltin(ruleEntrypoint, ruleFuncEntrypoint),
"repo": starlark.NewBuiltin(ruleRepo, ruleFuncRepo),
},
}

Expand Down Expand Up @@ -212,3 +213,16 @@ func ruleFuncEntrypoint(thread *starlark.Thread, _ *starlark.Builtin,
ir.Entrypoint(argList)
return starlark.None, nil
}

func ruleFuncRepo(thread *starlark.Thread, _ *starlark.Builtin,
args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var url, description string

if err := starlark.UnpackArgs(ruleRepo, args, kwargs, "url", &url, "description?", &description); err != nil {
return nil, err
}

logger.Debugf("repo info: url=%s, description=%s", url, description)
ir.Repo(url, description)
return starlark.None, nil
}
1 change: 1 addition & 0 deletions pkg/lang/frontend/starlark/config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ const (
ruleJuliaPackageServer = "config.julia_pkg_server"
ruleRStudioServer = "config.rstudio_server"
ruleEntrypoint = "config.entrypoint"
ruleRepo = "config.repo"
)
6 changes: 6 additions & 0 deletions pkg/lang/ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ func (g Graph) Labels() (map[string]string, error) {
}
labels[types.ImageLabelPorts] = string(portsData)

repoInfo, err := json.Marshal(g.Repo)
if err != nil {
return labels, err
}
labels[types.ImageLabelRepo] = string(repoInfo)

return labels, nil
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/lang/ir/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/opencontainers/go-digest"

"github.com/tensorchord/envd/pkg/editor/vscode"
"github.com/tensorchord/envd/pkg/types"
)

func Base(os, language, image string) error {
Expand Down Expand Up @@ -229,3 +230,10 @@ func RuntimeEnviron(env map[string]string) {
func RuntimeInitScript(commands []string) {
DefaultGraph.RuntimeInitScript = append(DefaultGraph.RuntimeInitScript, commands)
}

func Repo(url, description string) {
DefaultGraph.Repo = types.RepoInfo{
Description: description,
URL: url,
}
}
3 changes: 3 additions & 0 deletions pkg/lang/ir/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/tensorchord/envd/pkg/editor/vscode"
"github.com/tensorchord/envd/pkg/progress/compileui"
"github.com/tensorchord/envd/pkg/types"
)

// A Graph contains the state,
Expand Down Expand Up @@ -61,6 +62,8 @@ type Graph struct {
HTTP []HTTPInfo
Entrypoint []string

Repo types.RepoInfo

*JupyterConfig
*GitConfig
*CondaConfig
Expand Down
5 changes: 5 additions & 0 deletions pkg/types/envd.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ type Dependency struct {
PyPIPackages []string `json:"pypi_packages,omitempty"`
}

type RepoInfo struct {
URL string `json:"url,omitempty"`
Description string `json:"description,omitempty"`
}

type PortBinding struct {
Port string
Protocol string
Expand Down
1 change: 1 addition & 0 deletions pkg/types/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (

ImageLabelVendor = "ai.tensorchord.envd.vendor"
ImageLabelGPU = "ai.tensorchord.envd.gpu"
ImageLabelRepo = "ai.tensorchord.envd.repo"
ImageLabelPorts = "ai.tensorchord.envd.ports"
ImageLabelAPT = "ai.tensorchord.envd.apt.packages"
ImageLabelPyPI = "ai.tensorchord.envd.pypi.commands"
Expand Down

0 comments on commit 356a707

Please sign in to comment.