MCPcopy
hub / github.com/perkeep/perkeep / haveImage

Function haveImage

pkg/test/dockertest/docker.go:135–157  ·  view source on GitHub ↗

haveImage reports whether we have the the given docker image. The name can either be of the , or , or form.

(name string)

Source from the content-addressed store, hash-verified

133// haveImage reports whether we have the the given docker image. The name can
134// either be of the <repository>, or <image id>, or <repository:tag> form.
135func haveImage(name string) (ok bool, err error) {
136 out, err := exec.Command("docker", "images", "--no-trunc").Output()
137 if err != nil {
138 return
139 }
140 fields := strings.Split(name, ":")
141 if len(fields) < 2 {
142 return bytes.Contains(out, []byte(name)), nil
143 }
144 tag := fields[1]
145 image := fields[0]
146 sc := bufio.NewScanner(bytes.NewBuffer(out))
147 for sc.Scan() {
148 l := sc.Text()
149 if !strings.HasPrefix(l, image) {
150 continue
151 }
152 if strings.HasPrefix(strings.TrimSpace(strings.TrimPrefix(l, image)), tag) {
153 return true, nil
154 }
155 }
156 return false, sc.Err()
157}
158
159func run(args ...string) (containerID string, err error) {
160 cmd := exec.Command("docker", append([]string{"run"}, args...)...)

Callers 1

runLongTestFunction · 0.85

Calls 5

ContainsMethod · 0.80
HasPrefixMethod · 0.80
CommandMethod · 0.65
TextMethod · 0.65
ErrMethod · 0.45

Tested by

no test coverage detected