Skip to content

Commit

Permalink
Support of '--no-join' option (fix #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Sep 25, 2015
1 parent c707dca commit a322548
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
18 changes: 12 additions & 6 deletions client.go
Expand Up @@ -122,13 +122,19 @@ func (c *Client) HandleChannelRequests(channel ssh.Channel, requests <-chan *ssh
ok = true

// checking if a container already exists for this user
cmd := exec.Command("docker", "ps", "--filter=label=ssh2docker", "--filter=label=image:ubuntu", "--filter=label=user:nobody", "--quiet", "--no-trunc")
buf, err := cmd.CombinedOutput()
if err != nil {
logrus.Warnf("docker ps ... failed: %v", err)
continue
existingContainer := ""
if !c.Server.NoJoin {
cmd := exec.Command("docker", "ps", "--filter=label=ssh2docker", fmt.Sprintf("--filter=label=image:%s", c.ImageName), fmt.Sprintf("--filter=label=user:%s", c.RemoteUser), "--quiet", "--no-trunc")
buf, err := cmd.CombinedOutput()
if err != nil {
logrus.Warnf("docker ps ... failed: %v", err)
continue
}
existingContainer = strings.TrimSpace(string(buf))
}
existingContainer := strings.TrimSpace(string(buf))

var cmd *exec.Cmd
var err error

// Opening Docker process
if existingContainer != "" {
Expand Down
7 changes: 6 additions & 1 deletion cmd/ssh2docker/main.go
Expand Up @@ -85,6 +85,10 @@ func main() {
Usage: "'docker run' arguments",
Value: "-it --rm",
},
cli.BoolFlag{
Name: "no-join",
Usage: "Do not join existing containers, always create new ones",
},
}

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

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

// Register the SSH host key
hostKey := c.String("host-key")
Expand Down
1 change: 1 addition & 0 deletions server.go
Expand Up @@ -15,6 +15,7 @@ type Server struct {
AllowedImages []string
DefaultShell string
DockerRunArgs []string
NoJoin bool
}

// NewServer initialize a new Server instance with default values
Expand Down

0 comments on commit a322548

Please sign in to comment.