Commit Graph

96 Commits (e6c96c80fd1dc0e77dca20e71cd0fcdd66cb17fe)

Author SHA1 Message Date
Kohei Tokunaga 3b7422996a cache: Clean up temporary mount pool on restart
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2022-02-23 16:33:25 +09:00
Erik Sipsma bb09f3c032 Improve progress output for merge+diff ops.
Now, when a merge or diff ref is unlazied, the progress will show up
under the vertex for the merge/diff ref. Additionally, any ancestors of
the op that also need to be unlazied as part of unlazying the merge/diff
will show status updates under its vertex in the progress.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2022-02-08 11:26:05 -08:00
Tonis Tiigi dc21885891 hack: enable more linters
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2022-01-19 12:20:30 -08:00
Tonis Tiigi 01e935cff5 hack: update linter to v1.43
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2022-01-19 11:48:57 -08:00
Alex Couture-Beil c55a0b888c
use newer MatchesUsingParentResults
switch to using newer MatchesUsingParentResults methods which were
introduced in https://github.com/moby/moby/pull/43037

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2021-12-08 09:41:55 -08:00
Erik Sipsma d73e62f878 Add initial MergeOp implementation.
This consists of just the base MergeOp with support for merging LLB
results that include deletions using hardlinks as the efficient path
and copies as fallback.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2021-11-18 11:10:48 -08:00
Erik Sipsma 9321ec2f82 Refactor cache record mount cache.
This is mostly just preparation for merge-op. The existing
Extract method is updated to be usable for unlazying any type of refs
rather than just lazy blobs. The way views are created is simplified and
centralized in one location.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2021-11-17 11:02:16 -08:00
CrazyMax 54b8ff2fc8
go fmt: add //go:build
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-10-28 13:26:43 +02:00
Tõnis Tiigi f5eb400a85
Merge pull request #2318 from aaronlehmann/follow-links-includedpaths
Follow links in includedPaths to resolve incorrect caching when source path is behind symlink
2021-09-08 10:43:26 -07:00
Aaron Lehmann e9e6cec838 Use getFollowLinksWalked
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-09-08 09:14:48 -07:00
Aaron Lehmann 98f54ff22c Handle the case of multiple path component symlinks (including last component) in wildcard prefix
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-09-07 16:46:00 -07:00
Aaron Lehmann ddd18de18e Add test case for symlink which is not final path component before wildcard
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-09-07 13:41:19 -07:00
Erik Sipsma a9f1980ebb Refactor cache metadata interface.
There are a few goals with this refactor:
1. Remove external access to fields that no longer make sense and/or
   won't make sense soon due to other potential changes. For example,
   there can now be multiple blobs associated with a ref (for different
   compression types), so the fact that you could access the "Blob"
   field from the Info method on Ref incorrectly implied there was just
   a single blob for the ref. This is on top of the fact that there is
   no need for external access to blob digests.
2. Centralize use of cache metadata inside the cache package.
   Previously, many parts of the code outside the cache package could
   obtain the bolt storage item for any ref and read/write it directly.
   This made it hard to understand what fields are used and when. Now,
   the Metadata method has been removed from the Ref interface and
   replaced with getters+setters for metadata fields we want to expose
   outside the package, which makes it much easier to track and
   understand. Similar changes have been made to the metadata search
   interface.
3. Use a consistent getter+setter interface for metadata, replacing
   the mix of interfaces like Metadata(), Size(), Info() and other
   inconsistencies.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2021-08-25 19:15:09 +00:00
Aaron Lehmann 8021a3e667 Use fixed fileutils matching functions
This is important for two reasons:

1) Keeps caching logic consistent with recent fsutil changes to use
   these functions (also vendored here).

2) Allows us to move forward with removal of the original buggy Matches
   implementation in moby/moby.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-08-21 11:17:09 -07:00
Aaron Lehmann 56c0981f1e Follow links in includedPaths to resolve incorrect caching when source path is behind symlink
As discussed in #2300, includedPaths does not resolve symlinks when
looking up the source path in the prefix tree. If the user requests a
path that involves symlinks (for example, /a/foo when a symlink /a -> /b
exists), includedPaths will not find it, and will expect nothing to be
copied. This does not match the actual copy behavior implemented in
fsutil, which will follow symlinks in prefix components of a given path,
so it can end up caching an empty result even though the copy will
produce a non-empty result, which is quite bad.

To fix this, use getFollowLinks to resolve the path before walking it.
In the wildcard case, this is done to the non-wildcard prefix of the
path (if any), which matches the behavior in fsutil.

Fixes the repro case here:
https://gist.github.com/aaronlehmann/64054c9a2cff0d27e200cc107bba3d69

Fixes #2300

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-08-18 11:54:48 -07:00
Aaron Lehmann de785737db Fix IncludePattern/ExcludePattern matching
The transformation to rootedPatterns seems very wrong and inconsistent
with what the copy logic did. Change it to match the copy logic, and add
more testing.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-08-10 18:14:42 -07:00
Aaron Lehmann b6ba966a68 Additional tests and cleanup for cache/contenthash
This adds a little extra testing around ** patterns, and adds a
(currently skipped) test for copying directories under symlinks (#2300).

It removes an extra call to `filepath.FromSlash` in `shouldIncludePath`
and an unused argument to that function.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-08-10 14:41:03 -07:00
Akihiro Suda 9cf28dcf26
Merge pull request #2182 from tonistiigi/seek-radix
contenthash: use SeekLowerBound to seek radix tree
2021-07-02 14:29:44 +09:00
Tõnis Tiigi f5c34a05b8
Merge pull request #2047 from thaJeztah/improve_errors
Remove duplicate "not found" from some error messages
2021-07-01 21:36:33 -07:00
Tonis Tiigi b9f8a58256 contenthash: use SeekLowerBound to seek radix tree
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-06-28 16:19:12 -07:00
Aaron Lehmann c1a48b79f8 Make error message consistent when layer is empty
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-06-26 14:08:36 -07:00
Aaron Lehmann 799175fc83 Avoid nil pointer dereference when copying from image with no layers
Fix this panic when copying from an image with no layers:

```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0xdd8c17]

goroutine 326 [running]:
github.com/moby/buildkit/cache/contenthash.(*cacheManager).Checksum(0xc0005ec030, 0x1682c00, 0xc000842140, 0x0, 0x0, 0xc0005d4023, 0x1, 0x0, 0x0, 0x0, ...)
	/src/cache/contenthash/checksum.go:95 +0x37
github.com/moby/buildkit/cache/contenthash.Checksum(0x1682c00, 0xc000842140, 0x0, 0x0, 0xc0005d4023, 0x1, 0x0, 0x0, 0x0, 0x0, ...)
	/src/cache/contenthash/checksum.go:59 +0xd5
github.com/moby/buildkit/solver/llbsolver.NewContentHashFunc.func1.1(0x0, 0x4425d6)
	/src/solver/llbsolver/result.go:59 +0x20a
golang.org/x/sync/errgroup.(*Group).Go.func1(0xc00056a360, 0xc000594510)
	/src/vendor/golang.org/x/sync/errgroup/errgroup.go:57 +0x59
created by golang.org/x/sync/errgroup.(*Group).Go
	/src/vendor/golang.org/x/sync/errgroup/errgroup.go:54 +0x66
```

When the path is "/", we allow it because it's a noop.

Based on https://github.com/moby/buildkit/pull/2185

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-06-23 12:28:18 -07:00
Aaron Lehmann 7c13af37a4 Revendor updated fsutils fork; use same logic for IncludePatterns and ExcludePatterns
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-05-26 13:48:03 -07:00
Aaron Lehmann 5f90a18501 Add test case for added file which doesn't match include pattern
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-05-26 13:48:03 -07:00
Aaron Lehmann fc20bebf5e Exclude source dir metadata from checksum if source path ends in separator
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-05-26 13:48:03 -07:00
Aaron Lehmann 607dc1f2bf return false, false, nil
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-05-26 13:48:03 -07:00
Aaron Lehmann b94fc7f4d7 Seek to path if !wildcard
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-05-26 13:48:03 -07:00
Aaron Lehmann 32e52f15bc Update vendored fsutil fork
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-05-26 13:48:03 -07:00
Aaron Lehmann 7a35420c13 Include parent directories of include patterns in cache checksum
Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-05-26 13:48:03 -07:00
Aaron Lehmann 626744c9e7 Cache awareness of IncludePatterns/ExcludePatterns
Consider IncludePatterns and ExcludePattern when calculating content
hashes.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-05-26 13:48:03 -07:00
Sebastiaan van Stijn b81b56e000
Remove duplicate "not found" from some error messages
I noticed this when building a Dockerfile that failed because a file didn't
exist, so went through error messages that looked like they had a duplicate
"not found" in the output;

    [+] Building 0.9s (6/9)
     => [internal] load build definition from Dockerfile                0.2s
     => => transferring dockerfile: 306B                                0.0s
     => [internal] load .dockerignore                                   0.1s
     => => transferring context: 2B                                     0.0s
     => [internal] load metadata for docker.io/library/alpine:latest    0.0s
     => CACHED [1/5] FROM docker.io/library/alpine                      0.0s
     => [internal] load build context                                   0.6s
     => => transferring context: 701B                                   0.5s
     => ERROR [2/5] ADD no-such-file.txt /                              0.0s
    ------
     > [2/5] ADD no-such-file.txt /:
    ------
    failed to compute cache key: "/no-such-file.txt" not found: not found

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-03-29 13:17:06 +02:00
Tonis Tiigi 1982e1e285 contenthash: include basename in content checksum for wildcards
While we generally ignore the basename in this layer, for wildcards
there in no other place to add the basename to the checksum as they
can not be resolved earlier. Before the basename that was in the
checksum was the wildcard itself, so if the wildcard remained same,
content remained same but the file where wildcard pointed to was
renamed, the cache was not invalidated.

Unfortunately, this change breaks cache for all copy commands that
use a wildcard.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-03-23 17:15:50 -07:00
Akihiro Suda 13ea18ad08
vendor containerd (requred for rootless overlayfs on kernel 5.11)
Required for rootless overlayfs on kernel 5.11
https://github.com/containerd/containerd/pull/5076

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-03-10 13:51:27 +09:00
Tonis Tiigi e3b05289d8 add session injection to remote loading
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-11-02 22:20:44 -08:00
Sebastiaan van Stijn fbe1346912
replace github.com/docker/docker/pkg/locker with moby/locker v1.0.1
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-10-30 09:25:05 +01:00
Paul "TBBle" Hampson 6c824d68f1 Use filesystem-supplied modes for checksumming content
The existing code was spuriously failing unit tests, because it was
stripping non-permission bits off the file mode.

On examination, the behaviour was inherited from similar code in
moby/moby, which was intended to affect the resulting filemodes inside
a Linux-based container built from Windows. However, this code path does
have that effect in BuildKit as we are only calculating checksums here.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2020-07-29 02:50:24 +10:00
Paul "TBBle" Hampson 46995ec794 Don't silently ignore failed wildcard expansion
This was letting mount-related errors slip by, and instead returning
an empty hash.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2020-07-29 02:50:20 +10:00
Paul "TBBle" Hampson b2d3473cba Skip tests on Windows that attempt to bind-mount read-only
Containerd's mounter doesn't yet support bind-mounts on Windows.
BuildKit short-cuts this for read-write mounts, but not read-only
mounts.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2020-07-28 18:07:20 +10:00
Tõnis Tiigi a67af5b10c
Merge pull request #1581 from alexcb/tar-exporter-with-socket-copy-reproduce-error
fix socket handling during copy
2020-07-23 12:07:15 -07:00
Alex Couture-Beil 5382a2056e Treat unix sockets as regular files
This fix is similar to the fix in #1144; but was hit in a different code
path.

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2020-07-23 11:25:48 -07:00
Tonis Tiigi 0ed9eb77ce contenthash: fix buffer reuse pool
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-07-19 09:28:36 -07:00
Tonis Tiigi 57abacc68d contenthash: avoid deprecated Xattrs header
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-07-19 09:28:36 -07:00
Tonis Tiigi c8190b1518 lint: enable golint
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-07-19 09:28:24 -07:00
Tonis Tiigi b0d3737627 contenthash: allow security.capability in cache checksum
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-06-07 22:16:56 -07:00
Tonis Tiigi 37b8832d00 upgrade errors checks to Is()
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-04-18 22:53:38 -07:00
Tonis Tiigi 81e711302a contenthash: ignore system and security xattrs in calculation
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-03-03 19:37:28 -08:00
Akihiro Suda 7b579cdb98 vendor: update containerd (and various packages)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-02-28 10:24:10 +09:00
Tonis Tiigi 31a9aeea88 cache: add migration flow to new lease based format
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2019-10-16 10:35:49 -07:00
Tonis Tiigi 08194783e0 cache: update unit tests to new cache manager constructor
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2019-10-16 10:34:50 -07:00
Tonis Tiigi 3504fae6f2 contenthash: fix symlinks with unscanned parents
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2019-08-16 15:03:14 -07:00