-
Notifications
You must be signed in to change notification settings - Fork 269
[services] Let users set the port for process-compose #2299
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
Conversation
internal/services/manager.go
Outdated
BinPath string | ||
ExtraFlags []string | ||
Background bool | ||
PCPort int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProcesssComposePort
internal/services/ports.go
Outdated
return configPort, nil | ||
} | ||
|
||
if portStr, exists := os.LookupEnv("PC_PORT_NUM"); exists { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on naming this DEVBOX_PC_PORT_NUM
Reasons:
- If user sets
PC_PORT_NUM
outside of devbox, it's going to make starting devbox services on multiple projects fail. Since this is the env name set by process compose itself, it's not unreasonable that people will set it. - Keeping track of env variables is easier if we prefix them
- Avoids collisions
internal/services/ports.go
Outdated
return port > 1024 && disallowedPorts[port] == "" | ||
} | ||
|
||
func isPortAvailable(port int) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make getAvailablePort
call this.
internal/services/ports.go
Outdated
if port <= 0 { | ||
return 0, fmt.Errorf("invalid PC_PORT_NUM environment variable: ports cannot be less than 0") | ||
} | ||
return port, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return port, isPortAvailable(port)
so you don't have to call it outside.
internal/services/manager.go
Outdated
if !isPortAvailable(port) { | ||
return fmt.Errorf("port %d is already in use", port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove, call inside selectPort
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
Summary
Users can set the port that process-compose runs on when they use
devbox services
. If they do not specify a port, we default to randomly picking an open port with low risk of conflictUsers can specify their process-compose port by:
--pcport, -p
flag when runningdevbox services up
.PC_PORT_NUM
environment variable. This variable can be set in the projectsdevbox.json
if you want to always use the same port for process-compose. This is overridden by the--pcport
flag.How was it tested?
In the MySQL example:
devbox services up -b -p 8080
, orPC_PORT_NUM devbox services up -b
,I can verify that process-compose is running on my 8080 with
curl localhost:8080/processes
and seeing the list of expected processes.