Skip to content

Commit

Permalink
fix: add missing expose func exposed port to oci manifest (#797)
Browse files Browse the repository at this point in the history
* WIP: refactor the runtime graph

Signed-off-by: nullday <[email protected]>

* Refactor: introduce runtimeGraph as a embeded

Signed-off-by: nullday <[email protected]>

* fix: add missing exposed port metadata in OCI manifest

Signed-off-by: nullday <[email protected]>

* refactor: remove abstraction expose config

Signed-off-by: nullday <[email protected]>

Signed-off-by: nullday <[email protected]>
  • Loading branch information
aseaday authored Aug 19, 2022
1 parent 3a97375 commit 4440e22
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
4 changes: 2 additions & 2 deletions pkg/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ func (c generalClient) StartEnvd(ctx context.Context, tag, name, buildContext st
config.ExposedPorts[natPort] = struct{}{}
}

if g.ExposeConfig != nil && len(g.ExposeConfig.ExposeItems) > 0 {
for _, item := range g.ExposeConfig.ExposeItems {
if len(g.RuntimeExpose) > 0 {
for _, item := range g.RuntimeExpose {
var err error
if item.HostPort == 0 {
item.HostPort, err = netutil.GetFreePort()
Expand Down
25 changes: 17 additions & 8 deletions pkg/lang/ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import (
)

func NewGraph() *Graph {
runtimeGraph := RuntimeGraph{
RuntimeCommands: make(map[string]string),
RuntimeEnviron: make(map[string]string),
}
return &Graph{
OS: osDefault,
Language: Language{
Expand All @@ -44,14 +48,13 @@ func NewGraph() *Graph {
CUDNN: nil,
NumGPUs: -1,

PyPIPackages: []string{},
RPackages: []string{},
JuliaPackages: []string{},
SystemPackages: []string{},
Exec: []string{},
RuntimeCommands: make(map[string]string),
RuntimeEnviron: make(map[string]string),
Shell: shellBASH,
PyPIPackages: []string{},
RPackages: []string{},
JuliaPackages: []string{},
SystemPackages: []string{},
Exec: []string{},
Shell: shellBASH,
RuntimeGraph: runtimeGraph,
}
}

Expand Down Expand Up @@ -151,6 +154,12 @@ func (g Graph) ExposedPorts() (map[string]struct{}, error) {
ports[fmt.Sprintf("%d/tcp", config.RStudioServerPortInContainer)] = struct{}{}
}

if g.RuntimeExpose != nil && len(g.RuntimeExpose) > 0 {
for _, item := range g.RuntimeExpose {
ports[fmt.Sprintf("%d/tcp", item.EnvdPort)] = struct{}{}
}
}

return ports, nil
}

Expand Down
7 changes: 1 addition & 6 deletions pkg/lang/ir/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,7 @@ func RuntimeDaemon(commands [][]string) {
}

func RuntimeExpose(envdPort, hostPort int, serviceName string) error {
if DefaultGraph.ExposeConfig == nil {
DefaultGraph.ExposeConfig = &ExposeConfig{
ExposeItems: make([]ExposeItem, 0),
}
}
DefaultGraph.ExposeConfig.ExposeItems = append(DefaultGraph.ExposeConfig.ExposeItems, ExposeItem{
DefaultGraph.RuntimeExpose = append(DefaultGraph.RuntimeExpose, ExposeItem{
EnvdPort: envdPort,
HostPort: hostPort,
ServiceName: serviceName,
Expand Down
26 changes: 14 additions & 12 deletions pkg/lang/ir/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,28 @@ type Graph struct {

VSCodePlugins []vscode.Plugin

Exec []string
Copy []CopyInfo
Mount []MountInfo
Entrypoint []string
RuntimeCommands map[string]string
RuntimeDaemon [][]string
RuntimeEnviron map[string]string
Exec []string
Copy []CopyInfo
Mount []MountInfo
Entrypoint []string

*JupyterConfig
*GitConfig
*CondaConfig
*RStudioServerConfig
*ExposeConfig

Writer compileui.Writer
CachePrefix string

RuntimeGraph
}

// The results during runtime should be maintained here
type RuntimeGraph struct {
RuntimeCommands map[string]string
RuntimeDaemon [][]string
RuntimeEnviron map[string]string
RuntimeExpose []ExposeItem
}

type CopyInfo struct {
Expand Down Expand Up @@ -104,10 +110,6 @@ type ExposeItem struct {
ServiceName string
}

type ExposeConfig struct {
ExposeItems []ExposeItem
}

type JupyterConfig struct {
Token string
Port int64
Expand Down

0 comments on commit 4440e22

Please sign in to comment.