Skip to content

Commit

Permalink
Move image creation after unpack
Browse files Browse the repository at this point in the history
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
  • Loading branch information
dmcgowan committed May 7, 2018
1 parent 2bc9f49 commit f0b3d5a
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions client.go
Expand Up @@ -338,20 +338,29 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (Image
}
}

imgrec := images.Image{
Name: name,
Target: desc,
Labels: pullCtx.Labels,
img := &image{
client: c,
i: images.Image{
Name: name,
Target: desc,
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()
for {
if created, err := is.Create(ctx, imgrec); err != nil {
if created, err := is.Create(ctx, img.i); err != nil {
if !errdefs.IsAlreadyExists(err) {
return nil, err
}

updated, err := is.Update(ctx, imgrec)
updated, err := is.Update(ctx, img.i)
if err != nil {
// if image was removed, try create again
if errdefs.IsNotFound(err) {
Expand All @@ -360,23 +369,12 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (Image
return nil, err
}

imgrec = updated
img.i = updated
} else {
imgrec = 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)
img.i = created
}
return img, nil
}
return img, nil
}

// Push uploads the provided content to a remote resource
Expand Down

0 comments on commit f0b3d5a

Please sign in to comment.