Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
| ... | ... |
@@ -1,7 +1,10 @@ |
| 1 | 1 |
package fscache |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "archive/tar" |
|
| 5 |
+ "crypto/sha256" |
|
| 4 | 6 |
"encoding/json" |
| 7 |
+ "hash" |
|
| 5 | 8 |
"os" |
| 6 | 9 |
"path/filepath" |
| 7 | 10 |
"sort" |
| ... | ... |
@@ -11,8 +14,10 @@ import ( |
| 11 | 11 |
"github.com/boltdb/bolt" |
| 12 | 12 |
"github.com/docker/docker/builder" |
| 13 | 13 |
"github.com/docker/docker/builder/remotecontext" |
| 14 |
+ "github.com/docker/docker/pkg/archive" |
|
| 14 | 15 |
"github.com/docker/docker/pkg/directory" |
| 15 | 16 |
"github.com/docker/docker/pkg/stringid" |
| 17 |
+ "github.com/docker/docker/pkg/tarsum" |
|
| 16 | 18 |
"github.com/moby/buildkit/session/filesync" |
| 17 | 19 |
"github.com/pkg/errors" |
| 18 | 20 |
"github.com/sirupsen/logrus" |
| ... | ... |
@@ -578,6 +583,10 @@ func (dc *detectChanges) MarkSupported(v bool) {
|
| 578 | 578 |
dc.supported = v |
| 579 | 579 |
} |
| 580 | 580 |
|
| 581 |
+func (dc *detectChanges) ContentHasher() fsutil.ContentHasher {
|
|
| 582 |
+ return newTarsumHash |
|
| 583 |
+} |
|
| 584 |
+ |
|
| 581 | 585 |
type wrappedContext struct {
|
| 582 | 586 |
builder.Source |
| 583 | 587 |
closer func() error |
| ... | ... |
@@ -607,3 +616,40 @@ func (s sortableCacheSources) Less(i, j int) bool {
|
| 607 | 607 |
func (s sortableCacheSources) Swap(i, j int) {
|
| 608 | 608 |
s[i], s[j] = s[j], s[i] |
| 609 | 609 |
} |
| 610 |
+ |
|
| 611 |
+func newTarsumHash(stat *fsutil.Stat) (hash.Hash, error) {
|
|
| 612 |
+ fi := &fsutil.StatInfo{stat}
|
|
| 613 |
+ p := stat.Path |
|
| 614 |
+ if fi.IsDir() {
|
|
| 615 |
+ p += string(os.PathSeparator) |
|
| 616 |
+ } |
|
| 617 |
+ h, err := archive.FileInfoHeader(p, fi, stat.Linkname) |
|
| 618 |
+ if err != nil {
|
|
| 619 |
+ return nil, err |
|
| 620 |
+ } |
|
| 621 |
+ h.Name = p |
|
| 622 |
+ h.Uid = int(stat.Uid) |
|
| 623 |
+ h.Gid = int(stat.Gid) |
|
| 624 |
+ h.Linkname = stat.Linkname |
|
| 625 |
+ if stat.Xattrs != nil {
|
|
| 626 |
+ h.Xattrs = make(map[string]string) |
|
| 627 |
+ for k, v := range stat.Xattrs {
|
|
| 628 |
+ h.Xattrs[k] = string(v) |
|
| 629 |
+ } |
|
| 630 |
+ } |
|
| 631 |
+ |
|
| 632 |
+ tsh := &tarsumHash{h: h, Hash: sha256.New()}
|
|
| 633 |
+ tsh.Reset() |
|
| 634 |
+ return tsh, nil |
|
| 635 |
+} |
|
| 636 |
+ |
|
| 637 |
+// Reset resets the Hash to its initial state. |
|
| 638 |
+func (tsh *tarsumHash) Reset() {
|
|
| 639 |
+ tsh.Hash.Reset() |
|
| 640 |
+ tarsum.WriteV1Header(tsh.h, tsh.Hash) |
|
| 641 |
+} |
|
| 642 |
+ |
|
| 643 |
+type tarsumHash struct {
|
|
| 644 |
+ hash.Hash |
|
| 645 |
+ h *tar.Header |
|
| 646 |
+} |
| ... | ... |
@@ -5,15 +5,15 @@ import ( |
| 5 | 5 |
"os" |
| 6 | 6 |
"sync" |
| 7 | 7 |
|
| 8 |
- iradix "github.com/hashicorp/go-immutable-radix" |
|
| 9 |
- |
|
| 10 | 8 |
"github.com/docker/docker/pkg/containerfs" |
| 9 |
+ iradix "github.com/hashicorp/go-immutable-radix" |
|
| 10 |
+ digest "github.com/opencontainers/go-digest" |
|
| 11 | 11 |
"github.com/pkg/errors" |
| 12 | 12 |
"github.com/tonistiigi/fsutil" |
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 | 15 |
type hashed interface {
|
| 16 |
- Hash() string |
|
| 16 |
+ Digest() digest.Digest |
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
// CachableSource is a source that contains cache records for its contents |
| ... | ... |
@@ -110,7 +110,7 @@ func (cs *CachableSource) HandleChange(kind fsutil.ChangeKind, p string, fi os.F |
| 110 | 110 |
} |
| 111 | 111 |
|
| 112 | 112 |
hfi := &fileInfo{
|
| 113 |
- sum: h.Hash(), |
|
| 113 |
+ sum: h.Digest().Hex(), |
|
| 114 | 114 |
} |
| 115 | 115 |
cs.txn.Insert([]byte(p), hfi) |
| 116 | 116 |
cs.mu.Unlock() |
| ... | ... |
@@ -586,7 +586,9 @@ func testBuildWithSession(c *check.C, dir, dockerfile string) (outStr string) {
|
| 586 | 586 |
sess, err := session.NewSession("foo1", "foo")
|
| 587 | 587 |
assert.Nil(c, err) |
| 588 | 588 |
|
| 589 |
- fsProvider := filesync.NewFSSyncProvider(dir, nil) |
|
| 589 |
+ fsProvider := filesync.NewFSSyncProvider([]filesync.SyncedDir{
|
|
| 590 |
+ {Dir: dir},
|
|
| 591 |
+ }) |
|
| 590 | 592 |
sess.Allow(fsProvider) |
| 591 | 593 |
|
| 592 | 594 |
g, ctx := errgroup.WithContext(context.Background()) |
| ... | ... |
@@ -596,7 +598,7 @@ func testBuildWithSession(c *check.C, dir, dockerfile string) (outStr string) {
|
| 596 | 596 |
}) |
| 597 | 597 |
|
| 598 | 598 |
g.Go(func() error {
|
| 599 |
- res, body, err := request.Post("/build?remote=client-session&session="+sess.UUID(), func(req *http.Request) error {
|
|
| 599 |
+ res, body, err := request.Post("/build?remote=client-session&session="+sess.ID(), func(req *http.Request) error {
|
|
| 600 | 600 |
req.Body = ioutil.NopCloser(strings.NewReader(dockerfile)) |
| 601 | 601 |
return nil |
| 602 | 602 |
}) |
| ... | ... |
@@ -27,7 +27,7 @@ github.com/imdario/mergo 0.2.1 |
| 27 | 27 |
golang.org/x/sync de49d9dcd27d4f764488181bea099dfe6179bcf0 |
| 28 | 28 |
|
| 29 | 29 |
github.com/containerd/continuity 22694c680ee48fb8f50015b44618517e2bde77e8 |
| 30 |
-github.com/moby/buildkit c2dbdeb457ea665699a5d97f79eebfac4ab4726f https://github.com/tonistiigi/buildkit.git |
|
| 30 |
+github.com/moby/buildkit aaff9d591ef128560018433fe61beb802e149de8 |
|
| 31 | 31 |
github.com/tonistiigi/fsutil 1dedf6e90084bd88c4c518a15e68a37ed1370203 |
| 32 | 32 |
|
| 33 | 33 |
#get libnetwork packages |