Skip to content

Commit

Permalink
Add "orchard run" command
Browse files Browse the repository at this point in the history
It starts a proxy to an Orchard host, then runs a local command
with the DOCKER_HOST envvar set.

Signed-off-by: Ben Firshman <[email protected]>
  • Loading branch information
bfirsh committed Jul 11, 2014
1 parent 73ab555 commit 428398f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var All = []*Command{
Hosts,
IP,
Proxy,
Run,
}

var HostSubcommands = []*Command{
Expand All @@ -71,6 +72,7 @@ func init() {
Docker.Run = RunDocker
Proxy.Run = RunProxy
IP.Run = RunIP
Run.Run = RunRun
}

var Hosts = &Command{
Expand Down Expand Up @@ -165,6 +167,23 @@ host (named 'default') will be assumed.
`,
}

var Run = &Command{
UsageLine: "run [-H HOST] COMMAND [ARGS...]",
Short: "Run a command with the DOCKER_HOST envvar set",
Long: `Start a proxy to an Orchard host and run a command locally
with the DOCKER_HOST environment variable set.
For example:
$ orchard run fig up
You can optionally specify which host - if you don't, the default
host (named 'default') will be assumed.
`,
}

var flRunHost = Run.Flag.String("H", "", "")

func RunHosts(cmd *Command, args []string) error {
list := len(args) == 0 || (len(args) == 1 && args[0] == "ls")

Expand Down Expand Up @@ -331,6 +350,21 @@ func RunIP(cmd *Command, args []string) error {
return nil
}

func RunRun(cmd *Command, args []string) error {
if len(args) < 1 {
return cmd.UsageError("`orchard run` expects at least 1 argument")
}
return WithDockerProxy("", *flRunHost, func(listenURL string) error {
os.Setenv("DOCKER_HOST", listenURL)

cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
})
}

func WithDockerProxy(listenURL, hostName string, callback func(string) error) error {
if hostName == "" {
hostName = "default"
Expand Down

0 comments on commit 428398f

Please sign in to comment.