Skip to content

Commit 7169fd2

Browse files
committed
[pull]: when you pull an image it is added to the image store
closes #37 Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
1 parent d87fd73 commit 7169fd2

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

pull.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func createSouceManager() (*source.Manager, *fuse.Server, error) {
117117
ContentStore: opt.ContentStore,
118118
Applier: opt.Applier,
119119
CacheAccessor: cm,
120+
Images: opt.ImageStore,
120121
})
121122
if err != nil {
122123
return nil, fuseserver, err

pull_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

3-
import "testing"
3+
import (
4+
"strings"
5+
"testing"
6+
)
47

58
func TestPullFromDefaultRegistry(t *testing.T) {
69
// Test a user repo on docker hub.
@@ -16,3 +19,13 @@ func TestPullOfficialImage(t *testing.T) {
1619
// Test an official image,
1720
run(t, "pull", "alpine")
1821
}
22+
23+
func TestPullIsInListOutput(t *testing.T) {
24+
// Test an official image,
25+
run(t, "pull", "busybox")
26+
27+
out := run(t, "ls")
28+
if !strings.Contains(out, "busybox:latest") {
29+
t.Fatalf("expected busybox:latest in ls output, got: %s", out)
30+
}
31+
}

source/containerimage/pull.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/containerd/containerd/content"
1010
"github.com/containerd/containerd/diff"
11+
"github.com/containerd/containerd/errdefs"
1112
"github.com/containerd/containerd/images"
1213
"github.com/containerd/containerd/platforms"
1314
"github.com/containerd/containerd/remotes"
@@ -35,6 +36,7 @@ type SourceOpt struct {
3536
ContentStore content.Store
3637
Applier diff.Applier
3738
CacheAccessor cache.Accessor
39+
Images images.Store
3840
}
3941

4042
type imageSource struct {
@@ -102,6 +104,7 @@ func (is *imageSource) Resolve(ctx context.Context, id source.Identifier) (sourc
102104
src: imageIdentifier,
103105
is: is,
104106
resolver: is.getResolver(ctx),
107+
images: is.Images,
105108
}
106109
return p, nil
107110
}
@@ -114,6 +117,7 @@ type puller struct {
114117
ref string
115118
resolveErr error
116119
resolver remotes.Resolver
120+
images images.Store
117121
}
118122

119123
func (p *puller) resolve(ctx context.Context) error {
@@ -147,7 +151,30 @@ func (p *puller) resolve(ctx context.Context) error {
147151
}
148152
p.desc = desc
149153
p.ref = ref
154+
155+
// Add to the image store.
156+
if p.images == nil {
157+
p.resolveErr = errors.New("image store is nil")
158+
}
159+
160+
// Update the target image. Create it if it does not exist.
161+
img := images.Image{
162+
Name: p.ref,
163+
Target: p.desc,
164+
CreatedAt: time.Now(),
165+
}
166+
if _, err := p.images.Update(ctx, img); err != nil {
167+
if !errdefs.IsNotFound(err) {
168+
p.resolveErr = fmt.Errorf("updating image store for image %s failed: %v", p.ref, err)
169+
}
170+
171+
logrus.Debugf("Creating new tag: %s", p.ref)
172+
if _, err := p.images.Create(ctx, img); err != nil {
173+
p.resolveErr = fmt.Errorf("creating image %s in image store failed: %v", p.ref, err)
174+
}
175+
}
150176
})
177+
151178
return p.resolveErr
152179
}
153180

worker/runc/worker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func NewWorker(opt base.WorkerOpt, localDirs map[string]string) (*Worker, error)
6969
ContentStore: opt.ContentStore,
7070
Applier: opt.Applier,
7171
CacheAccessor: cm,
72+
Images: opt.ImageStore,
7273
})
7374
if err != nil {
7475
return nil, err

0 commit comments

Comments
 (0)