PullImages pulls images in parallel if they don't exist locally If pullAlways is true, it will always pull Otherwise, it will only pull if the image doesn't exist
(images []string, pullAlways bool)
| 356 | // If pullAlways is true, it will always pull |
| 357 | // Otherwise, it will only pull if the image doesn't exist |
| 358 | func PullImages(images []string, pullAlways bool) error { |
| 359 | if len(images) == 0 { |
| 360 | return nil |
| 361 | } |
| 362 | |
| 363 | composeYamlPull, err := CreateComposeProject("name: compose-yaml-pull") |
| 364 | if err != nil { |
| 365 | return err |
| 366 | } |
| 367 | |
| 368 | for _, image := range images { |
| 369 | if image == "" { |
| 370 | continue |
| 371 | } |
| 372 | if !pullAlways { |
| 373 | if imageExists, _ := ImageExistsLocally(image); imageExists { |
| 374 | continue |
| 375 | } |
| 376 | } |
| 377 | service := sanitizeServiceName(image) |
| 378 | if _, exists := composeYamlPull.Services[service]; exists { |
| 379 | continue |
| 380 | } |
| 381 | composeYamlPull.Services[service] = types.ServiceConfig{ |
| 382 | Image: image, |
| 383 | } |
| 384 | util.Debug(`Pulling image for %s ("%s" service)`, image, service) |
| 385 | } |
| 386 | |
| 387 | if len(composeYamlPull.Services) == 0 { |
| 388 | util.Debug("All images already exist locally, no pull needed") |
| 389 | return nil |
| 390 | } |
| 391 | |
| 392 | if !output.JSONOutput && isatty.IsTerminal(os.Stdin.Fd()) { |
| 393 | err = ComposeWithStreams(&ComposeCmdOpts{ |
| 394 | ComposeYaml: composeYamlPull, |
| 395 | Action: []string{"pull"}, |
| 396 | Env: []string{"COMPOSE_DISABLE_ENV_FILE=1"}, |
| 397 | }, nil, os.Stdout, os.Stderr) |
| 398 | } else { |
| 399 | _, _, err = ComposeCmd(&ComposeCmdOpts{ |
| 400 | ComposeYaml: composeYamlPull, |
| 401 | Action: []string{"pull"}, |
| 402 | Env: []string{"COMPOSE_DISABLE_ENV_FILE=1"}, |
| 403 | }) |
| 404 | } |
| 405 | |
| 406 | return err |
| 407 | } |
| 408 | |
| 409 | // Pull pulls image if it doesn't exist locally |
| 410 | func Pull(image string) error { |
no test coverage detected