Commit Graph

102 Commits

Author SHA1 Message Date
Justin Chadwell
4b7016b89f snapshot: prevent duplicate calls to mount returning different values
In addition to being wasteful, without this, concurrent calls to `Mount`
would have lost the previous `target` and so would never have been
removed.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2025-12-04 11:33:42 +00:00
Sebastiaan van Stijn
8322c04df8 replace github.com/hashicorp/go-multierror with errors.Join
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 16:24:49 +02:00
Tonis Tiigi
9fcedf9807 update gopls to go1.24 compatible version
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-05-07 18:23:20 -07:00
Tonis Tiigi
f1f56c2b77 golangci-lint: v2 upgrade
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-05-02 12:19:17 -07:00
Tõnis Tiigi
7e2b28d032 Merge pull request #5885 from profnandaa/fix-5807-localmounter-race
fix: wcow: fix race condition in localmounter
2025-04-03 13:51:44 -07:00
Anthony Nandaa
b3c2303607 fix: wcow: fix race condition in localmounter
> WIP: still going on with investigation to determine
> exactly which process is accessing the file, will
> update on the issue #5807 thread for the records.

Fix the race condition with maximum 2 retries for now.
From several test runs, 1 retry seems to be
enough, even without backoff. Added a simple
linear backoff for each retry starting at 30 ms.

fixes #5807

Signed-off-by: Anthony Nandaa <profnandaa@gmail.com>
2025-04-03 22:14:57 +03:00
Jonathan A. Sternberg
66016a8c63 vendor: switch from idtools to moby/sys/user
Convert usages of `github.com/docker/docker/pkg/idtools` to
`github.com/moby/sys/user` in order to break the dependency between
buildkit and docker.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-04-02 10:22:02 -05:00
Tonis Tiigi
b5286f8dcb apply x/tools/modernize fixes
Autogenerated with couple of manual patches.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-03-07 08:18:45 -08:00
Tonis Tiigi
8244761d21 fix trace blob detected as leaked blob in tests
Trace blob is created 3 seconds after build completion.
If this happens after test has cleaned all history records
and before it checks for leaked blobs, test can report the
trace blob as leaked. In practice it would be cleaned up
next time containerd GC gets triggered.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-02-25 09:29:54 -08:00
Marat Radchenko
5be7edb69c Upgrade to containerd 2
Co-authored-by: Derek McGowan <derek@mcg.dev>
Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
2025-01-13 16:42:48 -08:00
Marat Radchenko
0a5a80cfec Remove pre-Go 1.17 build tags
Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
2024-11-21 10:58:27 +03:00
Marat Radchenko
64f4631d8b Add stub implementations to make buildkitd build for Darwin
Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
2024-09-16 12:18:36 +03:00
Marat Radchenko
c8c5024758 Cleanup Linux-isms in code
appdefaults_unix.go, constants_unix.go:
/run is a thing only for Linux. Other Unixes use /var/run.

diffapply_linux.go and source_linux.go:
These files use Linux-only API.

Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
2024-08-26 11:21:12 +03:00
Sebastiaan van Stijn
b4a189390e migrate to github.com/moby/sys/userns
Commit 4b85f11164 migrated the use of the
userns package to the github.com/moby/sys/user module.

After further discussion with maintainers, it was decided to move the
userns package to a separate module, as it has no direct relation with
"user" operations (other than having "user" in its name).

This patch migrates our code to use the new module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-08 12:36:57 +02:00
Sebastiaan van Stijn
c6745c3fdf snapshot/containerd: fix wrong errdefs package import
I noticed that we were importing the nydus errdefs package here, and
looking at [f044e0a946][1] (v0.12.0-rc1),
which introduced this import, this very likely was meant to be containerd's
errdefs package.

The only function consumed from the package is `errdefs.IsNotFound` which at
the time of the commit was not compatible with containerd's `errdefs.IsNotFound`
as it was [checking for the nydus error specifically][2].

Nydus-snapshotter v0.8.0 fixed this incompatibility by aliasing the error to
[containerd's `ErrNotFound`][3] and was updated through [483e87725e][4].

Ironically, the original commit [f044e0a946][1]
broke vendoring, because the Nydus errdefs was no longer vendored. This was
fixed in [75dd88efb8][4], but failed to notice
that the missing vendor was due to an incorrect import.

So it looks like things were broken _twice_ in the chain of events (once
because the wrong errdefs package did not match the expected error; once
because the errdefs package was missing), but all of them landed in v0.12.0-rc1,
so nothing broke in a release ':-)

This PR;

- fixes the wrong import
- adds a depguard rule to prevent accidental importing of this package

[1]: f044e0a946
[2]: f044e0a946/vendor/github.com/containerd/nydus-snapshotter/pkg/errdefs/errors.go (L22-L33)
[3]: f044e0a946/vendor/github.com/containerd/nydus-snapshotter/pkg/errdefs/errors.go (L22-L33)
[4]: 483e87725e
[5]: 75dd88efb8

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-27 02:03:48 +02:00
Sebastiaan van Stijn
86b550e427 migrate to github.com/moby/sys/user/userns
The userns package in libcontainer was integrated into the moby/sys/user
module at commit [3778ae603c706494fd1e2c2faf83b406e38d687d][1].

The userns package is used in many places, and currently either depends
on runc/libcontainer, or on containerd, both of which have a complex
dependency tree. This patch is part of a series of patches to unify the
implementations, and to migrate toward that implementation to simplify
the dependency tree.

[1]: 3778ae603c

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-25 14:11:04 +02:00
Sebastiaan van Stijn
0f89a763aa vendor: github.com/containerd/containerd v1.7.18
Update to containerd 1.7.18, which now migrated to the errdefs module. The
existing errdefs package is now an alias for the module, and should no longer
be used directly.

This patch:

- updates the containerd dependency: https://github.com/containerd/containerd/compare/v1.7.17...v1.7.18
- replaces uses of the old package in favor of the new module
- adds a linter check to prevent accidental re-introduction of the old package
- adds a linter check to enforce using an alias, to prevent accidental use
  of the errdefs package in BuildKit or Moby.
- adds a linter check to prevent using the "log" package, which was also
  migrated to a separate module.

There are still some uses of the old package in (indirect) dependencies,
which should go away over time.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-05 08:54:22 +02:00
Tonis Tiigi
265d18f2e6 lint: enable gocritic
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-05-15 16:44:38 -07:00
Tonis Tiigi
8665364c6c lint: unusedparams fixes for freebsd
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-04-09 07:23:16 -07:00
Tonis Tiigi
a07a92e157 lint: unusedparams fixes for windows
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-04-09 07:23:16 -07:00
Tonis Tiigi
1f9988911f lint: unusedparams fixes
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-04-09 07:23:16 -07:00
Akihiro Suda
3436b4d075 Merge pull request #4604 from tonistiigi/0131-fix-subpaths-mount
exec: add extra validation for submount sources
2024-02-01 06:57:02 +09:00
Tonis Tiigi
c82ace1296 exec: add extra validation for submount sources
While submount paths were already validated there are some
cases where the parent mount may not be immutable while the
submount is created.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 2529ec4121bcd8c35bcd96218083da175c2e5b77)
2024-01-31 12:39:48 -08:00
Tonis Tiigi
0c5daa2327 gateway: pass executor with build and not access worker directly
Running interactive container APIs was done by giving
the gateway implementation access to worker controller
directly, but it should be passed with a build job instead.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 0971dffaab93d91e51af984b44c745b35b3c5b4d)
2024-01-31 12:38:19 -08:00
Grégoire Payen de La Garanderie
bc646a6604 Fix hardlink issue with whiteout deletes in the merge snapshotter.
Whiteouts may share the same inode which cause the snapshotter
to attempt to create a hardlink between two whiteouts in the destination layer.

The problem is that the first whiteout is only created if it is part of the lower layer from the base snapshot.
Otherwise, the whiteout is not created in the destination layer because it is not needed.

If the first whiteout is not created in the destination, attempting to create a hardlink for the second whiteout will fail.

To avoid this issue, this fix disables hardlinks for whiteouts.

Signed-off-by: Grégoire Payen de La Garanderie <gregoire.payen.de.la.garanderie@intel.com>
2024-01-02 23:31:36 +01:00
Tonis Tiigi
8a2a3e83ec replace context.WithCancel with WithCancelCause
Keep stack traces for cancellation errors where possible.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-12-06 22:15:06 -08:00
liulanzheng
6fe2ee8a9b fix usage loss for snapshots with labels in MergeSnapshotter
Signed-off-by: liulanzheng <lanzheng.liulz@alibaba-inc.com>
2023-10-30 20:05:12 +08:00
Artem Khramov
c415d85fe0 FreeBSD port
Buildkit code is mostly generic enough to support FreeBSD, however
there are some quirks / infrastructural pieces that need to be
addressed for full support, to name some

-    contenthash.NewFromStat attempts to set Devmajor / Devminor for
    regular files, assuming that RDev is zero for regular
    files. Unlike on Linux, it's not the case for FreeBSD.

-    containerdexecutor.Run uses bind mounts for rootfs. Bind mounts
    are not supported in FreeBSD and we should use nullfs instead

-    There is no CI job to run tests on FreeBSD

-    Some dependencies weren't ported

This change ports buildkit to FreeBSD

Signed-off-by: Artem Khramov <akhramov@pm.me>
Co-authored-by: Akihiro Suda <suda.kyoto@gmail.com>
2023-07-28 17:02:53 +03:00
Gabriel Adrian Samfira
f994e78774 Add special case for rw bind mounts
In case of a rw bind mount, we return the source directly.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-06-09 09:00:03 -07:00
Gabriel Adrian Samfira
cf05c75d06 Emulate "bind" mounts using the bind filter
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-06-08 02:30:43 -07:00
Gabriel Adrian Samfira
a3328d32a4 Fix mount layers on host
Unless we're extracting an image to a layer, we should never return it
directly. We must always interact with it via a mount point, as Windows
layers hold a number of metadata files which should never be mutated
directly. When reading/manipulating the contents of a layer we should
always pass through a mount.

Allow the containerd mount.Mount() to properly mount the layer before we
interact with it.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-06-08 01:34:51 -07:00
Tonis Tiigi
f5ca0c523d remove type aliases for leasemanager/contentstore
Linter does not understand these and shows bogus warnings.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-05-11 17:56:15 -07:00
Tonis Tiigi
f044e0a946 llbsolver: move history blobs to a separate namespace
Migrate history objects to separate namespace to holding
reference to a blob does not interfer with the GC labels
held for same blobs by the containerd image store.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-05-11 17:56:12 -07:00
Alexis Murzeau
cbd1a73339 overlay: use function to check for overlay-based mounts
Factorize code that check for an overlay mount type by using a function
instead.

This will allow supporting other overlay-based mount types more easily
in the future (for example fuse-overlayfs).

Signed-off-by: Alexis Murzeau <amubtdx@gmail.com>
2023-05-02 10:41:37 +00:00
Akihiro Suda
2fed51aea3 rootless: fix up unprivileged mount opts
Port https://github.com/moby/moby/blob/v23.0.1/daemon/oci_linux.go#L430-L460

> // Get the set of mount flags that are set on the mount that contains the given
> // path and are locked by CL_UNPRIVILEGED. This is necessary to ensure that
> // bind-mounting "with options" will not fail with user namespaces, due to
> // kernel restrictions that require user namespace mounts to preserve
> // CL_UNPRIVILEGED locked flags.

Fix issue 3098

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-03-09 21:09:58 +09:00
Erik Sipsma
0a36f1afea diffapply: do chown before xattrs
Chown will result file capabilities getting reset, so it should be done
before setting xattrs to ensure they are retained.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2023-02-24 15:15:23 -08:00
Erik Sipsma
3f1cb7e0f3 Add test for merge of files with capabilities.
Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2023-02-24 15:10:04 -08:00
Justin Chadwell
99566d54af chore: refactor misc to use errors pkg
Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-11-23 12:29:27 +00:00
Kohei Tokunaga
170b2b0a57 Bump up stargz-snapshotter to v0.12.0
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2022-07-27 11:45:45 +09:00
Eng Zer Jun
be6501b654 test: use T.TempDir to create temporary test directory
This commit replaces `os.MkdirTemp` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `os.MkdirTemp`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-07-24 02:27:26 +08:00
Tõnis Tiigi
63ad264423 Merge pull request #2729 from sipsma/use-temp-lease
snapshot: use temporary lease during diffapply
2022-03-15 14:46:23 -07:00
Erik Sipsma
868f78d070 snapshot: use temporary lease during diffapply.
A temporary lease ctx was previously made during the snapshotter Merge
method but it was not passed to diffApply, which may have meant that
temporary View snapshots created there could be garbage collected by
containerd at any time.

It's possible this was encountered in CI, but I was unable to reproduce
the failure after 1000 attempts locally, so this commit is just a best
guess at the problem.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2022-03-15 13:06:21 -07:00
Sebastiaan van Stijn
21e9e9641e Remove uses of deprecated io/ioutil
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-10 00:57:07 +01:00
Erik Sipsma
53722cc4c7 diffapply: make overwritten dirs opaque.
A previous commit fixed an issue where directories that overwrite
whiteout devices needed to be set to be opaque. While that was needed,
it wasn't enough because directories also need to be set opaque if they
are overwriting anything that isn't a directory, such as a file or a
symlink. This commit updates the code to handle that situation in
general.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2022-03-08 11:37:41 -08:00
Tõnis Tiigi
e6c96c80fd Merge pull request #2651 from earthly/vlad/fix-layer-index-upstream
Eliminate auto-removal of empty layers
2022-02-25 11:35:40 -08:00
Erik Sipsma
d1e6b7d7c9 merge: disable stargz hardlinking
The stargz snapshotter creates separate FUSE mounts for each lazy
snapshot and non-FUSE mounts for newly created local snapshots. This
means that hardlinking during diffApply fails. The code then falls back
to doing a copy, which works fine, but it also results in a ton of debug
logs about the failing hardlinks to be printed. This change just results
in those noisy log lines no longer appearing.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2022-02-23 13:04:41 -08:00
Vlad A. Ionescu
d67243ed0b Fix invalid layer index error
Signed-off-by: Vlad A. Ionescu <vladaionescu@users.noreply.github.com>
2022-02-16 21:11:44 -08:00
Erik Sipsma
0a2a4fe066 diffApply: set dir opaque when overwriting whiteout
Before this, there was a bug triggered under the following conditions:
1. An overlay snapshotter was being used, which caused the optimization
   of preparing a new snapshot off of the base layers to be triggered
2. The base layers contained a directory that had contents
3. One subsequent layer deleted that directory w/out recreating it
4. A later layer recreated the directory

In this case, what happened was a whiteout device would be created as
part of 3 above but then in step 4 the whiteout device would be removed
and replaced with a plain directory. The problem is that such a
directory doesn't block out the files from step 2 and it doesn't know
about them because they are in a lowerdir (not the upperdir being
applied to).

The simplest fix, which this commit implements, is to just set the
directory created in step 4 as opaque, which enables the correct
behavior of blocking out files below it.

This was missed in test coverage before because tests for opaque
handling always combined 3+4 into one layer, whereas the bug requires
they be separate layers. A new integration test has been added to cover
this case.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2022-02-09 20:15:11 -08:00
Erik Sipsma
5c4dcb2741 cache: add support for Diff refs.
This allows you to create refs that are single layers representing the
diff between any two arbitrary refs. The primary use case for this is
to allows users to extract the changes created by ops like Exec and
rebase them elsewhere through MergeOp. However, there is no restriction
on the inputs to DiffOp and the resulting ref's layer is simply the
layer created by running the differ on the two inputs refs
(specifically, the same differ used during exports).

A Diff ref can be mounted by itself, in which case it is defined as the
result of applying the diff to Scratch. Most use cases though will use
Diff refs as the input to a MergeOp, in which case the diff is just
applied on top of the lower merge inputs, as was the case before.

In cases like Diff(A, A->B->C) (i.e. cases where the diff is between two
refs where the lower is an ancestor of upper), the diff will be defined
as the layers separating the two refs. In other cases, the diff is just
a single layer, not re-used from the inputs, representing the diff
between the two refs (which can be defined as the layer "Diff(A,B)" that
satisfies "Merge(A, Diff(A,B)) == B").

Note that there is technically a meaningful difference between the
"unmerge" behavior of extracting the layers separating diffs and the
"simple diff" of just running the differ on the two refs. Namely, in the
case where there are "intermediate deletes" (i.e. deletes that only
exist in layers between A and B but not between A and B by themselves),
then the simple diff and unmerge can create different results when
plugged into a MergeOp. This is due to the fact that intermediate
deletes will apply to the merge when using the unmerge behavior, but not
when using the simple diff. This is on top of the fact that the simple
diff inherently has a "flattening" behavior where multiple layers are
squashed into a single one.

So, in the case where lower is an ancestor of upper, we choose to follow
the unmerge behavior, but it's possible users may prefer the simple diff
behavior. As of right now, they won't be able to do so, but if needed we
can add the ability to choose which behavior is followed in the future.
This could be done through a flag provided to DiffOp or possibly by
adapting llb.Copy to support this type of behavior with the same
efficiency as DiffOp.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2022-01-06 11:05:51 -08:00
Kohei Tokunaga
bc5cfe960b Disable redirect_dir for overlayfs snapshotter
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2021-12-24 11:58:44 +09:00