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

fix(lang): expose host port #832

Merged
merged 2 commits into from
Aug 31, 2022
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 envd/api/runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def expose(envd_port: str, host_port: Optional[str], service: Optional[str]):

Args:
envd_port (str): port in `envd` container
host_port (Optional[str]): port in the host, if not provided, `envd` will
randomly choose a free port
host_port (Optional[str]): port in the host, if not provided or
`host_port=0`, `envd` will randomly choose a free port
service (Optional[str]): service name
"""

Expand Down
6 changes: 3 additions & 3 deletions pkg/lang/frontend/starlark/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func ruleFuncExpose(thread *starlark.Thread, _ *starlark.Builtin,
args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var (
envdPort starlark.Int
hostPort = starlark.MakeInt(0)
hostPort = starlark.MakeInt(0) // 0 means envd can randomly choose a free port
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does envd randomly choose a port?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If host_port is not specified, it will use the default value 0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So 0 is the default value for the host port (if users do not set it) instead of an indicator of a randomly assigned value for the host port. Do I understand it correctly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 0 is the default value
  • if it's 0, envd will randomly choose a free port, user can check the host port with envd env describe --env <name>

    envd/pkg/docker/docker.go

    Lines 514 to 519 in 404de31

    if item.HostPort == 0 {
    item.HostPort, err = netutil.GetFreePort()
    if err != nil {
    return "", "", errors.Wrap(err, "failed to get a free port")
    }
    }

serviceName = starlark.String("")
)

Expand All @@ -108,8 +108,8 @@ func ruleFuncExpose(thread *starlark.Thread, _ *starlark.Builtin,
return nil, errors.New("envd_port must be a positive integer less than 65535")
}
hostPortInt, ok := hostPort.Int64()
if !ok || hostPortInt < 1 || hostPortInt > 65535 {
return nil, errors.New("envd_port must be a positive integer less than 65535")
if !ok || hostPortInt < 0 || hostPortInt > 65535 {
return nil, errors.New("host_port must be a positive integer less than 65535")
}
serviceNameStr := serviceName.GoString()

Expand Down