Skip to content

Change shim to be an oci-runtime wrapper. - #3913

Merged
sipsma merged 2 commits into
dagger:mainfrom
sipsma:mount-bin
Nov 18, 2022
Merged

sipsma merged 2 commits into
dagger:mainfrom
sipsma:mount-bin

Conversation

@sipsma

@sipsma sipsma commented Nov 18, 2022

Copy link
Copy Markdown
Contributor

Now shim is no longer built on the fly, instead it's built into our engine image. We then include it in dagger execs by configuring buildkitd to use it as the oci runtime binary. It then updates the container configuration to setup itself as the shim, which results in the same code executing as previously.

This new approach has the short term benefit of stopping us from needing to pull in golang images at runtime and build the shim on the fly, which is a frequent user complaint.

In the longer term, the ability to hook into the container runtime unlocks a ton of other interesting possibilities.

Signed-off-by: Erik Sipsma [email protected]


Problems solved and possibilities unlocked

  1. Fixes Building shim can cause rate limit errors from dockerhub #3733
  2. Enables us to take dagger-in-dagger out of experimental mode
  3. Totally hides _shim from log output (we partially hid it previously but it still showed up in errors when an exec exited non-zero, now it's gone from that too)
  4. Makes our IDs smaller because we don't have to embed the fully Dockerfile of the shim anymore whenever there is an exec.
  5. Solves the outstanding concern with the WASM prototype: [Experimental] wasi/wasm32 platform support #3603 (comment)
    • Similarly, I wonder if this could enable use of things like WINE to support running windows applications? Not sure, but maybe
  6. Gives us a path to completely hide the shim and the various .dagger_meta_mount artifacts that end up in each exec (which was always an unfortunate side effect of adding the shim's abilities)
    • I didn't do that as part of the PR so as to not expand the scope too much, but it should be possible now if we want it
  7. Potentially enables really interesting things like mounts being added to containers dynamically on request, which is something that came up a long time ago in the context of extensions.
  8. Generally, any sort of cool low-level system stuff becomes a lot more feasible now (though we should of course approach this with caution as low level container runtime details can be delicate)

@aluzzardi

Copy link
Copy Markdown
Contributor

Damn! Already :) Looking into it

Comment thread cmd/shim/main.go 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.

small nit: was this file mv'd instead of git mv? Or was just `git confused

Doesn't matter, but will make your rebase on the other PR harder

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 yeah I just mv'd probably. I'll see if it's possible to retroactively git mv it somehow.

Comment thread cmd/shim/main.go 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.

Can you add a comment explaining this sorcery?

If I understand correctly, we're getting called twice: once as dagger-shim which prepares calling ourselves again, this time as _shim, which triggers a different code path

Also, instead of documenting, WDYT if we made it more explicit by having cmd/shim and cmd/oci-worker? Since we're injecting a binary, we might as well inject 2.

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.

If I understand correctly, we're getting called twice: once as dagger-shim which prepares calling ourselves again, this time as _shim, which triggers a different code path

That's correct, it's basically just like having two subcommands available for use in the same binary; I just didn't bother to have an nice command line interface since these are far removed from anything a human should touch (or even see, they are buried in the engine image, never local to users).

I have a comment on setupBundle above but I'll expand it some more and put it down here or otherwise try to make it easier to find.

Also, instead of documenting, WDYT if we made it more explicit by having cmd/shim and cmd/oci-worker? Since we're injecting a binary, we might as well inject 2.

We can but there's some shared consts between the two that make it nicer to be in one main func and splitting probably slightly increases our image size + memory usage by not combining common executable pages together. So I'd overall prefer to keep them together at least right now if it's not too confusing.

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.

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.

Updated with a lot more comments, should be more clear now hopefully

Now shim is no longer built on the fly, instead it's built into our
engine image. We then include it in dagger execs by configuring
buildkitd to use *it* as the oci runtime binary. It then updates the
container configuration to setup itself as the shim, which results in
the same code executing as previously.

This new approach has the short term benefit of stopping us from needing
to pull in golang images at runtime and build the shim on the fly, which
is a frequent user complaint.

In the longer term, the ability to hook into the container runtime
unlocks a ton of other interesting possibilities.

Signed-off-by: Erik Sipsma <[email protected]>
@aluzzardi

Copy link
Copy Markdown
Contributor

Perfect! :shipit:

@sipsma

sipsma commented Nov 18, 2022

Copy link
Copy Markdown
Contributor Author

@aluzzardi I noticed one thing looking through the buildkitd logs; it was in some cases printing errors about failing to kill runc because that command doesn't take --bundle and the shim code was erroring there when it should have just passed through to runc. Didn't actually break anything but fixed that now.

Very small modification so I'll merge once tests pass if I don't hear back, but happy to address anything more in follow ups too if there happens to be any concerns with the second commit.

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.

Building shim can cause rate limit errors from dockerhub

2 participants