diff --git a/pkg/docker/docker.go b/pkg/docker/docker.go index 0edb3f7d3..806211ddd 100644 --- a/pkg/docker/docker.go +++ b/pkg/docker/docker.go @@ -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() diff --git a/pkg/lang/ir/compile.go b/pkg/lang/ir/compile.go index cf628fa85..4d479634f 100644 --- a/pkg/lang/ir/compile.go +++ b/pkg/lang/ir/compile.go @@ -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{ @@ -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, } } @@ -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 } diff --git a/pkg/lang/ir/interface.go b/pkg/lang/ir/interface.go index ca71719c2..6eb261345 100644 --- a/pkg/lang/ir/interface.go +++ b/pkg/lang/ir/interface.go @@ -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, diff --git a/pkg/lang/ir/types.go b/pkg/lang/ir/types.go index 1736c8604..59c859a8d 100644 --- a/pkg/lang/ir/types.go +++ b/pkg/lang/ir/types.go @@ -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 { @@ -104,10 +110,6 @@ type ExposeItem struct { ServiceName string } -type ExposeConfig struct { - ExposeItems []ExposeItem -} - type JupyterConfig struct { Token string Port int64