Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: modify SolveOpt to take fsutil.FS objects #4094

Merged
merged 5 commits into from
Oct 23, 2023

Conversation

jedevc
Copy link
Member

@jedevc jedevc commented Aug 2, 2023

This patch modifies the function signature of the FSSync provider to take an fsutil.FS instead of a simple raw path resolved to the client's root filesystem, and follows this through to allow specifying fsutil.FS objects on the SolveOpt itself.

Internally, we were already creating an fsutil.FS to Send to the buildkit server, however, this abstraction didn't reach the session attachable parameters, so we couldn't provide our own custom FS implementation.

The rationale behind this change is to allow providing more abstract custom filesystem implementations to a BuildKit client. This way, we can start to build from filesystems that might not be on disk - for example, we could use our Static filesystem implementation in tests to prevent creating lots of temporary directories, or we could use our Merge filesystem implementation to allow easily creating variants of a single context.

@jedevc jedevc force-pushed the fsutil-fs-in-opt branch 2 times, most recently from 0de1f87 to b69a117 Compare August 8, 2023 10:52
@jedevc jedevc force-pushed the fsutil-fs-in-opt branch 2 times, most recently from 8079693 to 2dea35e Compare September 4, 2023 14:32
@jedevc jedevc marked this pull request as ready for review September 4, 2023 14:32
Copy link
Collaborator

@jsternberg jsternberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems overall good to me. Had some naming suggestions and some suggestions to put some sections into their own functions just to make the code more streamlined to read.

client/solve.go Outdated Show resolved Hide resolved
client/solve.go Outdated
Comment on lines 94 to 97
sourceFS := make(map[string]fsutil.FS)
for k, fs := range opt.LocalFiles {
sourceFS[k] = fs
}
for k, dir := range opt.LocalDirs {
fs, err := fsutil.NewFS(dir)
if err != nil {
return nil, err
}
sourceFS[k] = fs
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to move this into a function. mergeLocalX with X being the name we decide for the solve opt name. So if it's local mounts, mergeLocalMounts, createLocalMounts, or maybe just createSourceFS?

Alternatively, since LocalDirs is deprecated, maybe we shouldn't implement this merging behavior? If LocalFiles is defined, use it exclusively. If it's not, fallback on LocalDirs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to move this into a function. mergeLocalX with X being the name we decide for the solve opt name. So if it's local mounts, mergeLocalMounts, createLocalMounts, or maybe just createSourceFS?

Given this is such a short snippet and not used anywhere, I don't see the need to move it - I've annotated with a comment though.

Alternatively, since LocalDirs is deprecated, maybe we shouldn't implement this merging behavior? If LocalFiles is defined, use it exclusively. If it's not, fallback on LocalDirs.

If we're aiming to have a release in which both are supported, then the most obvious behavior to me as a user is that setting both result in both getting set. The scenarios it makes sense to choose one over the other exclusively is at the gRPC API level, when any well-behaved client cannot set both. If we're aiming to not release anything where both are set (e.g. in a follow-up removing opt.LocalDirs), then it doesn't really matter the behavior atm.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally prefer a function if it's possible. It reduces the number of live local variables, self-documents itself, and also reduces the complexity for reading the function. In isolation, this snippet may be simple. In the overall context, each small bit of reduced complexity helps someone understand the intention of the top level function. In this case, I think this behavior is inconsequential to understanding solve so it's helpful to just remove it.

exporter/local/fs.go Outdated Show resolved Hide resolved
@jedevc
Copy link
Member Author

jedevc commented Oct 1, 2023

@tonistiigi PTAL when you have a moment.

Copy link
Collaborator

@jsternberg jsternberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One recommendation but looks fine to me.

client/solve.go Outdated Show resolved Hide resolved
This patch modifies the function signature of the FSSync provider to
take an fsutil.FS instead of a simple raw path resolved to the client's
root filesystem.

Internally, we were already creating an fsutil.FS to Send to the
buildkit server, however, this abstraction didn't reach the session
attachable parameters, so we couldn't provide our own custom FS
implementation.

The rationale behind this change is to allow providing more abstract
custom filesystem implementations to a BuildKit client. This way, we can
start to build from filesystems that might not be on disk - for example,
we could use our Static filesystem implementation in tests to prevent
creating lots of temporary directories, or we could use our Merge
filesystem implementation to allow easily creating variants of a single
context.

Signed-off-by: Justin Chadwell <[email protected]>
This completes propogating the fsutil.FS abstraction into the SolveOpt,
deprecating the old LocalDirs.

Since this is entirely a golang-level abstraction, we could potentially
investigate just removing the old LocalDirs directly.

Signed-off-by: Justin Chadwell <[email protected]>
Now we error out if there is any clash between LocalDirs and
LocalMounts.

Signed-off-by: Justin Chadwell <[email protected]>
@tonistiigi tonistiigi merged commit c62e704 into moby:master Oct 23, 2023
56 checks passed
crazy-max added a commit to crazy-max/buildkit that referenced this pull request Jan 30, 2024
This reverts commit c62e704, reversing
changes made to d5c1d78.

Signed-off-by: CrazyMax <[email protected]>
crazy-max added a commit to crazy-max/buildx that referenced this pull request Jan 30, 2024
crazy-max added a commit to crazy-max/compose that referenced this pull request Jan 30, 2024
Commit 7781b7c vendoring buildx master introduced a regression
with a bump of the peer dependency github.com/tonistiigi/fsutil.
full diff: tonistiigi/fsutil@36ef4d8...f098008

When bisecting, tonistiigi/fsutil#167 is the PR introducing the
regression.

We got a similar issue reported before DD 4.27 (docker/buildx#2207)
that was fixed with tonistiigi/fsutil@master...crazy-max:fsutil:toslash-keep-gogo
but Windows users encountered another new issue also related to fsutil.

While a fix is being worked on fsutil repo to address this issue, I have
created a branch that reverts this change in fsutil.

This branch for buildkit https://github.com/crazy-max/buildkit/tree/compose-957cb50df991
has been created at the regression point and reverts moby/buildkit#4094.
Another branch for buildx https://github.com/crazy-max/buildx/tree/compose-617f538cb315
has been created as well to vendor the buildkit branch and replace
both buildkit and fsutil to the right commit.

Signed-off-by: CrazyMax <[email protected]>
crazy-max added a commit to crazy-max/compose that referenced this pull request Jan 30, 2024
Commit 7781b7c vendoring buildx master introduced a regression
with a bump of the peer dependency github.com/tonistiigi/fsutil.
full diff: tonistiigi/fsutil@36ef4d8...f098008

When bisecting, tonistiigi/fsutil#167 is the PR introducing the
regression.

We got a similar issue reported before DD 4.27 (docker/buildx#2207)
that was fixed with tonistiigi/fsutil@master...crazy-max:fsutil:toslash-keep-gogo
but Windows users encountered another new issue also related to fsutil.

While a fix is being worked on fsutil repo to address this issue, I have
created a branch that reverts this change in fsutil.

This branch for buildkit https://github.com/crazy-max/buildkit/tree/compose-957cb50df991
has been created at the regression point and reverts moby/buildkit#4094.

Signed-off-by: CrazyMax <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants