func PullImage(image string) (digest string, err error) {
    ctx := context.Background()
    cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
    if err != nil {
        return "", err
    }
    defer cli.Close()

    resp, err := cli.ImagePull(ctx, image, types.ImagePullOptions{})
    if err != nil {
        return "", err
    }
    defer resp.Close()

    // Extract image digest from response
    // Possible that cli.ImageBuild() does not return an error, but we see an error from the response body
    // Read until EOF sent to ensure proper transfer of image
    scanner := bufio.NewScanner(resp)
    for scanner.Scan() {
        line := scanner.Text()
        // fmt.Println(line)

        var respObject struct {
            Status string
            Error string
        }

        err = json.Unmarshal([]byte(line), &respObject)
        if err != nil {
            return "", err
        }

        if respObject.Status != "" {
            substrs := strings.Split(respObject.Status, " ")
            if len(substrs) > 1 && substrs[0] == "Digest:" {
                digest = substrs[1]
            }
        } else if respObject.Error != "" {
            return "", errors.New(respObject.Error)
        }
    }

    if digest == "" {
        return "", errors.New("docker_driver: Error did not receive digest")
    }

    return digest, nil
}
// Pull image and return image digest
Pull image and return image digest
// Pull image and return image digest
func PullImage(image string) (digest string, err error) {
    ctx := context.Background()
    cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
    if err != nil {
        return "", err
    }
    defer cli.Close()
    resp, err := cli.ImagePull(ctx, image, types.ImagePullOptions{})
    if err != nil {
        return "", err
    }
    defer resp.Close()
    scanner := bufio.NewScanner(resp)
    for scanner.Scan() {
        line := scanner.Text()
        var respObject struct {
            Status string
            Error string
        }
        err = json.Unmarshal([]byte(line), &respObject)
        if err != nil {
            return "", err
        }
        if respObject.Status != "" {
            substrs := strings.Split(respObject.Status, " ")
            if len(substrs) > 1 && substrs[0] == "Digest:" {
                digest = substrs[1]
            }
        } else if respObject.Error != "" {
            return "", errors.New(respObject.Error)
        }
    }
    if digest == "" {
        return "", errors.New("docker_driver: Error did not receive digest")
    }
    return digest, nil
}
func PullImage ( image string ) ( digest string , err error ) { ctx := context . Background ( ) cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation ( ) ) if err != nil { return " " , err } defer cli . Close ( ) resp , err := cli . ImagePull ( ctx , image , types . ImagePullOptions { } ) if err != nil { return " " , err } defer resp . Close ( ) scanner := bufio . NewScanner ( resp ) for scanner . Scan ( ) { line := scanner . Text ( ) var respObject struct { Status string Error string } err = json . Unmarshal ( [ ] byte ( line ) , & respObject ) if err != nil { return " " , err } if respObject . Status != " " { substrs := strings . Split ( respObject . Status , " " ) if len ( substrs ) > 1 && substrs [ 0 ] == " " { digest = substrs [ 1 ] } } else if respObject . Error != " " { return " " , errors . New ( respObject . Error ) } } if digest == " " { return " " , errors . New ( " " ) } return digest , nil }
Pull image and return image digest
Pull image and return image digest
// Extract image digest from response // Possible that cli.ImageBuild() does not return an error, but we see an error from the response body // Read until EOF sent to ensure proper transfer of image // fmt.Println(line)