Repository navigation
Container: add various mount-related APIs - #3217
Conversation
👷 Deploy request for cloak-docs pending review.Visit the deploys page to approve it
|
0da0e44 to
53a8996
Compare
afe7437 to
bc25e26
Compare
522b11f to
afa5bfc
Compare
There was a problem hiding this comment.
Okay so for this current iteration we are just forcing use of this cache ID, and then is the idea we'll make a follow up where we support the whole CacheVolume idea discussed in discord?
I'm wondering if we should add this initial intermediate version or go right to the CacheVolume idea (with the simple implementation option you mentioned in terms of just joining keys together, not all the possible things we could layer on top). I guess it's backwards compatible in that we can change withMountedCache to optionally accept an ID in the future; this implementation would just be the fallback.
But the downside is the known fragility of using the container ID as cache ID. I don't think this would ever really work as expected if your container has source code in it (every change to source would invalidate the cache), so I'm kind of leaning toward just skipping this implementation and going right to the CacheVolume one. That one isn't perfect either but I suspect more useful.
Feel free to disagree though, no obvious answer. cc @shykes @aluzzardi
There was a problem hiding this comment.
I agree that we don't want to ship this as-is, but I don't want to figure out that API as part of this PR as there's already quite a lot tied into it, and some of it unblocks later things (I have a secrets branch based on this one). I could just remove this implementation, I only kept it because it's one of the earlier commits I made and I forgot about it. 😅
For CacheVolume are we thinking something like this? (Planning to open an issue, so getting some details early.)
scalar CacheID
extend type Query {
cache(id: CacheID!): CacheVolume! # for consistency
# for generating an ID (better word than tokens welcome)
cacheFromTokens(tokens: [String!]!): CacheVolume!
}
type CacheVolume {
id: CacheID!
# maybe more fieldslater?
}
extend type Container {
withMountedCache(path: String!, id: CacheID!, source: DirectoryID): Container!
}Not opinionated about names/etc., just trying to get an idea of the general shape.
There was a problem hiding this comment.
Yeah I think that's basically what I was imagining in terms of API.
I don't think it's worth creating rebasing nightmares by removing this commit as long as we get the newer api in before preview, which seems pretty doable? If we don't though then we should just hide this API from users probably. Either way, doesn't have to block this PR imo
There was a problem hiding this comment.
I may have missed a fix for this in the later commits, but this seems like it will remove all the mounts at a given point rather than just the top one. Popping the top one off the stack would be a closer match to the behavior of Linux mounts (but it's certainly up for debate whether we should exactly follow that, it's just the source of my own intuition).
There was a problem hiding this comment.
Yeah my initial implementation didn't have the stacking semantics in mind. Will tweak this and add a test.
There was a problem hiding this comment.
We can't grab directories from tmpfs or cache mounts, so I think we should check that case and have a clean error.
I guess technically we could find a way to implement that for cache mounts, but it would be really complicated and not worth it imo. tmpfs mounts are completely impossible though afaik.
There was a problem hiding this comment.
should do path.Clean on dir, just to try handling weird inputs like ../../../ and such. It's not really a security concern in our case I guess, just more for consistency.
Same for mnt.Target.
Also, we need to be consistent in whether dir is an absolute path or not. If it's a relative path, I guess it should be relative to the workingdir of the container (or / if we don't have that yet).
There was a problem hiding this comment.
Good catch!
I think we can just make every path relative to the container's workdir. I'll apply this to mount targets when they're added, and anywhere else that references a path.
Being honest, I think it's a little weird to do things like ../ with the API, but it's consistent with supporting relative paths, and as you said there aren't really security concerns here.
There was a problem hiding this comment.
Being honest, I think it's a little weird to do things like ../ with the API
Agreed, I don't think I'd ever recommend anyone do that, but it's probably right to allow it for obscure cases that actually do call for it for whatever reason.
There was a problem hiding this comment.
If you provide a dir that doesn't exist, this won't fail, right? It would only fail at some later time when you tried to do something with the Directory.
If so: it's tempting to add a check here that the dir actually exists (via gateway ReadDir or similar). There technically is a downside to that in that it will cause some buildkit refs to be "unlazied" (i.e. buildkit defers pulling an image until its really needed locally, same for calculating mergeops).
I'm inclined to not care about that performance optimization at the moment because the surprise factor of the error messages you might later get if the dir provided here doesn't exist is probably quite high.
There was a problem hiding this comment.
There are some nightmare-inducing corner cases involving symlinks here I think (double check my thinking though). I'm inclined to not care about them right now because I'm not sure users will, but they are worth being aware of:
- Rootfs has a symlink
/link -> /target - Use our api to put a mount at
/link/mnt. This should result in the mount really being at/target/mntduring exec ops (I think buildkit handles that via runc/containerd). So your code will see that/target/mnt/diris a valid, existing directory (and may output it to stdout). - Call this api with
directory(dir: "/target/mnt/dir")and you will not find the dir you may have been expecting because the mount was created with the API at/link, not/target. You may get some entirely different dir.
Like I said, my hope is that these cases are so obscure we don't have to care about them right now, but I could be wrong (people have gotten to this level of detail when asking about buildkit+dockerfiles). The only possible solutions are too complicated to be worth it right now I think. Bringing it up anyways in case anyone thinks of any related issues that are less obscure and more immediately pressing.
There was a problem hiding this comment.
Oh yeah hm that sounds annoying.
It's really tempting to just say "don't do that." In general I would expect the reader of the GraphQL API query to be able to recognize what directory(dir) is trying to access, i.e. a previously configured mount. It's strange to me to say "mount this at X but then read it from Y" in one API call.
But we'll have to see. Users always have the best surprises.
There was a problem hiding this comment.
Yeah totally, I do think the risk is gonna be increased when users are getting Container returned from other extensions, so they don't see the full chain and original mount paths. But still likely obscure enough to not care right now. I made an issue so we don't forget about it, but not high priority: #3269
|
@sipsma Thanks for the excellent review! I think my latest changes address all the feedback. I left the current super-flawed caching implementation in place since other tests use it to cover cross-mount-type behavior, and I think it'll be easier to just fix it up in another PR as soon as we figure out the API details. |
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]>
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]>
* mount targets are made absolute at creation time
* container { directory } resolves its path relative to workdir
* container { withWorkdir } now accepts path relative to current workdir
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
also use Stat instead of Contents so we don't needlessly fetch a bunch of data from a directory with a ton of files Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
we need a beefier runner :( Signed-off-by: Alex Suraci <[email protected]>
a test caught this, yay! Signed-off-by: Alex Suraci <[email protected]>
9eba737 to
ccaf365
Compare
| return llb.NewState(defop), nil | ||
| } | ||
|
|
||
| func absPath(workDir string, path_ string) string { |
There was a problem hiding this comment.
This was me getting frustrated with the path package name collision. 😂
Refactored later in b0b1f6b
There was a problem hiding this comment.
Yeah I think that's basically what I was imagining in terms of API.
I don't think it's worth creating rebasing nightmares by removing this commit as long as we get the newer api in before preview, which seems pretty doable? If we don't though then we should just hide this API from users probably. Either way, doesn't have to block this PR imo
part of #3183
based on #3205 - will rebase after it's merged to make this PR easier to review.rebased!Implements the following APIs: