Browse code

update vendor

Signed-off-by: Anda Xu <anda.xu@docker.com>

Anda Xu authored on 2018/09/14 09:44:22
Showing 5 changed files
... ...
@@ -26,7 +26,7 @@ github.com/imdario/mergo v0.3.6
26 26
 golang.org/x/sync 1d60e4601c6fd243af51cc01ddf169918a5407ca
27 27
 
28 28
 # buildkit
29
-github.com/moby/buildkit a9fe50acf16dd05d1f9877b27068884543ad7a1f
29
+github.com/moby/buildkit d88354f7856a1fafef6f23bc9c5a538c246f4023
30 30
 github.com/tonistiigi/fsutil b19464cd1b6a00773b4f2eb7acf9c30426f9df42
31 31
 github.com/grpc-ecosystem/grpc-opentracing 8e809c8a86450a29b90dcc9efbf062d0fe6d9746
32 32
 github.com/opentracing/opentracing-go 1361b9cd60be79c4c3a7fa9841b3c132e40066a7
... ...
@@ -10,17 +10,17 @@ import (
10 10
 	"github.com/moby/buildkit/session"
11 11
 	"github.com/moby/buildkit/session/auth"
12 12
 	"github.com/moby/buildkit/util/contentutil"
13
-	"github.com/moby/buildkit/util/tracing"
13
+	"github.com/moby/buildkit/util/resolver"
14 14
 	specs "github.com/opencontainers/image-spec/specs-go/v1"
15 15
 	"github.com/pkg/errors"
16 16
 )
17 17
 
18
-func ResolveCacheExporterFunc(sm *session.Manager) remotecache.ResolveCacheExporterFunc {
18
+func ResolveCacheExporterFunc(sm *session.Manager, resolverOpt resolver.ResolveOptionsFunc) remotecache.ResolveCacheExporterFunc {
19 19
 	return func(ctx context.Context, typ, ref string) (remotecache.Exporter, error) {
20 20
 		if typ != "" {
21 21
 			return nil, errors.Errorf("unsupported cache exporter type: %s", typ)
22 22
 		}
23
-		remote := newRemoteResolver(ctx, sm)
23
+		remote := newRemoteResolver(ctx, resolverOpt, sm, ref)
24 24
 		pusher, err := remote.Pusher(ctx, ref)
25 25
 		if err != nil {
26 26
 			return nil, err
... ...
@@ -29,12 +29,12 @@ func ResolveCacheExporterFunc(sm *session.Manager) remotecache.ResolveCacheExpor
29 29
 	}
30 30
 }
31 31
 
32
-func ResolveCacheImporterFunc(sm *session.Manager) remotecache.ResolveCacheImporterFunc {
32
+func ResolveCacheImporterFunc(sm *session.Manager, resolverOpt resolver.ResolveOptionsFunc) remotecache.ResolveCacheImporterFunc {
33 33
 	return func(ctx context.Context, typ, ref string) (remotecache.Importer, specs.Descriptor, error) {
34 34
 		if typ != "" {
35 35
 			return nil, specs.Descriptor{}, errors.Errorf("unsupported cache importer type: %s", typ)
36 36
 		}
37
-		remote := newRemoteResolver(ctx, sm)
37
+		remote := newRemoteResolver(ctx, resolverOpt, sm, ref)
38 38
 		xref, desc, err := remote.Resolve(ctx, ref)
39 39
 		if err != nil {
40 40
 			return nil, specs.Descriptor{}, err
... ...
@@ -47,11 +47,10 @@ func ResolveCacheImporterFunc(sm *session.Manager) remotecache.ResolveCacheImpor
47 47
 	}
48 48
 }
49 49
 
50
-func newRemoteResolver(ctx context.Context, sm *session.Manager) remotes.Resolver {
51
-	return docker.NewResolver(docker.ResolverOptions{
52
-		Client:      tracing.DefaultClient,
53
-		Credentials: getCredentialsFunc(ctx, sm),
54
-	})
50
+func newRemoteResolver(ctx context.Context, resolverOpt resolver.ResolveOptionsFunc, sm *session.Manager, ref string) remotes.Resolver {
51
+	opt := resolverOpt(ref)
52
+	opt.Credentials = getCredentialsFunc(ctx, sm)
53
+	return docker.NewResolver(opt)
55 54
 }
56 55
 
57 56
 func getCredentialsFunc(ctx context.Context, sm *session.Manager) func(string) (string, string, error) {
... ...
@@ -444,6 +444,7 @@ func (j *Job) Discard() error {
444 444
 	j.pw.Close()
445 445
 
446 446
 	for k, st := range j.list.actives {
447
+		st.mu.Lock()
447 448
 		if _, ok := st.jobs[j]; ok {
448 449
 			delete(st.jobs, j)
449 450
 			j.list.deleteIfUnreferenced(k, st)
... ...
@@ -451,6 +452,7 @@ func (j *Job) Discard() error {
451 451
 		if _, ok := st.allPw[j.pw]; ok {
452 452
 			delete(st.allPw, j.pw)
453 453
 		}
454
+		st.mu.Unlock()
454 455
 	}
455 456
 	return nil
456 457
 }
457 458
new file mode 100644
... ...
@@ -0,0 +1,45 @@
0
+package resolver
1
+
2
+import (
3
+	"math/rand"
4
+
5
+	"github.com/containerd/containerd/remotes/docker"
6
+	"github.com/docker/distribution/reference"
7
+	"github.com/moby/buildkit/util/tracing"
8
+)
9
+
10
+type RegistryConf struct {
11
+	Mirrors   []string
12
+	PlainHTTP bool
13
+}
14
+
15
+type ResolveOptionsFunc func(string) docker.ResolverOptions
16
+
17
+func NewResolveOptionsFunc(m map[string]RegistryConf) ResolveOptionsFunc {
18
+	return func(ref string) docker.ResolverOptions {
19
+		def := docker.ResolverOptions{
20
+			Client: tracing.DefaultClient,
21
+		}
22
+
23
+		parsed, err := reference.ParseNormalizedNamed(ref)
24
+		if err != nil {
25
+			return def
26
+		}
27
+		host := reference.Domain(parsed)
28
+
29
+		c, ok := m[host]
30
+		if !ok {
31
+			return def
32
+		}
33
+
34
+		if len(c.Mirrors) > 0 {
35
+			def.Host = func(string) (string, error) {
36
+				return c.Mirrors[rand.Intn(len(c.Mirrors))], nil
37
+			}
38
+		}
39
+
40
+		def.PlainHTTP = c.PlainHTTP
41
+
42
+		return def
43
+	}
44
+}
... ...
@@ -39,7 +39,7 @@ golang.org/x/time f51c12702a4d776e4c1fa9b0fabab841babae631
39 39
 github.com/docker/docker 71cd53e4a197b303c6ba086bd584ffd67a884281
40 40
 github.com/pkg/profile 5b67d428864e92711fcbd2f8629456121a56d91f
41 41
 
42
-github.com/tonistiigi/fsutil b19464cd1b6a00773b4f2eb7acf9c30426f9df42
42
+github.com/tonistiigi/fsutil 7e391b0e788f9b925f22bd3cf88e0210d1643673
43 43
 github.com/hashicorp/go-immutable-radix 826af9ccf0feeee615d546d69b11f8e98da8c8f1 git://github.com/tonistiigi/go-immutable-radix.git
44 44
 github.com/hashicorp/golang-lru a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4
45 45
 github.com/mitchellh/hashstructure 2bca23e0e452137f789efbc8610126fd8b94f73b