Skip to content

Commit

Permalink
Merge pull request #70 from buildkite/bind-address
Browse files Browse the repository at this point in the history
Add --listen-port to allow a stable port to be chosen
  • Loading branch information
lox authored Nov 28, 2019
2 parents 2994a9e + bc32a5f commit 8ce00dc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ We'd love to hear any feedback and questions you might have. Please [file an iss

On macOS, you can install with [Homebrew](https://brew.sh):

```
```bash
brew tap buildkite/cli
brew install bk
````
Expand Down Expand Up @@ -45,7 +45,7 @@ bk init

Developed using Golang 1.11+ with modules.

```
```bash
export GO111MODULE=on
git clone git@github.com:buildkite/cli.git
cd cli/
Expand Down
4 changes: 4 additions & 0 deletions cmd/bk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ func run(args []string, exit func(int)) {
Short('M').
StringMapVar(&runCmdCtx.Metadata)

cmd.
Flag("listen-port", "A specific port for the local API server to listen on").
IntVar(&runCmdCtx.ListenPort)

cmd.
Arg("file", "A specific pipeline file to upload").
FileVar(&runCmdCtx.File)
Expand Down
1 change: 1 addition & 0 deletions cmd_local_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type LocalRunCommandContext struct {
StepFilterRegex *regexp.Regexp
Prompt bool
DryRun bool
ListenPort int
}

func LocalRunCommand(ctx LocalRunCommandContext) error {
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf h1:fnPsqIDRbCSgumaMCRpoIo
golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20180530034148-89e543239a64 h1:otRUcJnCzmletog6NvNtimZZStU31VhmAuuno53i0Nk=
golang.org/x/net v0.0.0-20180530034148-89e543239a64/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/oauth2 v0.0.0-20180529203656-ec22f46f877b h1:nCwwlzLoBQhkY/S3CJ2CGAU4pYfR8+5/TPGEHT+p5Nk=
golang.org/x/oauth2 v0.0.0-20180529203656-ec22f46f877b/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down
3 changes: 2 additions & 1 deletion local/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ type RunParams struct {
StepFilter *regexp.Regexp
DryRun bool
JobTemplate Job
ListenPort int
}

func Run(ctx context.Context, params RunParams) error {
agentPool := newAgentPool()
server := newApiServer(agentPool)
server := newApiServer(agentPool, params.ListenPort)
steps := newStepQueue()

// Consume pipeline uploads from the server and apply any filters
Expand Down
6 changes: 4 additions & 2 deletions local/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,22 @@ type apiServer struct {
agents *agentPool
pipelineUploads chan pipelineUpload
listener net.Listener
listenPort int

sync.Mutex
jobs []*jobEnvelope
artifacts *orderedMap
metadata *orderedMap
}

func newApiServer(agentPool *agentPool) *apiServer {
func newApiServer(agentPool *agentPool, listenPort int) *apiServer {
return &apiServer{
agents: agentPool,
pipelineUploads: make(chan pipelineUpload),
jobs: []*jobEnvelope{},
artifacts: newOrderedMap(),
metadata: newOrderedMap(),
listenPort: listenPort,
}
}

Expand Down Expand Up @@ -857,7 +859,7 @@ func readRequestInto(r *http.Request, into interface{}) error {

func (a *apiServer) ListenAndServe() (string, error) {
var err error
a.listener, err = net.Listen("tcp", "127.0.0.1:0")
a.listener, err = net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", a.listenPort))
if err != nil {
return "", err
}
Expand Down

0 comments on commit 8ce00dc

Please sign in to comment.