(task *task.Task, tar io.ReadCloser, options types.ImageBuildOptions)
| 272 | } |
| 273 | |
| 274 | func (c Client) BuildImageWithProcessAndOptions(task *task.Task, tar io.ReadCloser, options types.ImageBuildOptions) error { |
| 275 | out, err := c.cli.ImageBuild(context.Background(), tar, options) |
| 276 | if err != nil { |
| 277 | return err |
| 278 | } |
| 279 | defer out.Body.Close() |
| 280 | decoder := json.NewDecoder(out.Body) |
| 281 | for { |
| 282 | var progress map[string]interface{} |
| 283 | if err = decoder.Decode(&progress); err != nil { |
| 284 | if err == io.EOF { |
| 285 | break |
| 286 | } |
| 287 | return err |
| 288 | } |
| 289 | if msg, ok := progress["errorDetail"]; ok { |
| 290 | return fmt.Errorf("image build failed, err: %v", msg) |
| 291 | } |
| 292 | if msg, ok := progress["error"]; ok { |
| 293 | return fmt.Errorf("image build failed, err: %v", msg) |
| 294 | } |
| 295 | status, _ := progress["status"].(string) |
| 296 | stream, _ := progress["stream"].(string) |
| 297 | if len(status) == 0 && len(stream) != 0 { |
| 298 | if stream != "\n" { |
| 299 | task.Log(stream) |
| 300 | } |
| 301 | continue |
| 302 | } |
| 303 | switch status { |
| 304 | case "Downloading", "Extracting": |
| 305 | logProcess(progress, task) |
| 306 | case "Pull complete", "Download complete", "Verifying Checksum": |
| 307 | id, _ := progress["id"].(string) |
| 308 | progressStr := fmt.Sprintf("%s %s", status, id) |
| 309 | _ = setLog(id, progressStr, task) |
| 310 | default: |
| 311 | progressStr, _ := json.Marshal(progress) |
| 312 | task.Log(string(progressStr)) |
| 313 | } |
| 314 | } |
| 315 | return nil |
| 316 | } |
| 317 | |
| 318 | func (c Client) PullImageWithProcess(task *task.Task, imageName string) error { |
| 319 | options := image.PullOptions{} |
no test coverage detected