Skip to content

simpler Host API - #3560

Merged
vito merged 19 commits into
dagger:mainfrom
vito:dynamic-filesync
Oct 28, 2022
Merged

vito merged 19 commits into
dagger:mainfrom
vito:dynamic-filesync

Conversation

@vito

@vito vito commented Oct 26, 2022 •

Copy link
Copy Markdown
Contributor
  • copy the entire filesync implementation from BuildKit and change it to just accept direct paths instead of an allowlist of paths
  • it is no longer required to pre-configure LocalDirs
  • add Directory.export
  • remove HostDirectory
  • change Host.workdir to return a Directory
  • change Host.directory to take a path and return a Directory

New API (same as #3421):

host {
  directory(path: String!): Directory!
  workdir: Directory!
}

directory {
  export(path: String!): Boolean!
}

# container/file export not implemented yet

Note that this includes an extra README.md + NOTICE + BUILDKIT_AUTHORS file for the extracted filesync implementation to preserve copyright attribution.

MAJOR RISK: as soon as we merge this the API will have unfettered read access to the host filesystem. We should understand the implications of this for the Playground, and/or figure out how to make this more secure before merging.

@vito
vito requested review from aluzzardi, jlongtine, shykes and sipsma and removed request for aluzzardi and sipsma October 26, 2022 18:11
Comment thread engine/filesync/README.md Resolved
Comment thread core/host.go Resolved
Comment thread core/schema/directory.graphqls Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

bikeshedding: if export is on Directory, why not have import (or syncFromHost) on Directory too? e.g.

type Directory {
  ...
  # merge the contents of hostPath from the host into destPath in the directory
  syncFromHost(hostPath: String!, destPath: String!, include: [String!], exclude: [String!]) Directory!
  ...
}

Just seems more intuitive, but if you and no one else agree please ignore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

One thing to keep in mind is that we also plan to have File.export and Container.export.

Though to your point, I could see us adding File.import (load a single file into a File) and Container.import (load an OCI tarball into a Container).

@shykes @aluzzardi 🚲 🏚️ 🖌️

@vito vito Oct 27, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thought about this a bit more, I think it's OK the way it is.

This was the dealbreaker: if we were to add a Container.import that reads from the host filesystem, people wouldn't be able to import from a DirectoryID (let's say you ran nix build or something to build an OCI tarball in Dagger). But if they can import from a DirectoryID, they can also import from the host filesystem.

So it seems to me that it's an anti-goal for each object to support importing from the host filesystem, because they should ideally be reading from a DirectoryID for maximum flexibility instead.

I know this wasn't your argument, I'm just countering my own "logical conclusion." :)

Here are some supporting arguments for the current scheme:

  1. Having export on each type feels more natural than having exportX, exportY, and exportZ on the Host.
  2. Having directories be "created" from their origin is already a common pattern, e.g. Container.directory
  3. If we inverted it we might end up with Directory.fromContainer which feels like the type of pattern we're avoiding in step 1.

I don't know if I'm making sense here, there might be a better way to express it.

Comment thread core/host.go Resolved
@jlongtine

jlongtine commented Oct 26, 2022 •

Copy link
Copy Markdown
Contributor

I don't have any comments on the implementation... but I like the design (presuming we can sort out any potential security issues).

Comment thread go.mod Outdated

@sipsma sipsma Oct 27, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is going to break the automatic spin up of buildkitd I think.

I'm personally okay with moving to being based on master branch builds of buildkit, but making that switch now is going to increase the scope here of this PR. Maybe it's doable relatively quickly, but if not I don't think we should block the PR on it. We can use the copied source for now and then switch to master buildkit in a follow up.

@vito vito Oct 27, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh right - I just had to fix that code to handle replace rules, so I think I can just tweak it again to use master if the version isn't a regular semver.

edit: or maybe the exact commit sha? I'll check if they push those tags, too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The problem is that the code looks at the version of buildkit in our dependencies and then pulls the buildkit image based on that: https://github.com/sipsma/dagger/blob/ab7fba6ce6611a5eb0c279f8db42bb45b1cca11f/internal/buildkitd/buildkitd.go#L85-L85

So before it was v0.10.5 and we thus pulled moby/buildkit:v0.10.5.

There are images built from the master branch but I don't know of a way to map the commit SHA we depend on to those images. Honestly, I think I'd be okay with just hardcoding an image digest to pull for moby/buildkit and then adding a test to make sure we always keep it updated with our client. Not having to wait for official buildkit releases will resolve so many headaches (i.e. the dumb issue where running go get -u breaks the fsutil dep or this fix from May that was made for a bug encountered by a Dagger Europa user which still has not made it to us...)

I think we can then add a test that makes sure our client dependency is aligned with the server; when I currently run docker exec -it dagger-buildkitd buildctl --version I get a commit SHA, so I think we can use that in the test (since buildctl version inside that container should be the same as buildkitd).

THEN when we switch to having our own embedded buildkitd and image and all that I think this will likely all still be useful and what we want, so probably not throwaway work either.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again, this might be too much for this PR, another option is to go back to copying code for a bit, then make these changes in a follow up. I'm also happy to do that follow up too to help distribute the workload here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I came up with something that should cover all of the following cases:

  • Pointing to an unreleased version for client-only changes.
  • Pointing to an unreleased version for server changes.
  • Pointing to a fork for either of the above.

The gist of it is we'll now grab the version from replace lines too, and we just maintain a custom mapping from replaced versions to full image references, which can either be manually built ourselves or just pointed to the upstream moby/buildkit:master equivalent (but with a digest for stability).

Comment thread go.mod Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did this happen automatically?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, which is a bit spooky. I'm not sure what this will mean for the release. I decided to commit it and call it out since we're gonna run into it someday, better to see what happens.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yuck, now I get this error when trying to run tests:

core/integration/container_test.go:8:2: module dagger.io/dagger provides package dagger.io/dagger and is replaced but not required; to add it:
        go get dagger.io/dagger

Go can't seem to decide whether this dependency should exist. 🤔 Or maybe I just broke something. I'll try just adding it back and see if it disappears again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So it gets removed when I do go get github.com/moby/buildkit@master.

And then when I go get dagger.io/[email protected] to bring it back, it un-bumps github.com/moby/buildkit to v0.10.5. 😡

Probably because dagger.io/dagger ends up depending on github.com/moby/buildkit and Go actually sees v0.10.1-0.20221027014600-b78713cdd127 => v0.10.5 as a version bump. 😭

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The fix here seems to be to add this line instead:

replace github.com/moby/buildkit => github.com/moby/buildkit v0.10.1-0.20221027014600-b78713cdd127

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fix here seems to be to add this line instead:

If we do that, then I think our SDK users will also need to include that replace, right? 😢

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I just ran into that. 🤦‍♂️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It sucks, but right now I'm leaning towards just doing it since it's kind of a drop in the bucket, and it'll go away at the same time that we switch to an external engine.

Even without that replace line we'll need to update the docker/docker replace, so they'll already need to do some more copy-pasta.

The alternative of course is to go back to vendoring the filesync implementation.

@vito

vito commented Oct 28, 2022 •

Copy link
Copy Markdown
Contributor Author

@shykes @sipsma @aluzzardi This is ready to go now that there's a flag to disable host i/o, but we need to decide how to handle the Buildkit dependency bump. (Or whether to punt for now - see second option.)

Unfortunately our dependency cycle makes it impossible to simply bump our moby/buildkit dependency, because the dagger.io/dagger dependency has a transitive dependency on v0.10.5 which Go considers "newer" than an unreleased tag (v0.10.1-foo-bar). Some context here: #3560 (comment)

It doesn't seem possible to bump Buildkit without bumping it in both members of the dependency cycle at the same time, similar to the trick we pulled with the engine's dagger.io/dagger dependency.


The first option is to keep the PR as-is, meaning users will need an additional replace line to use the SDK.

diff --git a/docs/current/partials/_install-sdk-go.md b/docs/current/partials/_install-sdk-go.md
index 367add79..28e93643 100644
--- a/docs/current/partials/_install-sdk-go.md
+++ b/docs/current/partials/_install-sdk-go.md
@@ -6,7 +6,8 @@ From an existing Go module, you can install the Dagger Go SDK using the commands
 
 ```shell
 go get dagger.io/dagger@latest
-go mod edit -replace github.com/docker/docker=github.com/docker/[email protected]+incompatible
+go mod edit -replace github.com/docker/docker=github.com/docker/[email protected]+incompatible
+go mod edit -replace github.com/moby/buildkit=github.com/moby/[email protected]

Pros:

  • Lets us jump ahead to newer unreleased Buildkit versions for server-side + client-side if/when we need to.
  • The replace rule goes away when we do remote-engine.

Cons:

  • The replace rule stays even if we're able to remove the docker/docker replace, so this becomes a hard dependency on external engine.

The second option is to go back to vendoring our own filesync package, which I did in a previous commit. It just involved retaining the copyright notice + author attribution.

Pros:

  • We can kick the can down the road on bumping the Buildkit dependency.

Cons:

  • It's a bit hacky. Protobuf types have to be renamed to avoid conflicts for example.
  • Won't help us if/when we need unreleased Buildkit features. There are already some juicy things merged that it'd be nice to use.

The third option is to break the dependency cycle from the engine to the SDK. I took a swing at this and it was kinda sorta doable, but pretty messy. Here's where I stopped.

Pros:

  • Solves the root of the problem (the dependency cycle) but in the opposite direction.
  • Might be easier than external engine.

Cons:

  • Awkward duplication of code within the repo
  • Not as easy as I hoped, there may be dragons

The fourth option is to bite the bullet and prioritize external engine very soon. I'm pretty interested in pursuing this but I don't have a good idea of our current thinking regarding priorities/timeline/dependencies for this.

Pros:

  • We're pretty sure we'll want this eventually.

Cons:

  • Might disrupt existing priorities/plans.
  • Forces the issue re: multi-session or mono-session.

I'm sure I missed some pros/cons. This is also all very confusing so please ask if something seems wrong/unclear. There may be other options too.

I'm leaning towards the first option since it grants us more flexibility going forward. It's an extra replace rule, but it feels like a drop in the bucket; running two cryptic commands isn't very different from running one. It does add a hard blocker on external engine for removing the replaces, but even if Docker adopts semver we'd need to wait for a new Buildkit release that uses it.

Also good with the second option though for the sake of decoupling this PR from larger more dramatic changes. My only concern is whether we'll want either those changes or newer Buildkit version very soon anyway.

I'm going to go rest my brain.

vito added 12 commits October 28, 2022 14:08
* copy the entire filesync implementation from BuildKit and change it to
  just accept direct paths instead of an allowlist of paths
* it is no longer required to pre-configure LocalDirs
* add Directory.export
* remove HostDirectory
* change Host.workdir to return a Directory
* change Host.directory to take a path and return a Directory

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
* handle github.com/moby/buildkit replace rules in go.mod
* support mapping replaced versions to custom images

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
vito added 4 commits October 28, 2022 14:08
Signed-off-by: Alex Suraci <[email protected]>
this is the behavior for LocalDirs in upstream Buildkit, and without it
synced files end up with funky ownership that causes e.g. git commands
to fail with the following error:

  detected dubious ownership in repository at '<path>'

Signed-off-by: Alex Suraci <[email protected]>
currently untested; not totally sure how to do that yet, since exposing
it via the client doesn't seem to make sense

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the dynamic-filesync branch from b64ebd0 to c36d13e Compare October 28, 2022 18:09
@shykes

shykes commented Oct 28, 2022

Copy link
Copy Markdown
Contributor

Any update on the tradeoff here? What is everyone's opinion?

@sipsma

sipsma commented Oct 28, 2022

Copy link
Copy Markdown
Contributor

@vito Appreciate you writing this all out and being today's tour guide through dependency hell :-)

transitive dependency on v0.10.5 which Go considers "newer" than an unreleased tag (v0.10.1-foo-bar).

I'm so confused by this on so many levels. Where does "v0.10.1" even come from? Why that specific version and not any other? I tried playing around with this too a bit and just became more confused.

No response needed, I'm just agreeing that this is very frustrating.

Also good with the second option though for the sake of decoupling this PR from larger more dramatic changes. My only concern is whether we'll want either those changes or newer Buildkit version very soon anyway.

Honestly this is my vote at this immediate moment, just because having support for dynamic localdirs is a blocker on include/exclude, which is being requested a few times a day already. We can just do this for now, then safely make a decision between 1, 3 and 4 afterwards without causing any extra issues on top of what we already have to deal with (afaict, right? correct me if wrong)

We will very much just be kicking the can approximately 1 meter down the road rather than solving anything though. I just think decoupling is more important at this point.

@shykes

shykes commented Oct 28, 2022

Copy link
Copy Markdown
Contributor

Would a live call with the Buildkit / Docker devs help here, to review options? From @cpuguy83 's message on yesterday's community call, I inferred that maybe we could get some support, if we know exactly what to ask for and it's not too disruptive for the Docker community?

@shykes

shykes commented Oct 28, 2022

Copy link
Copy Markdown
Contributor

I agree with @sipsma that option 2 is the right call as an immediate next step. It doesn't solve the underlying problem, but it doesn't make it worse for our users which is important. Whatever problems it creates for us (dragons) etc are reversible.

Not a super strong opinion since I don't have full mastery of the underlying details.

@shykes

shykes commented Oct 28, 2022

Copy link
Copy Markdown
Contributor

Follow-up: big +1 on optimizing for speed on shipping this feature, even if it means kicking a bunch of cans down the road. This feature is high priority: frequently requested, and also a breaking API change which is time sensitive (earlier is better).

Thank you both for pushing this so quickly!

@vito

vito commented Oct 28, 2022

Copy link
Copy Markdown
Contributor Author

Would a live call with the Buildkit / Docker devs help here, to review options?

I don't think that's necessary, the part we're stuck on is a problem of our own that's orthogonal to the docker/docker replace issue. It's because of our own circular dependency between the engine and the SDK.

re: votes for option 2 - works for me! I'll start preparing a vendored edition instead. I too would like to just call this darn thing finished. I'll keep the work I did to support moving ahead to unreleased Buildkit versions in case we want it in the future.

@shykes shykes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Love the feature, big improvement on the API.

Only blocker is the buildkit dependency disaster, which I know is being handled in parallel. Proactively approving :)

@vito

vito commented Oct 28, 2022

Copy link
Copy Markdown
Contributor Author

@sipsma Vendored filesync and un-bumped Buildkit, ready to go!

@vito
vito merged commit 5a2a495 into dagger:main Oct 28, 2022
@shykes

shykes commented Oct 28, 2022 •

Copy link
Copy Markdown
Contributor

Nicely done. Maybe we should write a guide on local filesystem access, to celebrate the occasion? Any takers @kpenfound @mircubed @vikram-dagger @jpadams @grouville ?

Created an issue: #3593

@vikram-dagger

Copy link
Copy Markdown
Contributor

Nicely done. Maybe we should write a guide on local filesystem access, to celebrate the occasion? Any takers @kpenfound @mircubed @vikram-dagger @jpadams @grouville ?

Created an issue: #3593

I can take this one @shykes. Please lmk who I should coordinate with for technical questions. @grouville, feel free to reassign to me.

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.

5 participants