Skip to content

Commit

Permalink
feat: add runtime graph to image label (#815)
Browse files Browse the repository at this point in the history
* feat: add proposal for runtime graph image label

Signed-off-by: nullday <aseaday@hotmail.com>

* docs: Add running context

Signed-off-by: nullday <aseaday@hotmail.com>

* Add design details for proposal

Signed-off-by: nullday <aseaday@hotmail.com>

* Add implementation

Signed-off-by: nullday <aseaday@hotmail.com>

* Fix lint

Signed-off-by: nullday <aseaday@hotmail.com>

* Fix proposal

Signed-off-by: nullday <aseaday@hotmail.com>

* Refact the method name of dump and load

Signed-off-by: nullday <aseaday@hotmail.com>

* Move msgpack to json

Signed-off-by: nullday <aseaday@hotmail.com>

* Remove msgpack in proposal

Signed-off-by: nullday <aseaday@hotmail.com>

* Fix go.mod and go.sum

Signed-off-by: nullday <aseaday@hotmail.com>

Signed-off-by: nullday <aseaday@hotmail.com>
  • Loading branch information
aseaday committed Sep 6, 2022
1 parent 6ad1d4c commit 8056fda
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
54 changes: 54 additions & 0 deletions docs/proposals/20220826-image-runtime-redistributed-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Add Runtime Configuration to Image for Envd Image Redistribution
Authors:
- [nullday](https://github.com/aseaday)

## Summary

The `envd` would add (runing graph metadata)[https://github.com/tensorchord/envd/blob/630ada172bdf876c3b749329fdbe284c108051f2/pkg/lang/ir/types.go#L70] would be encoded into a ASCII string and added to be image(OCI Spec) as a config.

we named the above mentioned encoded config `Envd Runtime Graph Label`

## Motivation

This proposal is part of effort to define what the artifact `envd` delivery and decoupling the phases of build and runing. It will be friendly for running a envd environment even at the absence of `build.env`.

the concept of `running context` is a also needed as addition of `build contxt` for example:

- An engineer build a easy-to-use env for his/her interns for the quick use of company tools.
- Kubernetes remote runtime support in the future.

## Goals
- Provide internal API:
- read runtime metadata
- write runtime metadata
- `up` and `run` command doesn't need to interpret the `build.env`. `run` command can run a built env image with attachment of current working directory as `running context`.

## Implementations

There are two parts of runtime configuration that can be used in envd.
- OCI sepecifications specific:
- ExposedPort
- Entrypoint
- Env
- Cmd
- Custome Labels

For some parts of runtime configuration, we could use the OCI part such as environment variables. We still need to deal with extra parts such as port bindings which not covered by the OCI spec.

```golang
type RuntimeGraph struct {
RuntimeCommands map[string]string
RuntimeDaemon [][]string
RuntimeEnviron map[string]string
RuntimeExpose []ExposeItem
}
```

- *RuntimeEnviron* is completely in accordance with the OCI defined configuration `Env`. So we don't need to add it to the runtime label.
- *RuntimeDaemon* and *RuntimeExpose* will be added to the runtime label and we also should update the config the OCI configuration's Entrypoint and ExposedPort accordingly.

we use the following labels:

- ai.tensorchord.envd.runtimeGraph.version
- ai.tensorchord.envd.runtimeGraph.Daemon
- ai.tensorchord.envd.runtimeGraph.Expose
5 changes: 5 additions & 0 deletions pkg/lang/ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ func (g Graph) Labels() (map[string]string, error) {
}
}
labels[types.ImageLabelVendor] = types.ImageVendorEnvd
code, err := g.RuntimeGraph.Dump()
if err != nil {
return labels, err
}
labels[types.RuntimeGraphCode] = code

return labels, nil
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/lang/ir/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package ir

import (
"encoding/json"
"os/user"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -67,3 +68,25 @@ func getUIDGID() (int, int, error) {
}
return uid, gid, nil
}

func (rg *RuntimeGraph) Dump() (string, error) {
b, err := json.Marshal(rg)
if err != nil {
return "", nil
}
runtimeGraphCode := string(b)
return runtimeGraphCode, nil
}

func (rg *RuntimeGraph) Load(code []byte) error {
var newrg *RuntimeGraph
err := json.Unmarshal(code, newrg)
if err != nil {
return err
}
rg.RuntimeCommands = newrg.RuntimeCommands
rg.RuntimeDaemon = newrg.RuntimeDaemon
rg.RuntimeEnviron = newrg.RuntimeEnviron
rg.RuntimeExpose = newrg.RuntimeExpose
return nil
}
1 change: 1 addition & 0 deletions pkg/types/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
ImageLabelCUDNN = "ai.tensorchord.envd.gpu.cudnn"
ImageLabelContext = "ai.tensorchord.envd.build.context"
ImageLabelCacheHash = "ai.tensorchord.envd.build.digest"
RuntimeGraphCode = "ai.tensorchord.envd.runtimeGraph"

ImageVendorEnvd = "envd"
)

0 comments on commit 8056fda

Please sign in to comment.