func newDockerPullExecutor()

in command-runner/internal/containers/docker/docker_pull.go [27:74]


func newDockerPullExecutor(input newDockerPullExecutorInput) common.Executor {
	return func(ctx context.Context) error {
		log.Ctx(ctx).Printf("%sdocker pull %v", logPrefix, input.Image)

		if common.Dryrun(ctx) {
			return nil
		}

		pull := input.ForcePull
		if !pull {
			imageExists, err := imageExistsLocally(ctx, input.Image, input.Platform)
			log.Ctx(ctx).Printf("Image exists? %v", imageExists)
			if err != nil {
				return fmt.Errorf("unable to determine if image already exists for image '%s' (%s): %w", input.Image, input.Platform, err)
			}

			if !imageExists {
				pull = true
			}
		}

		if !pull {
			return nil
		}

		imageRef := cleanImage(ctx, input.Image)
		log.Ctx(ctx).Printf("pulling image '%v' (%s)", imageRef, input.Platform)

		cli, err := getDockerClient(ctx)
		if err != nil {
			return err
		}
		defer cli.Close()

		imagePullOptions, err := getImagePullOptions(ctx, input)
		if err != nil {
			return err
		}

		reader, err := cli.ImagePull(ctx, imageRef, imagePullOptions)

		_ = logDockerResponse(log.Ctx(ctx), reader, err != nil)
		if err != nil {
			return err
		}
		return nil
	}
}