Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve docker port configurability #59

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/localnet/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ func PlatformDirMount(ctx context.Context, platform tools.Platform) (volume infr

// FromHostAddress returns address of the app service seen from the host.
func FromHostAddress(proto string, app *infra.App, port infra.PortName) string {
return infra.JoinNetAddr(proto, app.Info().HostFromHost, app.Ports[port])
return infra.JoinNetAddr(proto, app.Info().HostFromHost, app.Ports[port].HostPort)
}

// FromContainerAddress returns address of the app service seen from the container.
func FromContainerAddress(proto string, app *infra.App, port infra.PortName) string {
return infra.JoinNetAddr(proto, app.Info().HostFromContainer, app.Ports[port])
return infra.JoinNetAddr(proto, app.Info().HostFromContainer, app.Ports[port].ContainerPort)
}

func appDir(ctx context.Context, appName string) string {
Expand Down
4 changes: 1 addition & 3 deletions pkg/localnet/infra/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os"
osexec "os/exec"
"path/filepath"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -179,8 +178,7 @@ func (d *Docker) prepareRunArgs(app *App) []string {
runArgs = append(runArgs, "--user", fmt.Sprintf("%d:%d", os.Getuid(), os.Getgid()))
}
for _, port := range app.Ports {
portStr := strconv.Itoa(port)
runArgs = append(runArgs, "-p", "127.0.0.1:"+portStr+":"+portStr+"/tcp")
runArgs = append(runArgs, "-p", fmt.Sprintf("127.0.0.1:%d:%d/tcp", port.HostPort, port.ContainerPort))
}
for _, v := range app.Volumes {
runArgs = append(runArgs, "-v", lo.Must(filepath.EvalSymlinks(lo.Must(filepath.Abs(v.Source))))+":"+
Expand Down
8 changes: 7 additions & 1 deletion pkg/localnet/infra/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,14 @@ type Volume struct {
// PortName represents the name of the port.
type PortName string

// DockerPort is the port mapping from host to container.
type DockerPort struct {
HostPort int
ContainerPort int
}

// Ports is the map of exposed ports.
type Ports map[PortName]int
type Ports map[PortName]DockerPort

// App represents application to be deployed.
type App struct {
Expand Down
Loading