本文整理汇总了Golang中github.com/docker/engine-api/types.ImagePullOptions.RegistryAuth方法的典型用法代码示例。如果您正苦于以下问题:Golang ImagePullOptions.RegistryAuth方法的具体用法?Golang ImagePullOptions.RegistryAuth怎么用?Golang ImagePullOptions.RegistryAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/engine-api/types.ImagePullOptions
的用法示例。
在下文中一共展示了ImagePullOptions.RegistryAuth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PullImage
func (d *kubeDockerClient) PullImage(image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error {
// RegistryAuth is the base64 encoded credentials for the registry
base64Auth, err := base64EncodeAuth(auth)
if err != nil {
return err
}
opts.RegistryAuth = base64Auth
ctx, cancel := d.getCancelableContext()
defer cancel()
resp, err := d.client.ImagePull(ctx, image, opts)
if err != nil {
return err
}
defer resp.Close()
reporter := newProgressReporter(image, cancel)
reporter.start()
defer reporter.stop()
decoder := json.NewDecoder(resp)
for {
var msg dockermessage.JSONMessage
err := decoder.Decode(&msg)
if err == io.EOF {
break
}
if err != nil {
return err
}
if msg.Error != nil {
return msg.Error
}
reporter.set(&msg)
}
return nil
}
示例2: PullImage
func (d *kubeDockerClient) PullImage(image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error {
// RegistryAuth is the base64 encoded credentials for the registry
base64Auth, err := base64EncodeAuth(auth)
if err != nil {
return err
}
opts.RegistryAuth = base64Auth
// Don't set timeout for the context because image pulling can be
// take an arbitrarily long time.
resp, err := d.client.ImagePull(context.Background(), image, opts)
if err != nil {
return err
}
defer resp.Close()
reporter := newProgressReporter(image, defaultImagePullingProgressReportInterval)
reporter.start()
defer reporter.stop()
decoder := json.NewDecoder(resp)
for {
var msg dockermessage.JSONMessage
err := decoder.Decode(&msg)
if err == io.EOF {
break
}
if err != nil {
return err
}
if msg.Error != nil {
return msg.Error
}
reporter.set(&msg)
}
return nil
}
示例3: PullImage
func (d *kubeDockerClient) PullImage(image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error {
// RegistryAuth is the base64 encoded credentials for the registry
base64Auth, err := base64EncodeAuth(auth)
if err != nil {
return err
}
opts.ImageID = image
opts.RegistryAuth = base64Auth
resp, err := d.client.ImagePull(getDefaultContext(), opts, nil)
if err != nil {
return err
}
defer resp.Close()
// TODO(random-liu): Use the image pulling progress information.
decoder := json.NewDecoder(resp)
for {
var msg dockermessage.JSONMessage
err := decoder.Decode(&msg)
if err == io.EOF {
break
}
if err != nil {
return err
}
if msg.Error != nil {
return msg.Error
}
}
return nil
}
示例4: PullImage
func (d *kubeDockerClient) PullImage(image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error {
// RegistryAuth is the base64 encoded credentials for the registry
base64Auth, err := base64EncodeAuth(auth)
if err != nil {
return err
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
opts.RegistryAuth = base64Auth
resp, err := d.client.ImagePull(ctx, image, opts)
if ctxErr := contextError(ctx); ctxErr != nil {
return ctxErr
}
if err != nil {
return err
}
defer resp.Close()
// TODO(random-liu): Use the image pulling progress information.
decoder := json.NewDecoder(resp)
for {
var msg dockermessage.JSONMessage
err := decoder.Decode(&msg)
if err == io.EOF {
break
}
if err != nil {
return err
}
if msg.Error != nil {
return msg.Error
}
}
return nil
}
示例5: Spool
// Spool spools an image with a tag latest
func (b *Box) Spool(ctx context.Context, name string, opts isolate.Profile) (err error) {
profile, err := convertProfile(opts)
if err != nil {
apexctx.GetLogger(ctx).WithError(err).WithFields(log.Fields{"name": name}).Info("unbale to convert raw profile to Docker specific profile")
return err
}
if profile.Registry == "" {
apexctx.GetLogger(ctx).WithFields(log.Fields{"name": name}).Info("local image will be used")
return nil
}
defer apexctx.GetLogger(ctx).WithField("name", name).Trace("spooling an image").Stop(&err)
pullOpts := types.ImagePullOptions{
All: false,
}
if registryAuth, ok := b.config.RegistryAuth[profile.Registry]; ok {
pullOpts.RegistryAuth = registryAuth
}
ref := fmt.Sprintf("%s:%s", filepath.Join(profile.Registry, profile.Repository, name), "latest")
body, err := b.client.ImagePull(ctx, ref, pullOpts)
if err != nil {
apexctx.GetLogger(ctx).WithError(err).WithFields(
log.Fields{"name": name, "ref": ref}).Error("unable to pull an image")
return err
}
defer body.Close()
if err := decodeImagePull(ctx, body); err != nil {
return err
}
return nil
}