Skip to content

Commit

Permalink
Ability to configure docker run arguments (fix #13)
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Sep 25, 2015
1 parent 1554517 commit 6132818
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ func (c *Client) HandleChannelRequests(channel ssh.Channel, requests <-chan *ssh
}
ok = true

args := []string{"run", "-it", "--rm", c.Conn.User(), "/bin/sh"}
args := []string{"run"}
args = append(args, c.Server.DockerRunArgs...)
args = append(args, c.Conn.User(), c.Server.DefaultShell)
logrus.Debugf("Executing 'docker %s'", strings.Join(args, " "))
cmd := exec.Command("docker", args...)
cmd.Env = c.Env.List()
Expand Down
14 changes: 14 additions & 0 deletions cmd/ssh2docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func main() {
Usage: "List of allowed images, i.e: alpine,ubuntu:trusty,1cf3e6c",
Value: "",
},
cli.StringFlag{
Name: "shell",
Usage: "Default shell",
Value: "/bin/sh",
},
cli.StringFlag{
Name: "docker-run-args",
Usage: "'docker run' arguments",
Value: "-it --rm",
},
}

app.Action = Action
Expand Down Expand Up @@ -105,6 +115,10 @@ func Action(c *cli.Context) {
server.AllowedImages = strings.Split(c.String("allowed-images"), ",")
}

// Set defaults
server.DefaultShell = c.String("shell")
server.DockerRunArgs = strings.Split(c.String("docker-run-args"), " ")

// Register the SSH host key
hostKey := c.String("host-key")
if hostKey == "built-in" {
Expand Down
4 changes: 4 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type Server struct {
// Clients []Client

AllowedImages []string
DefaultShell string
DockerRunArgs []string
}

// NewServer initialize a new Server instance with default values
Expand All @@ -22,6 +24,8 @@ func NewServer() (*Server, error) {
PasswordCallback: server.PasswordCallback,
}
server.AllowedImages = nil
server.DefaultShell = "/bin/sh"
server.DockerRunArgs = []string{"-it", "--rm"}
return &server, nil
}

Expand Down

0 comments on commit 6132818

Please sign in to comment.