Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
e9278cc0
Commit
e9278cc0
authored
May 06, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/plugin: Randomly generate port to run on
parent
b9e3eb1f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
3 deletions
+28
-3
packer/plugin/plugin.go
packer/plugin/plugin.go
+21
-2
packer/plugin/plugin_test.go
packer/plugin/plugin_test.go
+7
-1
No files found.
packer/plugin/plugin.go
View file @
e9278cc0
...
@@ -10,19 +10,38 @@ import (
...
@@ -10,19 +10,38 @@ import (
"net/rpc"
"net/rpc"
"os"
"os"
packrpc
"github.com/mitchellh/packer/packer/rpc"
packrpc
"github.com/mitchellh/packer/packer/rpc"
"strconv"
)
)
// This serves a single RPC connection on the given RPC server on
// This serves a single RPC connection on the given RPC server on
// a random port.
// a random port.
func
serve
(
server
*
rpc
.
Server
)
(
err
error
)
{
func
serve
(
server
*
rpc
.
Server
)
(
err
error
)
{
listener
,
err
:=
net
.
Listen
(
"tcp"
,
":2345"
)
minPort
,
err
:=
strconv
.
ParseInt
(
os
.
Getenv
(
"PACKER_PLUGIN_MIN_PORT"
),
10
,
32
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
maxPort
,
err
:=
strconv
.
ParseInt
(
os
.
Getenv
(
"PACKER_PLUGIN_MAX_PORT"
),
10
,
32
)
if
err
!=
nil
{
return
}
var
address
string
var
listener
net
.
Listener
for
port
:=
minPort
;
port
<=
maxPort
;
port
++
{
address
=
fmt
.
Sprintf
(
":%d"
,
port
)
listener
,
err
=
net
.
Listen
(
"tcp"
,
address
)
if
err
!=
nil
{
return
}
break
}
defer
listener
.
Close
()
defer
listener
.
Close
()
// Output the address to stdout
// Output the address to stdout
fmt
.
Println
(
":2345"
)
fmt
.
Println
(
address
)
os
.
Stdout
.
Sync
()
os
.
Stdout
.
Sync
()
// Accept a connection
// Accept a connection
...
...
packer/plugin/plugin_test.go
View file @
e9278cc0
...
@@ -21,8 +21,14 @@ func (helperCommand) Synopsis() string {
...
@@ -21,8 +21,14 @@ func (helperCommand) Synopsis() string {
func
helperProcess
(
s
...
string
)
*
exec
.
Cmd
{
func
helperProcess
(
s
...
string
)
*
exec
.
Cmd
{
cs
:=
[]
string
{
"-test.run=TestHelperProcess"
,
"--"
}
cs
:=
[]
string
{
"-test.run=TestHelperProcess"
,
"--"
}
cs
=
append
(
cs
,
s
...
)
cs
=
append
(
cs
,
s
...
)
env
:=
[]
string
{
"GO_WANT_HELPER_PROCESS=1"
,
"PACKER_PLUGIN_MIN_PORT=10000"
,
"PACKER_PLUGIN_MAX_PORT=25000"
,
}
cmd
:=
exec
.
Command
(
os
.
Args
[
0
],
cs
...
)
cmd
:=
exec
.
Command
(
os
.
Args
[
0
],
cs
...
)
cmd
.
Env
=
append
(
[]
string
{
"GO_WANT_HELPER_PROCESS=1"
}
,
os
.
Environ
()
...
)
cmd
.
Env
=
append
(
env
,
os
.
Environ
()
...
)
return
cmd
return
cmd
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment