Move image creation after unpack
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
2bc9f49ffd
commit
f0b3d5a2c5
32
client.go
32
client.go
@ -338,20 +338,29 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (Image
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imgrec := images.Image{
|
img := &image{
|
||||||
|
client: c,
|
||||||
|
i: images.Image{
|
||||||
Name: name,
|
Name: name,
|
||||||
Target: desc,
|
Target: desc,
|
||||||
Labels: pullCtx.Labels,
|
Labels: pullCtx.Labels,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if pullCtx.Unpack {
|
||||||
|
if err := img.Unpack(ctx, pullCtx.Snapshotter); err != nil {
|
||||||
|
errors.Wrapf(err, "failed to unpack image on snapshotter %s", pullCtx.Snapshotter)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is := c.ImageService()
|
is := c.ImageService()
|
||||||
for {
|
for {
|
||||||
if created, err := is.Create(ctx, imgrec); err != nil {
|
if created, err := is.Create(ctx, img.i); err != nil {
|
||||||
if !errdefs.IsAlreadyExists(err) {
|
if !errdefs.IsAlreadyExists(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
updated, err := is.Update(ctx, imgrec)
|
updated, err := is.Update(ctx, img.i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// if image was removed, try create again
|
// if image was removed, try create again
|
||||||
if errdefs.IsNotFound(err) {
|
if errdefs.IsNotFound(err) {
|
||||||
@ -360,24 +369,13 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (Image
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
imgrec = updated
|
img.i = updated
|
||||||
} else {
|
} else {
|
||||||
imgrec = created
|
img.i = created
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
img := &image{
|
|
||||||
client: c,
|
|
||||||
i: imgrec,
|
|
||||||
}
|
|
||||||
if pullCtx.Unpack {
|
|
||||||
if err := img.Unpack(ctx, pullCtx.Snapshotter); err != nil {
|
|
||||||
errors.Wrapf(err, "failed to unpack image on snapshotter %s", pullCtx.Snapshotter)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Push uploads the provided content to a remote resource
|
// Push uploads the provided content to a remote resource
|
||||||
func (c *Client) Push(ctx context.Context, ref string, desc ocispec.Descriptor, opts ...RemoteOpt) error {
|
func (c *Client) Push(ctx context.Context, ref string, desc ocispec.Descriptor, opts ...RemoteOpt) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user