Skip to content

Commit

Permalink
Merge pull request #35 from Crazybus/extra_extra
Browse files Browse the repository at this point in the history
Add option to specify custom docker arguments
  • Loading branch information
Crazybus authored Nov 24, 2018
2 parents ced1a55 + 9495ab9 commit eba6a78
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ cp $GOPATH/github.com/Crazybus/lope/lope /usr/local/bin

### Planned

* Add option to specify custom docker flags
* Get vagrant/virtualbox combo working
* Make sure all images/names are unique so multiple lopes can be run at the same time
* If using addMount add all .dot directories instead of mounting them
Expand Down Expand Up @@ -225,3 +224,4 @@ cp $GOPATH/github.com/Crazybus/lope/lope /usr/local/bin
* Mount the docker socket into the container
* Automated ssh agent forwarding for OSX. https://github.com/uber-common/docker-ssh-agent-forward
* Run as current user and group when bind mounting
* Add option to specify custom docker flags
10 changes: 10 additions & 0 deletions lope.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ func (l *lope) addUserAndGroup() {
}

func (l *lope) runParams() {

for _, a := range extraArgs {
for _, s := range strings.Split(a, " ") {
l.params = append(l.params, s)
}
}

l.params = append(l.params, l.cfg.image, "-c", strings.Join(l.cfg.cmd, " "))
}

Expand Down Expand Up @@ -424,6 +431,7 @@ func (i *flagArray) Set(value string) error {

var instructions flagArray
var mountPaths flagArray
var extraArgs flagArray

func main() {

Expand All @@ -446,6 +454,8 @@ func main() {

flag.Var(&mountPaths, "path", "Paths that will be mounted from the users home directory into lope. Path will be ignored if it isn't accessible. Can be specified multiple times")

flag.Var(&extraArgs, "arg", "Extra docker run arguments which will be appended to the docker run command. Can be specified multiple times")

noMount := flag.Bool("noMount", false, "Disable mounting the current working directory into the image")

addMount := flag.Bool("addMount", false, "Setting this will add the directory into the image instead of mounting it")
Expand Down
13 changes: 13 additions & 0 deletions lope_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ func TestLopeCli(t *testing.T) {
"README.md",
},
},
{
"Run a command with an extra docker arg",
[]string{
"-noTty",
"-arg",
"--hostname=crazybus",
"alpine",
"hostname",
},
[]string{
"crazybus",
},
},
}

for _, test := range tests {
Expand Down
22 changes: 17 additions & 5 deletions lope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"net/url"
"reflect"
"strings"
"testing"
)
Expand Down Expand Up @@ -40,20 +41,30 @@ func TestRunParams(t *testing.T) {
var tests = []struct {
description string
cmd []string
extra []string
image string
want string
want []string
}{
{
"Run command with image and cmd",
[]string{"command"},
[]string{},
"imageName",
"imageName -c command",
[]string{"imageName", "-c", "command"},
},
{
"Run command with image and multiple cmd args",
[]string{"command", "-arg"},
[]string{},
"imageName",
"imageName -c command -arg",
[]string{"imageName", "-c", "command -arg"},
},
{
"Run command with an extra arg",
[]string{"command", "-arg"},
[]string{"--ulimit 10"},
"imageName",
[]string{"--ulimit", "10", "imageName", "-c", "command -arg"},
},
}

Expand All @@ -62,12 +73,13 @@ func TestRunParams(t *testing.T) {
l.params = make([]string, 0)
l.cfg.cmd = test.cmd
l.cfg.image = test.image
extraArgs = test.extra
l.runParams()

got := strings.Join(l.params, " ")
got := l.params
want := test.want

if got != want {
if !reflect.DeepEqual(got, want) {
t.Errorf("got %q want %q", got, want)
}
})
Expand Down

0 comments on commit eba6a78

Please sign in to comment.