Browse code

vendor: update buildkit to 8818c67c

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2019/04/24 10:43:39
Showing 18 changed files
... ...
@@ -21,6 +21,7 @@ import (
21 21
 	"github.com/moby/buildkit/cache/metadata"
22 22
 	"github.com/moby/buildkit/cache/remotecache"
23 23
 	inlineremotecache "github.com/moby/buildkit/cache/remotecache/inline"
24
+	localremotecache "github.com/moby/buildkit/cache/remotecache/local"
24 25
 	"github.com/moby/buildkit/client"
25 26
 	"github.com/moby/buildkit/control"
26 27
 	"github.com/moby/buildkit/frontend"
... ...
@@ -186,6 +187,7 @@ func newController(rt http.RoundTripper, opt Opt) (*control.Controller, error) {
186 186
 		CacheKeyStorage:  cacheStorage,
187 187
 		ResolveCacheImporterFuncs: map[string]remotecache.ResolveCacheImporterFunc{
188 188
 			"registry": localinlinecache.ResolveCacheImporterFunc(opt.SessionManager, opt.ResolverOpt, dist.ReferenceStore, dist.ImageStore),
189
+			"local":    localremotecache.ResolveCacheImporterFunc(opt.SessionManager),
189 190
 		},
190 191
 		ResolveCacheExporterFuncs: map[string]remotecache.ResolveCacheExporterFunc{
191 192
 			"inline": inlineremotecache.ResolveCacheExporterFunc(),
... ...
@@ -27,7 +27,7 @@ github.com/imdario/mergo                            7c29201646fa3de8506f70121347
27 27
 golang.org/x/sync                                   e225da77a7e68af35c70ccbf71af2b83e6acac3c
28 28
 
29 29
 # buildkit
30
-github.com/moby/buildkit                            b3028967ae6259c9a31c1a1deeccd30fe3469cce
30
+github.com/moby/buildkit                            8818c67cff663befa7b70f21454e340f71616581
31 31
 github.com/tonistiigi/fsutil                        3bbb99cdbd76619ab717299830c60f6f2a533a6b
32 32
 github.com/grpc-ecosystem/grpc-opentracing          8e809c8a86450a29b90dcc9efbf062d0fe6d9746
33 33
 github.com/opentracing/opentracing-go               1361b9cd60be79c4c3a7fa9841b3c132e40066a7
... ...
@@ -38,7 +38,7 @@ BuildKit is used by the following projects:
38 38
 - [OpenFaaS Cloud](https://github.com/openfaas/openfaas-cloud)
39 39
 - [container build interface](https://github.com/containerbuilding/cbi)
40 40
 - [Knative Build Templates](https://github.com/knative/build-templates)
41
-- [boss](https://github.com/crosbymichael/boss)
41
+- [vab](https://github.com/stellarproject/vab)
42 42
 - [Rio](https://github.com/rancher/rio) (on roadmap)
43 43
 
44 44
 ### Quick start
... ...
@@ -100,7 +100,7 @@ To start building use `buildctl build` command. The example script accepts `--wi
100 100
 go run examples/buildkit0/buildkit.go | buildctl build
101 101
 ```
102 102
 
103
-`buildctl build` will show interactive progress bar by default while the build job is running. It will also show you the path to the trace file that contains all information about the timing of the individual steps and logs.
103
+`buildctl build` will show interactive progress bar by default while the build job is running. If the path to the trace file is specified, the trace file generated will contain all information about the timing of the individual steps and logs.
104 104
 
105 105
 Different versions of the example scripts show different ways of describing the build definition for this project to show the capabilities of the library. New versions have been added when new features have become available.
106 106
 
... ...
@@ -218,8 +218,8 @@ buildctl build ... --import-cache type=registry,ref=localhost:5000/myrepo:buildc
218 218
 #### To/From local filesystem
219 219
 
220 220
 ```
221
-buildctl build ... --export-cache type=local,src=path/to/input-dir
222
-buildctl build ... --import-cache type=local,dest=path/to/output-dir
221
+buildctl build ... --export-cache type=local,dest=path/to/output-dir
222
+buildctl build ... --import-cache type=local,src=path/to/input-dir
223 223
 ```
224 224
 
225 225
 The directory layout conforms to OCI Image Spec v1.0.
... ...
@@ -228,11 +228,11 @@ The directory layout conforms to OCI Image Spec v1.0.
228 228
 * `mode=min` (default): only export layers for the resulting image
229 229
 * `mode=max`: export all the layers of all intermediate steps
230 230
 * `ref=docker.io/user/image:tag`: reference for `registry` cache exporter
231
-* `src=path/to/output-dir`: directory for `local` cache exporter
231
+* `dest=path/to/output-dir`: directory for `local` cache exporter
232 232
 
233 233
 #### `--import-cache` options
234 234
 * `ref=docker.io/user/image:tag`: reference for `registry` cache importer
235
-* `dest=path/to/input-dir`: directory for `local` cache importer
235
+* `src=path/to/input-dir`: directory for `local` cache importer
236 236
 * `digest=sha256:deadbeef`: digest of the manifest list to import for `local` cache importer. Defaults to the digest of "latest" tag in `index.json`
237 237
 
238 238
 ### Other
... ...
@@ -271,6 +271,18 @@ buildctl build --help
271 271
 The images can be also built locally using `./hack/dockerfiles/test.Dockerfile` (or `./hack/dockerfiles/test.buildkit.Dockerfile` if you already have BuildKit).
272 272
 Run `make images` to build the images as `moby/buildkit:local` and `moby/buildkit:local-rootless`.
273 273
 
274
+#### Connection helpers
275
+
276
+If you are running `moby/buildkit:master` or `moby/buildkit:master-rootless` as a Docker/Kubernetes container, you can use special `BUILDKIT_HOST` URL for connecting to the BuildKit daemon in the container:
277
+
278
+```
279
+export BUILDKIT_HOST=docker://<container>
280
+```
281
+
282
+```
283
+export BUILDKIT_HOST=kube-pod://<pod>
284
+```
285
+
274 286
 ### Opentracing support
275 287
 
276 288
 BuildKit supports opentracing for buildkitd gRPC API and buildctl commands. To capture the trace to [Jaeger](https://github.com/jaegertracing/jaeger), set `JAEGER_TRACE` environment variable to the collection address.
277 289
new file mode 100644
... ...
@@ -0,0 +1,83 @@
0
+package local
1
+
2
+import (
3
+	"context"
4
+	"time"
5
+
6
+	"github.com/containerd/containerd/content"
7
+	"github.com/moby/buildkit/cache/remotecache"
8
+	"github.com/moby/buildkit/session"
9
+	sessioncontent "github.com/moby/buildkit/session/content"
10
+	digest "github.com/opencontainers/go-digest"
11
+	specs "github.com/opencontainers/image-spec/specs-go/v1"
12
+	"github.com/pkg/errors"
13
+)
14
+
15
+const (
16
+	attrDigest           = "digest"
17
+	attrSrc              = "src"
18
+	attrDest             = "dest"
19
+	contentStoreIDPrefix = "local:"
20
+)
21
+
22
+// ResolveCacheExporterFunc for "local" cache exporter.
23
+func ResolveCacheExporterFunc(sm *session.Manager) remotecache.ResolveCacheExporterFunc {
24
+	return func(ctx context.Context, attrs map[string]string) (remotecache.Exporter, error) {
25
+		store := attrs[attrDest]
26
+		if store == "" {
27
+			return nil, errors.New("local cache exporter requires dest")
28
+		}
29
+		csID := contentStoreIDPrefix + store
30
+		cs, err := getContentStore(ctx, sm, csID)
31
+		if err != nil {
32
+			return nil, err
33
+		}
34
+		return remotecache.NewExporter(cs), nil
35
+	}
36
+}
37
+
38
+// ResolveCacheImporterFunc for "local" cache importer.
39
+func ResolveCacheImporterFunc(sm *session.Manager) remotecache.ResolveCacheImporterFunc {
40
+	return func(ctx context.Context, attrs map[string]string) (remotecache.Importer, specs.Descriptor, error) {
41
+		dgstStr := attrs[attrDigest]
42
+		if dgstStr == "" {
43
+			return nil, specs.Descriptor{}, errors.New("local cache importer requires explicit digest")
44
+		}
45
+		dgst := digest.Digest(dgstStr)
46
+		store := attrs[attrSrc]
47
+		if store == "" {
48
+			return nil, specs.Descriptor{}, errors.New("local cache importer requires src")
49
+		}
50
+		csID := contentStoreIDPrefix + store
51
+		cs, err := getContentStore(ctx, sm, csID)
52
+		if err != nil {
53
+			return nil, specs.Descriptor{}, err
54
+		}
55
+		info, err := cs.Info(ctx, dgst)
56
+		if err != nil {
57
+			return nil, specs.Descriptor{}, err
58
+		}
59
+		desc := specs.Descriptor{
60
+			// MediaType is typically MediaTypeDockerSchema2ManifestList,
61
+			// but we leave it empty until we get correct support for local index.json
62
+			Digest: dgst,
63
+			Size:   info.Size,
64
+		}
65
+		return remotecache.NewImporter(cs), desc, nil
66
+	}
67
+}
68
+
69
+func getContentStore(ctx context.Context, sm *session.Manager, storeID string) (content.Store, error) {
70
+	sessionID := session.FromContext(ctx)
71
+	if sessionID == "" {
72
+		return nil, errors.New("local cache exporter/importer requires session")
73
+	}
74
+	timeoutCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
75
+	defer cancel()
76
+
77
+	caller, err := sm.Get(timeoutCtx, sessionID)
78
+	if err != nil {
79
+		return nil, err
80
+	}
81
+	return sessioncontent.NewCallerStore(caller, storeID), nil
82
+}
... ...
@@ -30,15 +30,17 @@ import (
30 30
 )
31 31
 
32 32
 type SolveOpt struct {
33
-	Exports             []ExportEntry
34
-	LocalDirs           map[string]string
35
-	SharedKey           string
36
-	Frontend            string
37
-	FrontendAttrs       map[string]string
38
-	CacheExports        []CacheOptionsEntry
39
-	CacheImports        []CacheOptionsEntry
40
-	Session             []session.Attachable
41
-	AllowedEntitlements []entitlements.Entitlement
33
+	Exports               []ExportEntry
34
+	LocalDirs             map[string]string
35
+	SharedKey             string
36
+	Frontend              string
37
+	FrontendAttrs         map[string]string
38
+	CacheExports          []CacheOptionsEntry
39
+	CacheImports          []CacheOptionsEntry
40
+	Session               []session.Attachable
41
+	AllowedEntitlements   []entitlements.Entitlement
42
+	SharedSession         *session.Session // TODO: refactor to better session syncing
43
+	SessionPreInitialized bool             // TODO: refactor to better session syncing
42 44
 }
43 45
 
44 46
 type ExportEntry struct {
... ...
@@ -94,68 +96,80 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG
94 94
 		statusContext = opentracing.ContextWithSpan(statusContext, span)
95 95
 	}
96 96
 
97
-	s, err := session.NewSession(statusContext, defaultSessionName(), opt.SharedKey)
98
-	if err != nil {
99
-		return nil, errors.Wrap(err, "failed to create session")
100
-	}
97
+	s := opt.SharedSession
101 98
 
102
-	if len(syncedDirs) > 0 {
103
-		s.Allow(filesync.NewFSSyncProvider(syncedDirs))
99
+	if s == nil {
100
+		if opt.SessionPreInitialized {
101
+			return nil, errors.Errorf("no session provided for preinitialized option")
102
+		}
103
+		s, err = session.NewSession(statusContext, defaultSessionName(), opt.SharedKey)
104
+		if err != nil {
105
+			return nil, errors.Wrap(err, "failed to create session")
106
+		}
104 107
 	}
105 108
 
106
-	for _, a := range opt.Session {
107
-		s.Allow(a)
109
+	cacheOpt, err := parseCacheOptions(opt)
110
+	if err != nil {
111
+		return nil, err
108 112
 	}
109 113
 
110 114
 	var ex ExportEntry
111
-	if len(opt.Exports) > 1 {
112
-		return nil, errors.New("currently only single Exports can be specified")
113
-	}
114
-	if len(opt.Exports) == 1 {
115
-		ex = opt.Exports[0]
116
-	}
117 115
 
118
-	switch ex.Type {
119
-	case ExporterLocal:
120
-		if ex.Output != nil {
121
-			return nil, errors.New("output file writer is not supported by local exporter")
116
+	if !opt.SessionPreInitialized {
117
+		if len(syncedDirs) > 0 {
118
+			s.Allow(filesync.NewFSSyncProvider(syncedDirs))
122 119
 		}
123
-		if ex.OutputDir == "" {
124
-			return nil, errors.New("output directory is required for local exporter")
120
+
121
+		for _, a := range opt.Session {
122
+			s.Allow(a)
125 123
 		}
126
-		s.Allow(filesync.NewFSSyncTargetDir(ex.OutputDir))
127
-	case ExporterOCI, ExporterDocker, ExporterTar:
128
-		if ex.OutputDir != "" {
129
-			return nil, errors.Errorf("output directory %s is not supported by %s exporter", ex.OutputDir, ex.Type)
124
+
125
+		if len(opt.Exports) > 1 {
126
+			return nil, errors.New("currently only single Exports can be specified")
130 127
 		}
131
-		if ex.Output == nil {
132
-			return nil, errors.Errorf("output file writer is required for %s exporter", ex.Type)
128
+		if len(opt.Exports) == 1 {
129
+			ex = opt.Exports[0]
133 130
 		}
134
-		s.Allow(filesync.NewFSSyncTarget(ex.Output))
135
-	default:
136
-		if ex.Output != nil {
137
-			return nil, errors.Errorf("output file writer is not supported by %s exporter", ex.Type)
131
+
132
+		switch ex.Type {
133
+		case ExporterLocal:
134
+			if ex.Output != nil {
135
+				return nil, errors.New("output file writer is not supported by local exporter")
136
+			}
137
+			if ex.OutputDir == "" {
138
+				return nil, errors.New("output directory is required for local exporter")
139
+			}
140
+			s.Allow(filesync.NewFSSyncTargetDir(ex.OutputDir))
141
+		case ExporterOCI, ExporterDocker, ExporterTar:
142
+			if ex.OutputDir != "" {
143
+				return nil, errors.Errorf("output directory %s is not supported by %s exporter", ex.OutputDir, ex.Type)
144
+			}
145
+			if ex.Output == nil {
146
+				return nil, errors.Errorf("output file writer is required for %s exporter", ex.Type)
147
+			}
148
+			s.Allow(filesync.NewFSSyncTarget(ex.Output))
149
+		default:
150
+			if ex.Output != nil {
151
+				return nil, errors.Errorf("output file writer is not supported by %s exporter", ex.Type)
152
+			}
153
+			if ex.OutputDir != "" {
154
+				return nil, errors.Errorf("output directory %s is not supported by %s exporter", ex.OutputDir, ex.Type)
155
+			}
138 156
 		}
139
-		if ex.OutputDir != "" {
140
-			return nil, errors.Errorf("output directory %s is not supported by %s exporter", ex.OutputDir, ex.Type)
157
+
158
+		if len(cacheOpt.contentStores) > 0 {
159
+			s.Allow(sessioncontent.NewAttachable(cacheOpt.contentStores))
141 160
 		}
142
-	}
143 161
 
144
-	cacheOpt, err := parseCacheOptions(opt)
145
-	if err != nil {
146
-		return nil, err
147
-	}
148
-	if len(cacheOpt.contentStores) > 0 {
149
-		s.Allow(sessioncontent.NewAttachable(cacheOpt.contentStores))
162
+		eg.Go(func() error {
163
+			return s.Run(statusContext, grpchijack.Dialer(c.controlClient()))
164
+		})
150 165
 	}
166
+
151 167
 	for k, v := range cacheOpt.frontendAttrs {
152 168
 		opt.FrontendAttrs[k] = v
153 169
 	}
154 170
 
155
-	eg.Go(func() error {
156
-		return s.Run(statusContext, grpchijack.Dialer(c.controlClient()))
157
-	})
158
-
159 171
 	solveCtx, cancelSolve := context.WithCancel(ctx)
160 172
 	var res *SolveResponse
161 173
 	eg.Go(func() error {
... ...
@@ -20,6 +20,7 @@ import (
20 20
 	"github.com/moby/buildkit/frontend/dockerfile/dockerfile2llb"
21 21
 	"github.com/moby/buildkit/frontend/gateway/client"
22 22
 	"github.com/moby/buildkit/solver/pb"
23
+	"github.com/moby/buildkit/util/apicaps"
23 24
 	specs "github.com/opencontainers/image-spec/specs-go/v1"
24 25
 	"github.com/pkg/errors"
25 26
 	"golang.org/x/sync/errgroup"
... ...
@@ -61,8 +62,10 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
61 61
 		localNameContext = v
62 62
 	}
63 63
 
64
+	forceLocalDockerfile := false
64 65
 	localNameDockerfile := DefaultLocalNameDockerfile
65 66
 	if v, ok := opts[keyNameDockerfile]; ok {
67
+		forceLocalDockerfile = true
66 68
 		localNameDockerfile = v
67 69
 	}
68 70
 
... ...
@@ -118,11 +121,14 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
118 118
 		llb.SharedKeyHint(localNameDockerfile),
119 119
 		dockerfile2llb.WithInternalName(name),
120 120
 	)
121
+
121 122
 	var buildContext *llb.State
122 123
 	isScratchContext := false
123 124
 	if st, ok := detectGitContext(opts[localNameContext]); ok {
124
-		src = *st
125
-		buildContext = &src
125
+		if !forceLocalDockerfile {
126
+			src = *st
127
+		}
128
+		buildContext = st
126 129
 	} else if httpPrefix.MatchString(opts[localNameContext]) {
127 130
 		httpContext := llb.HTTP(opts[localNameContext], llb.Filename("context"), dockerfile2llb.WithInternalName("load remote build context"))
128 131
 		def, err := httpContext.Marshal(marshalOpts...)
... ...
@@ -151,19 +157,35 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
151 151
 			return nil, errors.Errorf("failed to read downloaded context")
152 152
 		}
153 153
 		if isArchive(dt) {
154
-			copyImage := opts[keyOverrideCopyImage]
155
-			if copyImage == "" {
156
-				copyImage = dockerfile2llb.DefaultCopyImage
154
+			fileop := useFileOp(opts, &caps)
155
+			if fileop {
156
+				bc := llb.Scratch().File(llb.Copy(httpContext, "/context", "/", &llb.CopyInfo{
157
+					AttemptUnpack: true,
158
+				}))
159
+				if !forceLocalDockerfile {
160
+					src = bc
161
+				}
162
+				buildContext = &bc
163
+			} else {
164
+				copyImage := opts[keyOverrideCopyImage]
165
+				if copyImage == "" {
166
+					copyImage = dockerfile2llb.DefaultCopyImage
167
+				}
168
+				unpack := llb.Image(copyImage, dockerfile2llb.WithInternalName("helper image for file operations")).
169
+					Run(llb.Shlex("copy --unpack /src/context /out/"), llb.ReadonlyRootFS(), dockerfile2llb.WithInternalName("extracting build context"))
170
+				unpack.AddMount("/src", httpContext, llb.Readonly)
171
+				bc := unpack.AddMount("/out", llb.Scratch())
172
+				if !forceLocalDockerfile {
173
+					src = bc
174
+				}
175
+				buildContext = &bc
157 176
 			}
158
-			unpack := llb.Image(copyImage, dockerfile2llb.WithInternalName("helper image for file operations")).
159
-				Run(llb.Shlex("copy --unpack /src/context /out/"), llb.ReadonlyRootFS(), dockerfile2llb.WithInternalName("extracting build context"))
160
-			unpack.AddMount("/src", httpContext, llb.Readonly)
161
-			src = unpack.AddMount("/out", llb.Scratch())
162
-			buildContext = &src
163 177
 		} else {
164 178
 			filename = "context"
165
-			src = httpContext
166
-			buildContext = &src
179
+			if !forceLocalDockerfile {
180
+				src = httpContext
181
+			}
182
+			buildContext = &httpContext
167 183
 			isScratchContext = true
168 184
 		}
169 185
 	}
... ...
@@ -529,3 +551,13 @@ func parseNetMode(v string) (pb.NetMode, error) {
529 529
 		return 0, errors.Errorf("invalid netmode %s", v)
530 530
 	}
531 531
 }
532
+
533
+func useFileOp(args map[string]string, caps *apicaps.CapSet) bool {
534
+	enabled := true
535
+	if v, ok := args["build-arg:BUILDKIT_DISABLE_FILEOP"]; ok {
536
+		if b, err := strconv.ParseBool(v); err == nil {
537
+			enabled = !b
538
+		}
539
+	}
540
+	return enabled && caps != nil && caps.Supports(pb.CapFileBase) == nil
541
+}
... ...
@@ -390,6 +390,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
390 390
 	if !platformOpt.implicitTarget {
391 391
 		target.image.OS = platformOpt.targetPlatform.OS
392 392
 		target.image.Architecture = platformOpt.targetPlatform.Architecture
393
+		target.image.Variant = platformOpt.targetPlatform.Variant
393 394
 	}
394 395
 
395 396
 	return &st, &target.image, nil
... ...
@@ -50,6 +50,9 @@ type Image struct {
50 50
 
51 51
 	// Config defines the execution parameters which should be used as a base when running a container using the image.
52 52
 	Config ImageConfig `json:"config,omitempty"`
53
+
54
+	// Variant defines platform variant. To be added to OCI.
55
+	Variant string `json:"variant,omitempty"`
53 56
 }
54 57
 
55 58
 func clone(src Image) Image {
... ...
@@ -67,6 +70,7 @@ func emptyImage(platform specs.Platform) Image {
67 67
 			Architecture: platform.Architecture,
68 68
 			OS:           platform.OS,
69 69
 		},
70
+		Variant: platform.Variant,
70 71
 	}
71 72
 	img.RootFS.Type = "layers"
72 73
 	img.Config.WorkingDir = "/"
... ...
@@ -200,6 +200,11 @@ type CopyCommand struct {
200 200
 
201 201
 // Expand variables
202 202
 func (c *CopyCommand) Expand(expander SingleWordExpander) error {
203
+	expandedChown, err := expander(c.Chown)
204
+	if err != nil {
205
+		return err
206
+	}
207
+	c.Chown = expandedChown
203 208
 	return expandSliceInPlace(c.SourcesAndDest, expander)
204 209
 }
205 210
 
206 211
new file mode 100644
... ...
@@ -0,0 +1,3 @@
0
+package upload
1
+
2
+//go:generate protoc --gogoslick_out=plugins=grpc:. upload.proto
0 3
new file mode 100644
... ...
@@ -0,0 +1,55 @@
0
+package upload
1
+
2
+import (
3
+	"context"
4
+	io "io"
5
+	"net/url"
6
+
7
+	"github.com/moby/buildkit/session"
8
+	"google.golang.org/grpc/metadata"
9
+)
10
+
11
+const (
12
+	keyPath = "urlpath"
13
+	keyHost = "urlhost"
14
+)
15
+
16
+func New(ctx context.Context, c session.Caller, url *url.URL) (*Upload, error) {
17
+	opts := map[string][]string{
18
+		keyPath: {url.Path},
19
+		keyHost: {url.Host},
20
+	}
21
+
22
+	client := NewUploadClient(c.Conn())
23
+
24
+	ctx = metadata.NewOutgoingContext(ctx, opts)
25
+
26
+	cc, err := client.Pull(ctx)
27
+	if err != nil {
28
+		return nil, err
29
+	}
30
+
31
+	return &Upload{cc: cc}, nil
32
+}
33
+
34
+type Upload struct {
35
+	cc Upload_PullClient
36
+}
37
+
38
+func (u *Upload) WriteTo(w io.Writer) (int, error) {
39
+	n := 0
40
+	for {
41
+		var bm BytesMessage
42
+		if err := u.cc.RecvMsg(&bm); err != nil {
43
+			if err == io.EOF {
44
+				return n, nil
45
+			}
46
+			return n, err
47
+		}
48
+		nn, err := w.Write(bm.Data)
49
+		n += nn
50
+		if err != nil {
51
+			return n, err
52
+		}
53
+	}
54
+}
0 55
new file mode 100644
... ...
@@ -0,0 +1,506 @@
0
+// Code generated by protoc-gen-gogo. DO NOT EDIT.
1
+// source: upload.proto
2
+
3
+package upload
4
+
5
+import proto "github.com/gogo/protobuf/proto"
6
+import fmt "fmt"
7
+import math "math"
8
+
9
+import bytes "bytes"
10
+
11
+import strings "strings"
12
+import reflect "reflect"
13
+
14
+import (
15
+	context "golang.org/x/net/context"
16
+	grpc "google.golang.org/grpc"
17
+)
18
+
19
+import io "io"
20
+
21
+// Reference imports to suppress errors if they are not otherwise used.
22
+var _ = proto.Marshal
23
+var _ = fmt.Errorf
24
+var _ = math.Inf
25
+
26
+// This is a compile-time assertion to ensure that this generated file
27
+// is compatible with the proto package it is being compiled against.
28
+// A compilation error at this line likely means your copy of the
29
+// proto package needs to be updated.
30
+const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
31
+
32
+// BytesMessage contains a chunk of byte data
33
+type BytesMessage struct {
34
+	Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
35
+}
36
+
37
+func (m *BytesMessage) Reset()      { *m = BytesMessage{} }
38
+func (*BytesMessage) ProtoMessage() {}
39
+func (*BytesMessage) Descriptor() ([]byte, []int) {
40
+	return fileDescriptor_upload_0898dc79ebc86e9c, []int{0}
41
+}
42
+func (m *BytesMessage) XXX_Unmarshal(b []byte) error {
43
+	return m.Unmarshal(b)
44
+}
45
+func (m *BytesMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
46
+	if deterministic {
47
+		return xxx_messageInfo_BytesMessage.Marshal(b, m, deterministic)
48
+	} else {
49
+		b = b[:cap(b)]
50
+		n, err := m.MarshalTo(b)
51
+		if err != nil {
52
+			return nil, err
53
+		}
54
+		return b[:n], nil
55
+	}
56
+}
57
+func (dst *BytesMessage) XXX_Merge(src proto.Message) {
58
+	xxx_messageInfo_BytesMessage.Merge(dst, src)
59
+}
60
+func (m *BytesMessage) XXX_Size() int {
61
+	return m.Size()
62
+}
63
+func (m *BytesMessage) XXX_DiscardUnknown() {
64
+	xxx_messageInfo_BytesMessage.DiscardUnknown(m)
65
+}
66
+
67
+var xxx_messageInfo_BytesMessage proto.InternalMessageInfo
68
+
69
+func (m *BytesMessage) GetData() []byte {
70
+	if m != nil {
71
+		return m.Data
72
+	}
73
+	return nil
74
+}
75
+
76
+func init() {
77
+	proto.RegisterType((*BytesMessage)(nil), "moby.upload.v1.BytesMessage")
78
+}
79
+func (this *BytesMessage) Equal(that interface{}) bool {
80
+	if that == nil {
81
+		return this == nil
82
+	}
83
+
84
+	that1, ok := that.(*BytesMessage)
85
+	if !ok {
86
+		that2, ok := that.(BytesMessage)
87
+		if ok {
88
+			that1 = &that2
89
+		} else {
90
+			return false
91
+		}
92
+	}
93
+	if that1 == nil {
94
+		return this == nil
95
+	} else if this == nil {
96
+		return false
97
+	}
98
+	if !bytes.Equal(this.Data, that1.Data) {
99
+		return false
100
+	}
101
+	return true
102
+}
103
+func (this *BytesMessage) GoString() string {
104
+	if this == nil {
105
+		return "nil"
106
+	}
107
+	s := make([]string, 0, 5)
108
+	s = append(s, "&upload.BytesMessage{")
109
+	s = append(s, "Data: "+fmt.Sprintf("%#v", this.Data)+",\n")
110
+	s = append(s, "}")
111
+	return strings.Join(s, "")
112
+}
113
+func valueToGoStringUpload(v interface{}, typ string) string {
114
+	rv := reflect.ValueOf(v)
115
+	if rv.IsNil() {
116
+		return "nil"
117
+	}
118
+	pv := reflect.Indirect(rv).Interface()
119
+	return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv)
120
+}
121
+
122
+// Reference imports to suppress errors if they are not otherwise used.
123
+var _ context.Context
124
+var _ grpc.ClientConn
125
+
126
+// This is a compile-time assertion to ensure that this generated file
127
+// is compatible with the grpc package it is being compiled against.
128
+const _ = grpc.SupportPackageIsVersion4
129
+
130
+// UploadClient is the client API for Upload service.
131
+//
132
+// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
133
+type UploadClient interface {
134
+	Pull(ctx context.Context, opts ...grpc.CallOption) (Upload_PullClient, error)
135
+}
136
+
137
+type uploadClient struct {
138
+	cc *grpc.ClientConn
139
+}
140
+
141
+func NewUploadClient(cc *grpc.ClientConn) UploadClient {
142
+	return &uploadClient{cc}
143
+}
144
+
145
+func (c *uploadClient) Pull(ctx context.Context, opts ...grpc.CallOption) (Upload_PullClient, error) {
146
+	stream, err := c.cc.NewStream(ctx, &_Upload_serviceDesc.Streams[0], "/moby.upload.v1.Upload/Pull", opts...)
147
+	if err != nil {
148
+		return nil, err
149
+	}
150
+	x := &uploadPullClient{stream}
151
+	return x, nil
152
+}
153
+
154
+type Upload_PullClient interface {
155
+	Send(*BytesMessage) error
156
+	Recv() (*BytesMessage, error)
157
+	grpc.ClientStream
158
+}
159
+
160
+type uploadPullClient struct {
161
+	grpc.ClientStream
162
+}
163
+
164
+func (x *uploadPullClient) Send(m *BytesMessage) error {
165
+	return x.ClientStream.SendMsg(m)
166
+}
167
+
168
+func (x *uploadPullClient) Recv() (*BytesMessage, error) {
169
+	m := new(BytesMessage)
170
+	if err := x.ClientStream.RecvMsg(m); err != nil {
171
+		return nil, err
172
+	}
173
+	return m, nil
174
+}
175
+
176
+// UploadServer is the server API for Upload service.
177
+type UploadServer interface {
178
+	Pull(Upload_PullServer) error
179
+}
180
+
181
+func RegisterUploadServer(s *grpc.Server, srv UploadServer) {
182
+	s.RegisterService(&_Upload_serviceDesc, srv)
183
+}
184
+
185
+func _Upload_Pull_Handler(srv interface{}, stream grpc.ServerStream) error {
186
+	return srv.(UploadServer).Pull(&uploadPullServer{stream})
187
+}
188
+
189
+type Upload_PullServer interface {
190
+	Send(*BytesMessage) error
191
+	Recv() (*BytesMessage, error)
192
+	grpc.ServerStream
193
+}
194
+
195
+type uploadPullServer struct {
196
+	grpc.ServerStream
197
+}
198
+
199
+func (x *uploadPullServer) Send(m *BytesMessage) error {
200
+	return x.ServerStream.SendMsg(m)
201
+}
202
+
203
+func (x *uploadPullServer) Recv() (*BytesMessage, error) {
204
+	m := new(BytesMessage)
205
+	if err := x.ServerStream.RecvMsg(m); err != nil {
206
+		return nil, err
207
+	}
208
+	return m, nil
209
+}
210
+
211
+var _Upload_serviceDesc = grpc.ServiceDesc{
212
+	ServiceName: "moby.upload.v1.Upload",
213
+	HandlerType: (*UploadServer)(nil),
214
+	Methods:     []grpc.MethodDesc{},
215
+	Streams: []grpc.StreamDesc{
216
+		{
217
+			StreamName:    "Pull",
218
+			Handler:       _Upload_Pull_Handler,
219
+			ServerStreams: true,
220
+			ClientStreams: true,
221
+		},
222
+	},
223
+	Metadata: "upload.proto",
224
+}
225
+
226
+func (m *BytesMessage) Marshal() (dAtA []byte, err error) {
227
+	size := m.Size()
228
+	dAtA = make([]byte, size)
229
+	n, err := m.MarshalTo(dAtA)
230
+	if err != nil {
231
+		return nil, err
232
+	}
233
+	return dAtA[:n], nil
234
+}
235
+
236
+func (m *BytesMessage) MarshalTo(dAtA []byte) (int, error) {
237
+	var i int
238
+	_ = i
239
+	var l int
240
+	_ = l
241
+	if len(m.Data) > 0 {
242
+		dAtA[i] = 0xa
243
+		i++
244
+		i = encodeVarintUpload(dAtA, i, uint64(len(m.Data)))
245
+		i += copy(dAtA[i:], m.Data)
246
+	}
247
+	return i, nil
248
+}
249
+
250
+func encodeVarintUpload(dAtA []byte, offset int, v uint64) int {
251
+	for v >= 1<<7 {
252
+		dAtA[offset] = uint8(v&0x7f | 0x80)
253
+		v >>= 7
254
+		offset++
255
+	}
256
+	dAtA[offset] = uint8(v)
257
+	return offset + 1
258
+}
259
+func (m *BytesMessage) Size() (n int) {
260
+	if m == nil {
261
+		return 0
262
+	}
263
+	var l int
264
+	_ = l
265
+	l = len(m.Data)
266
+	if l > 0 {
267
+		n += 1 + l + sovUpload(uint64(l))
268
+	}
269
+	return n
270
+}
271
+
272
+func sovUpload(x uint64) (n int) {
273
+	for {
274
+		n++
275
+		x >>= 7
276
+		if x == 0 {
277
+			break
278
+		}
279
+	}
280
+	return n
281
+}
282
+func sozUpload(x uint64) (n int) {
283
+	return sovUpload(uint64((x << 1) ^ uint64((int64(x) >> 63))))
284
+}
285
+func (this *BytesMessage) String() string {
286
+	if this == nil {
287
+		return "nil"
288
+	}
289
+	s := strings.Join([]string{`&BytesMessage{`,
290
+		`Data:` + fmt.Sprintf("%v", this.Data) + `,`,
291
+		`}`,
292
+	}, "")
293
+	return s
294
+}
295
+func valueToStringUpload(v interface{}) string {
296
+	rv := reflect.ValueOf(v)
297
+	if rv.IsNil() {
298
+		return "nil"
299
+	}
300
+	pv := reflect.Indirect(rv).Interface()
301
+	return fmt.Sprintf("*%v", pv)
302
+}
303
+func (m *BytesMessage) Unmarshal(dAtA []byte) error {
304
+	l := len(dAtA)
305
+	iNdEx := 0
306
+	for iNdEx < l {
307
+		preIndex := iNdEx
308
+		var wire uint64
309
+		for shift := uint(0); ; shift += 7 {
310
+			if shift >= 64 {
311
+				return ErrIntOverflowUpload
312
+			}
313
+			if iNdEx >= l {
314
+				return io.ErrUnexpectedEOF
315
+			}
316
+			b := dAtA[iNdEx]
317
+			iNdEx++
318
+			wire |= (uint64(b) & 0x7F) << shift
319
+			if b < 0x80 {
320
+				break
321
+			}
322
+		}
323
+		fieldNum := int32(wire >> 3)
324
+		wireType := int(wire & 0x7)
325
+		if wireType == 4 {
326
+			return fmt.Errorf("proto: BytesMessage: wiretype end group for non-group")
327
+		}
328
+		if fieldNum <= 0 {
329
+			return fmt.Errorf("proto: BytesMessage: illegal tag %d (wire type %d)", fieldNum, wire)
330
+		}
331
+		switch fieldNum {
332
+		case 1:
333
+			if wireType != 2 {
334
+				return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType)
335
+			}
336
+			var byteLen int
337
+			for shift := uint(0); ; shift += 7 {
338
+				if shift >= 64 {
339
+					return ErrIntOverflowUpload
340
+				}
341
+				if iNdEx >= l {
342
+					return io.ErrUnexpectedEOF
343
+				}
344
+				b := dAtA[iNdEx]
345
+				iNdEx++
346
+				byteLen |= (int(b) & 0x7F) << shift
347
+				if b < 0x80 {
348
+					break
349
+				}
350
+			}
351
+			if byteLen < 0 {
352
+				return ErrInvalidLengthUpload
353
+			}
354
+			postIndex := iNdEx + byteLen
355
+			if postIndex > l {
356
+				return io.ErrUnexpectedEOF
357
+			}
358
+			m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...)
359
+			if m.Data == nil {
360
+				m.Data = []byte{}
361
+			}
362
+			iNdEx = postIndex
363
+		default:
364
+			iNdEx = preIndex
365
+			skippy, err := skipUpload(dAtA[iNdEx:])
366
+			if err != nil {
367
+				return err
368
+			}
369
+			if skippy < 0 {
370
+				return ErrInvalidLengthUpload
371
+			}
372
+			if (iNdEx + skippy) > l {
373
+				return io.ErrUnexpectedEOF
374
+			}
375
+			iNdEx += skippy
376
+		}
377
+	}
378
+
379
+	if iNdEx > l {
380
+		return io.ErrUnexpectedEOF
381
+	}
382
+	return nil
383
+}
384
+func skipUpload(dAtA []byte) (n int, err error) {
385
+	l := len(dAtA)
386
+	iNdEx := 0
387
+	for iNdEx < l {
388
+		var wire uint64
389
+		for shift := uint(0); ; shift += 7 {
390
+			if shift >= 64 {
391
+				return 0, ErrIntOverflowUpload
392
+			}
393
+			if iNdEx >= l {
394
+				return 0, io.ErrUnexpectedEOF
395
+			}
396
+			b := dAtA[iNdEx]
397
+			iNdEx++
398
+			wire |= (uint64(b) & 0x7F) << shift
399
+			if b < 0x80 {
400
+				break
401
+			}
402
+		}
403
+		wireType := int(wire & 0x7)
404
+		switch wireType {
405
+		case 0:
406
+			for shift := uint(0); ; shift += 7 {
407
+				if shift >= 64 {
408
+					return 0, ErrIntOverflowUpload
409
+				}
410
+				if iNdEx >= l {
411
+					return 0, io.ErrUnexpectedEOF
412
+				}
413
+				iNdEx++
414
+				if dAtA[iNdEx-1] < 0x80 {
415
+					break
416
+				}
417
+			}
418
+			return iNdEx, nil
419
+		case 1:
420
+			iNdEx += 8
421
+			return iNdEx, nil
422
+		case 2:
423
+			var length int
424
+			for shift := uint(0); ; shift += 7 {
425
+				if shift >= 64 {
426
+					return 0, ErrIntOverflowUpload
427
+				}
428
+				if iNdEx >= l {
429
+					return 0, io.ErrUnexpectedEOF
430
+				}
431
+				b := dAtA[iNdEx]
432
+				iNdEx++
433
+				length |= (int(b) & 0x7F) << shift
434
+				if b < 0x80 {
435
+					break
436
+				}
437
+			}
438
+			iNdEx += length
439
+			if length < 0 {
440
+				return 0, ErrInvalidLengthUpload
441
+			}
442
+			return iNdEx, nil
443
+		case 3:
444
+			for {
445
+				var innerWire uint64
446
+				var start int = iNdEx
447
+				for shift := uint(0); ; shift += 7 {
448
+					if shift >= 64 {
449
+						return 0, ErrIntOverflowUpload
450
+					}
451
+					if iNdEx >= l {
452
+						return 0, io.ErrUnexpectedEOF
453
+					}
454
+					b := dAtA[iNdEx]
455
+					iNdEx++
456
+					innerWire |= (uint64(b) & 0x7F) << shift
457
+					if b < 0x80 {
458
+						break
459
+					}
460
+				}
461
+				innerWireType := int(innerWire & 0x7)
462
+				if innerWireType == 4 {
463
+					break
464
+				}
465
+				next, err := skipUpload(dAtA[start:])
466
+				if err != nil {
467
+					return 0, err
468
+				}
469
+				iNdEx = start + next
470
+			}
471
+			return iNdEx, nil
472
+		case 4:
473
+			return iNdEx, nil
474
+		case 5:
475
+			iNdEx += 4
476
+			return iNdEx, nil
477
+		default:
478
+			return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
479
+		}
480
+	}
481
+	panic("unreachable")
482
+}
483
+
484
+var (
485
+	ErrInvalidLengthUpload = fmt.Errorf("proto: negative length found during unmarshaling")
486
+	ErrIntOverflowUpload   = fmt.Errorf("proto: integer overflow")
487
+)
488
+
489
+func init() { proto.RegisterFile("upload.proto", fileDescriptor_upload_0898dc79ebc86e9c) }
490
+
491
+var fileDescriptor_upload_0898dc79ebc86e9c = []byte{
492
+	// 179 bytes of a gzipped FileDescriptorProto
493
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x2d, 0xc8, 0xc9,
494
+	0x4f, 0x4c, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0xcb, 0xcd, 0x4f, 0xaa, 0xd4, 0x83,
495
+	0x0a, 0x95, 0x19, 0x2a, 0x29, 0x71, 0xf1, 0x38, 0x55, 0x96, 0xa4, 0x16, 0xfb, 0xa6, 0x16, 0x17,
496
+	0x27, 0xa6, 0xa7, 0x0a, 0x09, 0x71, 0xb1, 0xa4, 0x24, 0x96, 0x24, 0x4a, 0x30, 0x2a, 0x30, 0x6a,
497
+	0xf0, 0x04, 0x81, 0xd9, 0x46, 0x01, 0x5c, 0x6c, 0xa1, 0x60, 0x0d, 0x42, 0x6e, 0x5c, 0x2c, 0x01,
498
+	0xa5, 0x39, 0x39, 0x42, 0x32, 0x7a, 0xa8, 0xc6, 0xe8, 0x21, 0x9b, 0x21, 0x85, 0x57, 0x56, 0x83,
499
+	0xd1, 0x80, 0xd1, 0xc9, 0xe6, 0xc2, 0x43, 0x39, 0x86, 0x1b, 0x0f, 0xe5, 0x18, 0x3e, 0x3c, 0x94,
500
+	0x63, 0x6c, 0x78, 0x24, 0xc7, 0xb8, 0xe2, 0x91, 0x1c, 0xe3, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e,
501
+	0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0xf8, 0xe2, 0x91, 0x1c, 0xc3, 0x87, 0x47, 0x72, 0x8c, 0x13,
502
+	0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x14, 0x1b, 0xc4, 0xc4,
503
+	0x24, 0x36, 0xb0, 0x57, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x12, 0xf2, 0xfc, 0xb4, 0xda,
504
+	0x00, 0x00, 0x00,
505
+}
0 506
new file mode 100644
... ...
@@ -0,0 +1,14 @@
0
+syntax = "proto3";
1
+
2
+package moby.upload.v1;
3
+
4
+option go_package = "upload";
5
+
6
+service Upload {
7
+	rpc Pull(stream BytesMessage) returns (stream BytesMessage);
8
+}
9
+
10
+// BytesMessage contains a chunk of byte data
11
+message BytesMessage{
12
+	bytes data = 1;
13
+}
... ...
@@ -176,14 +176,16 @@ func (lcm *lazyCacheManager) ID() string {
176 176
 	return lcm.id
177 177
 }
178 178
 func (lcm *lazyCacheManager) Query(inp []solver.CacheKeyWithSelector, inputIndex solver.Index, dgst digest.Digest, outputIndex solver.Index) ([]*solver.CacheKey, error) {
179
-	if err := lcm.wait(); err != nil {
180
-		return nil, err
179
+	lcm.wait()
180
+	if lcm.main == nil {
181
+		return nil, nil
181 182
 	}
182 183
 	return lcm.main.Query(inp, inputIndex, dgst, outputIndex)
183 184
 }
184 185
 func (lcm *lazyCacheManager) Records(ck *solver.CacheKey) ([]*solver.CacheRecord, error) {
185
-	if err := lcm.wait(); err != nil {
186
-		return nil, err
186
+	lcm.wait()
187
+	if lcm.main == nil {
188
+		return nil, nil
187 189
 	}
188 190
 	return lcm.main.Records(ck)
189 191
 }
... ...
@@ -14,7 +14,6 @@ import (
14 14
 	"github.com/moby/buildkit/exporter/containerimage/exptypes"
15 15
 	"github.com/moby/buildkit/frontend"
16 16
 	"github.com/moby/buildkit/frontend/gateway"
17
-	"github.com/moby/buildkit/identity"
18 17
 	"github.com/moby/buildkit/session"
19 18
 	"github.com/moby/buildkit/solver"
20 19
 	"github.com/moby/buildkit/util/entitlements"
... ...
@@ -306,7 +305,7 @@ func oneOffProgress(ctx context.Context, id string) func(err error) error {
306 306
 
307 307
 func inVertexContext(ctx context.Context, name, id string, f func(ctx context.Context) error) error {
308 308
 	if id == "" {
309
-		id = identity.NewID()
309
+		id = name
310 310
 	}
311 311
 	v := client.Vertex{
312 312
 		Digest: digest.FromBytes([]byte(id)),
... ...
@@ -35,10 +35,10 @@ type Opt struct {
35 35
 }
36 36
 
37 37
 type httpSource struct {
38
-	md     *metadata.Store
39
-	cache  cache.Accessor
40
-	locker *locker.Locker
41
-	client *http.Client
38
+	md        *metadata.Store
39
+	cache     cache.Accessor
40
+	locker    *locker.Locker
41
+	transport http.RoundTripper
42 42
 }
43 43
 
44 44
 func NewSource(opt Opt) (source.Source, error) {
... ...
@@ -47,12 +47,10 @@ func NewSource(opt Opt) (source.Source, error) {
47 47
 		transport = tracing.DefaultTransport
48 48
 	}
49 49
 	hs := &httpSource{
50
-		md:     opt.MetadataStore,
51
-		cache:  opt.CacheAccessor,
52
-		locker: locker.New(),
53
-		client: &http.Client{
54
-			Transport: transport,
55
-		},
50
+		md:        opt.MetadataStore,
51
+		cache:     opt.CacheAccessor,
52
+		locker:    locker.New(),
53
+		transport: transport,
56 54
 	}
57 55
 	return hs, nil
58 56
 }
... ...
@@ -66,17 +64,21 @@ type httpSourceHandler struct {
66 66
 	src      source.HttpIdentifier
67 67
 	refID    string
68 68
 	cacheKey digest.Digest
69
+	client   *http.Client
69 70
 }
70 71
 
71
-func (hs *httpSource) Resolve(ctx context.Context, id source.Identifier, _ *session.Manager) (source.SourceInstance, error) {
72
+func (hs *httpSource) Resolve(ctx context.Context, id source.Identifier, sm *session.Manager) (source.SourceInstance, error) {
72 73
 	httpIdentifier, ok := id.(*source.HttpIdentifier)
73 74
 	if !ok {
74 75
 		return nil, errors.Errorf("invalid http identifier %v", id)
75 76
 	}
76 77
 
78
+	sessionID := session.FromContext(ctx)
79
+
77 80
 	return &httpSourceHandler{
78 81
 		src:        *httpIdentifier,
79 82
 		httpSource: hs,
83
+		client:     &http.Client{Transport: newTransport(hs.transport, sm, sessionID)},
80 84
 	}, nil
81 85
 }
82 86
 
83 87
new file mode 100644
... ...
@@ -0,0 +1,60 @@
0
+package http
1
+
2
+import (
3
+	"context"
4
+	"io"
5
+	"net/http"
6
+	"time"
7
+
8
+	"github.com/moby/buildkit/session"
9
+	"github.com/moby/buildkit/session/upload"
10
+	"github.com/pkg/errors"
11
+)
12
+
13
+func newTransport(rt http.RoundTripper, sm *session.Manager, id string) http.RoundTripper {
14
+	return &sessionHandler{rt: rt, sm: sm, id: id}
15
+}
16
+
17
+type sessionHandler struct {
18
+	sm *session.Manager
19
+	rt http.RoundTripper
20
+	id string
21
+}
22
+
23
+func (h *sessionHandler) RoundTrip(req *http.Request) (*http.Response, error) {
24
+	if req.URL.Host != "buildkit-session" {
25
+		return h.rt.RoundTrip(req)
26
+	}
27
+
28
+	if req.Method != "GET" {
29
+		return nil, errors.Errorf("invalid request")
30
+	}
31
+
32
+	timeoutCtx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
33
+	defer cancel()
34
+
35
+	caller, err := h.sm.Get(timeoutCtx, h.id)
36
+	if err != nil {
37
+		return nil, err
38
+	}
39
+
40
+	up, err := upload.New(context.TODO(), caller, req.URL)
41
+	if err != nil {
42
+		return nil, err
43
+	}
44
+
45
+	pr, pw := io.Pipe()
46
+	go func() {
47
+		_, err := up.WriteTo(pw)
48
+		pw.CloseWithError(err)
49
+	}()
50
+
51
+	resp := &http.Response{
52
+		Status:        "200 OK",
53
+		StatusCode:    200,
54
+		Body:          pr,
55
+		ContentLength: -1,
56
+	}
57
+
58
+	return resp, nil
59
+}
... ...
@@ -13,7 +13,7 @@ var arr []string
13 13
 
14 14
 func SupportedPlatforms() []string {
15 15
 	once.Do(func() {
16
-		def := platforms.DefaultString()
16
+		def := defaultPlatform()
17 17
 		arr = append(arr, def)
18 18
 		if p := "linux/amd64"; def != p && amd64Supported() == nil {
19 19
 			arr = append(arr, p)
... ...
@@ -34,7 +34,7 @@ func SupportedPlatforms() []string {
34 34
 //the end user could fix the issue based on those warning, and thus no need to drop
35 35
 //the platform from the candidates.
36 36
 func WarnIfUnsupported(pfs []string) {
37
-	def := platforms.DefaultString()
37
+	def := defaultPlatform()
38 38
 	for _, p := range pfs {
39 39
 		if p != def {
40 40
 			if p == "linux/amd64" {
... ...
@@ -56,6 +56,10 @@ func WarnIfUnsupported(pfs []string) {
56 56
 	}
57 57
 }
58 58
 
59
+func defaultPlatform() string {
60
+	return platforms.Format(platforms.Normalize(platforms.DefaultSpec()))
61
+}
62
+
59 63
 func printPlatfromWarning(p string, err error) {
60 64
 	if strings.Contains(err.Error(), "exec format error") {
61 65
 		logrus.Warnf("platform %s cannot pass the validation, kernel support for miscellaneous binary may have not enabled.", p)