Skip to content

Add Container { withMountedDirectory } - #3205

Merged
sipsma merged 8 commits into
dagger:cloakfrom
vito:container-dir-mounts
Oct 4, 2022
Merged

sipsma merged 8 commits into
dagger:cloakfrom
vito:container-dir-mounts

Conversation

@vito

@vito vito commented Sep 30, 2022 •

Copy link
Copy Markdown
Contributor

part of #3183

  • Track the exec metadata mount point (/dagger) in a separate field within ContainerID since its lifecycle differs from regular mounts
  • Add Container { withMountedDirectory } and propagate changes to mounts from parent Container to child
  • Respect sub-directory configuration within source DirectoryID
  • Make Container { stdout, stderr } nullable (same reason exitCode is nullable)
  • Allow container { from } to propagate mounts

meta isn't really like other mounts: we need to access it specifically
in exitCode/stdout/stderr, and we don't want it propagating from one
container to the next. having it separate makes most of the code
cleaner, at the cost of an extra return value from Decode.

Signed-off-by: Alex Suraci <[email protected]>
@netlify

netlify Bot commented Sep 30, 2022 •

Copy link
Copy Markdown

👷 Deploy request for cloak-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit be7ea41

@vito
vito requested review from aluzzardi, shykes and sipsma September 30, 2022 23:31
Comment thread core/container.go Resolved
vito added 2 commits October 1, 2022 11:19
this was actually fine and it failed again

This reverts commit ce678e8.

Signed-off-by: Alex Suraci <[email protected]>
* refactor away from Container.Decode and its 4 return values
* move behavior from container schema to Container model

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the container-dir-mounts branch from 24b33e2 to 52f2776 Compare October 1, 2022 18:56
vito added 2 commits October 3, 2022 11:28
linter was complaining about code being too similar, which is kind of
nonsense imo. I switched it to use a scratch directory which surfaced
some issues, so I refactored scratch directories to work more like
scratch containers and added a helper for handling a marshaled
llb.Scratch.

Signed-off-by: Alex Suraci <[email protected]>
this should probably be done everywhere, but it's a start

Signed-off-by: Alex Suraci <[email protected]>
@vito

vito commented Oct 3, 2022

Copy link
Copy Markdown
Contributor Author

@sipsma @aluzzardi @shykes This is finally ready, though it ended up with more churn than I would have liked. (One linter led to another.) I would recommend doing split diff view instead of unified. 😄

@sipsma sipsma 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.

I think we should fix the comment about amd64 in the test before merging (unless it's not actually an issue) but overall looks great!

Comment thread core/integration/container_test.go Resolved
Comment thread core/container.go

// propagate any changes to the mounts to subsequent containers
for i, mnt := range mounts {
execMountDef, err := execSt.GetMount(mnt.Target).Marshal(ctx, llb.Platform(platform))

@sipsma sipsma Oct 4, 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.

If you specify multiple mounts at the same location, I think this will not error out but you'll start getting the wrong mount here.

This gets into all the corner cases around overlapping mounts that we are just ignoring for the first iterations here, so fixing this isn't a blocker at all, but worth a followup issue.

One solution is to get the modified mount state by calling execSt.AddMount instead of GetMount, but we may want to handle this situation entirely differently, so can figure it out later.

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 see - so the issue is that we always append to containerIDPayload.Mounts which almost does what the user wants, since later ones override, but GetMount always gets the first mount from the list, i.e. the one that is going to be mounted over by the later ones.

One solution is to get the modified mount state by calling execSt.AddMount instead of GetMount, but we may want to handle this situation entirely differently, so can figure it out later.

I'm not sure I follow, but I guess another way could be to replace any mounts at or beneath the same target when adding a mount point, rather than just appending?

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'll save the fix here for after #3217 is merged since it adds a bunch of other mount APIs that'll need to be updated. Thanks for noticing it!

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.

Yeah we need to decide what we want the behavior to be in overlapping mount cases, including once we support withoutMount. My default assumption is that we just mirror the behavior of how mounts work in Linux where if you make multiple mounts over the same point then they "stack" in that if you unmount one you will reveal the one below it.

In that case, the problem is that in this loop all the mounts at a given point will be set to the same one, so if you later unmount you will no longer have the mount you were expecting.

The suggestion to use AddMount is that in LLB instead of providing mounts as run options you can also do this:

execState := llb.Image(...).Run(...)
mountA := execState.AddMount(foo, "/foo")
mountB := execState.AddMount(bar, "/bar")

in which case mountA and mountB will be the state of the mounts after the exec occurred. Basically a different way of accomplishing what GetMount accomplishes, but in such a way that I think this case of overlapping mounts will be handled.

Either way, yeah this will be important to get right someday for consistency but it's getting far beyond what we need to implement right now, saving for after #3217 sounds good to me.

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 nice, yeah that's a much cleaner fix! Just confirmed locally with a test I wrote for the other fix I attempted and it also makes it pass. I like the idea of just deferring to the platform's native mount layering semantics.

Here's the fix: 522b11f

@vito

vito commented Oct 4, 2022

Copy link
Copy Markdown
Contributor Author

@sipsma Ready for another look!

@sipsma
sipsma merged commit bb84552 into dagger:cloak Oct 4, 2022
@vito
vito deleted the container-dir-mounts branch October 4, 2022 16:31
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.

2 participants