MCPcopy Index your code
hub / github.com/cortexlabs/cortex / PullImage

Function PullImage

pkg/lib/docker/docker.go:143–205  ·  view source on GitHub ↗
(image string, encodedAuthConfig string, pullVerbosity PullVerbosity)

Source from the content-addressed store, hash-verified

141)
142
143func PullImage(image string, encodedAuthConfig string, pullVerbosity PullVerbosity) (bool, error) {
144 dockerClient, err := GetDockerClient()
145 if err != nil {
146 return false, err
147 }
148
149 if err := CheckImageExistsLocally(dockerClient, image); err == nil {
150 return false, nil
151 }
152
153 pullOutput, err := dockerClient.ImagePull(context.Background(), image, dockertypes.ImagePullOptions{
154 RegistryAuth: encodedAuthConfig,
155 })
156 if err != nil {
157 return false, WrapDockerError(err)
158 }
159 defer pullOutput.Close()
160
161 switch pullVerbosity {
162 case PrintProgressBars:
163 termFd, isTerm := term.GetFdInfo(os.Stderr)
164 jsonmessage.DisplayJSONMessagesStream(pullOutput, os.Stderr, termFd, isTerm, nil)
165 fmt.Println()
166 case PrintDots:
167 var err error
168 fmt.Printf("○ downloading docker image %s ", image)
169 defer func() {
170 if err == nil {
171 fmt.Print(" ✓\n")
172 } else {
173 fmt.Print(" x\n")
174 }
175 }()
176 d := json.NewDecoder(pullOutput)
177 var result jsonmessage.JSONMessage
178 dotCron := cron.Run(print.Dot, nil, 2*time.Second)
179 defer dotCron.Cancel()
180 for {
181 if e := d.Decode(&result); e != nil {
182 if e == io.EOF {
183 return true, nil
184 }
185 err = e
186 return false, err
187 }
188
189 if result.Error != nil {
190 err = result.Error
191 break
192 }
193 }
194 if err != nil {
195 return false, err
196 }
197 default:
198 // wait until the pull has completed
199 if _, err := ioutil.ReadAll(pullOutput); err != nil {
200 return false, err

Callers 1

runManagerFunction · 0.92

Calls 6

RunFunction · 0.92
GetDockerClientFunction · 0.85
CheckImageExistsLocallyFunction · 0.85
WrapDockerErrorFunction · 0.85
CancelMethod · 0.80
PrintMethod · 0.45

Tested by

no test coverage detected