Fix race in ctr pull
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
e017143dde
commit
f701b3b960
@ -61,19 +61,19 @@ Most of this is experimental and there are few leaps to make this work.`,
|
|||||||
var (
|
var (
|
||||||
ref = clicontext.Args().First()
|
ref = clicontext.Args().First()
|
||||||
)
|
)
|
||||||
_, err := Fetch(ref, clicontext)
|
client, ctx, cancel, err := commands.NewClient(clicontext)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
_, err = Fetch(ctx, client, ref, clicontext)
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch loads all resources into the content store and returns the image
|
// Fetch loads all resources into the content store and returns the image
|
||||||
func Fetch(ref string, cliContext *cli.Context) (containerd.Image, error) {
|
func Fetch(ctx context.Context, client *containerd.Client, ref string, cliContext *cli.Context) (containerd.Image, error) {
|
||||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
resolver, err := commands.GetResolver(ctx, cliContext)
|
resolver, err := commands.GetResolver(ctx, cliContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -57,10 +57,20 @@ command. As part of this process, we do the following:
|
|||||||
if ref == "" {
|
if ref == "" {
|
||||||
return fmt.Errorf("please provide an image reference to pull")
|
return fmt.Errorf("please provide an image reference to pull")
|
||||||
}
|
}
|
||||||
ctx, cancel := commands.AppContext(context)
|
|
||||||
|
client, ctx, cancel, err := commands.NewClient(context)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
img, err := content.Fetch(ref, context)
|
ctx, done, err := client.WithLease(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer done(ctx)
|
||||||
|
|
||||||
|
img, err := content.Fetch(ctx, client, ref, context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user