Skip to content

Commit

Permalink
Removes publish All by default and locks to localhost for port binding
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkirkbater committed May 10, 2024
1 parent 2206028 commit bc26f2b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type ContainerRef struct {
BestEffortArgs []string
Privileged bool
RemoveAfterExit bool
LocalPorts map[string]int
}

type VolumeMount struct {
Expand Down Expand Up @@ -233,8 +234,14 @@ func parseRefToArgs(c ContainerRef) ([]string, error) {
args = append(args, "--rm")
}

// If PublishAll is set - publish all of the ports. Otherwise, bind each
// one individually to localhost.
if c.PublishAll {
args = append(args, "--publish-all")
} else if c.LocalPorts != nil {
for service, _ := range c.LocalPorts {
args = append(args, fmt.Sprintf("--publish=127.0.0.1::%d", c.LocalPorts[service]))
}
}

if c.Envs != nil {
Expand Down
8 changes: 6 additions & 2 deletions pkg/ocmcontainer/ocmcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ func New(cmd *cobra.Command, args []string) (*ocmContainer, error) {
// disable-console-port is deprecated so this we're also checking the new --no-console-port flag
// This can be simplified when disable-console-port is deprecated and removed
if featureEnabled("console-port") && !viper.GetBool("disable-console-port") {
c.PublishAll = true
if c.LocalPorts == nil {
c.LocalPorts = map[string]int{}
}
c.LocalPorts["console"] = 9999
}

// GCloud configuration
Expand Down Expand Up @@ -262,7 +265,8 @@ func New(cmd *cobra.Command, args []string) (*ocmContainer, error) {
}

func (o *ocmContainer) consolePortEnabled() bool {
return o.container.Ref.PublishAll
_, ok := o.container.Ref.LocalPorts["console"]
return ok
}

func (o *ocmContainer) newConsolePortMap() error {
Expand Down

0 comments on commit bc26f2b

Please sign in to comment.