Skip to content

Commit

Permalink
Merge 239f72a into 04d0b5e
Browse files Browse the repository at this point in the history
  • Loading branch information
mvid committed Jun 13, 2021
2 parents 04d0b5e + 239f72a commit 032ac15
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
20 changes: 18 additions & 2 deletions docker/opts/opts_unix.go
Expand Up @@ -4,9 +4,8 @@ package opts

import (
"fmt"
"strings"

"github.com/pkg/errors"
"strings"
)

// DefaultHTTPHost Default HTTP Host used if only port is provided to -H flag e.g. dockerd -H tcp://:8080
Expand All @@ -20,3 +19,20 @@ func MountParser(mount string) (source, destination string, err error) {
}
return "", "", errors.Wrap(fmt.Errorf("invalid mount format: got %s, expected <src>:<dst>", mount), "")
}

// VolumeParser parsed volume path.
func VolumeParser(volume string) (source, target string, readOnly bool, err error) {
st := strings.Split(volume, ":")
if len(st) == 3 {
if st[2] == "ro" {
return st[0], st[1], true, nil
} else {
return "", "", false, errors.Wrap(fmt.Errorf("invalid volume format: got %s, expected <src>:<trgt>:ro", volume), "")
}

}
if len(st) == 2 {
return st[0], st[1], false, nil
}
return "", "", false, errors.Wrap(fmt.Errorf("invalid volume format: got %s, expected <src>:<trgt>", volume), "")
}
11 changes: 10 additions & 1 deletion docker/opts/opts_windows.go
Expand Up @@ -68,5 +68,14 @@ func MountParser(mount string) (source, destination string, err error) {
if len(sd) == 3 {
return sd[0] + sd[1], sd[2], nil
}
return "", "", errors.Wrap(fmt.Errorf("invalid mount format: got %s, expected <drive>:<src>:<dst>", mount), "")
return "", "", errors.Wrap(errors.Wrap(fmt.Errorf("invalid mount format: got %s, expected <drive>:<src>:<dst>", mount), ""), "")
}

// VolumeParser parsed volume path.
func VolumeParser(volume string) (source, target string, readOnly bool, err error) {
st := strings.Split(volume, ":")
if len(st) == 3 {
return st[1], st[2], false, nil
}
return "", "", false, errors.Wrap(errors.Wrap(fmt.Errorf("invalid volume format: got %s, expected <drive>:<src>:<trgt>", volume), ""),"")
}
16 changes: 16 additions & 0 deletions dockertest.go
Expand Up @@ -287,6 +287,7 @@ type RunOptions struct {
Entrypoint []string
Cmd []string
Mounts []string
Volumes []string
Links []string
ExposedPorts []string
ExtraHosts []string
Expand Down Expand Up @@ -382,6 +383,20 @@ func (d *Pool) RunWithOptions(opts *RunOptions, hcOpts ...func(*dc.HostConfig))
})
}

var volumes []dc.HostMount
for _, v := range opts.Volumes {
s, t, ro, err := options.VolumeParser(v)
if err != nil {
return nil, err
}
volumes = append(volumes, dc.HostMount{
Type: "volume",
Source: s,
Target: t,
ReadOnly: ro,
})
}

if tag == "" {
tag = "latest"
}
Expand Down Expand Up @@ -416,6 +431,7 @@ func (d *Pool) RunWithOptions(opts *RunOptions, hcOpts ...func(*dc.HostConfig))
SecurityOpt: opts.SecurityOpt,
Privileged: opts.Privileged,
DNS: opts.DNS,
Mounts: volumes,
}

for _, hostConfigOption := range hcOpts {
Expand Down

0 comments on commit 032ac15

Please sign in to comment.