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

feat(wasmtime): support wasi:http/proxy world in wasmtime shim #691

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

andreiltd
Copy link
Member

@andreiltd andreiltd commented Oct 7, 2024

This is a follow-up to #401.

The patch introduces initial support for the wasi:http/proxy world in the wasmtime shim. The main goal is to detect components targeting http/proxy, start up a hyper server to listen for incoming connections, and forward the incoming requests to the WASM component for handling. This behavior is very similar to what the wasmtime serve command currently offers. The server task is terminated upon receiving a terminate or interrupt signal in the container.

The server can be customized by setting environment variables passed to the RuntimeContext. These variables include:

  • WASMTIME_HTTP_PROXY_SOCKET_ADDR: Defines the socket address to bind to (default: 0.0.0.0:8080).
  • WASMTIME_HTTP_PROXY_BACKLOG: Defines the maximum number of pending connections in the queue (default: 100).

The compiled WASM component targeting wasi:http/proxy world has been integrated into the test-modules crate. This allows us to validate the functionality in the integration tests.

Closes: #416

@andreiltd andreiltd marked this pull request as draft October 7, 2024 15:59
@andreiltd andreiltd force-pushed the wasi-http branch 2 times, most recently from 131e0b5 to 74b24e7 Compare October 7, 2024 16:54
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
@andreiltd andreiltd force-pushed the wasi-http branch 5 times, most recently from dfae7d6 to 9548e83 Compare October 10, 2024 15:20
crates/containerd-shim-wasmtime/Cargo.toml Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/http_proxy.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/http_proxy.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/http_proxy.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
@andreiltd andreiltd force-pushed the wasi-http branch 2 times, most recently from 563426c to 64ffcbf Compare October 14, 2024 18:26
Copy link
Member

@Mossaka Mossaka left a comment

Choose a reason for hiding this comment

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

Great work! I left some comments on this PR. I think the shape of this PR is pretty good and I am happy to approve it to merge to the main tree when comments are resolved.

Cargo.toml Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
crates/containerd-shim-wasm/Cargo.toml Outdated Show resolved Hide resolved
crates/containerd-shim-wasm/src/testing.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/http_proxy.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/http_proxy.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
@andreiltd andreiltd changed the title Support wasi:http/proxy world in wasmtime shim feat(wasmtime): support wasi:http/proxy world in wasmtime shim Oct 16, 2024
@andreiltd andreiltd marked this pull request as ready for review October 16, 2024 17:47
Mossaka
Mossaka previously approved these changes Oct 21, 2024
Copy link
Member

@Mossaka Mossaka left a comment

Choose a reason for hiding this comment

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

LGTM!

Mossaka
Mossaka previously approved these changes Oct 21, 2024
Copy link
Collaborator

@jprendes jprendes left a comment

Choose a reason for hiding this comment

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

Thanks @andreiltd, this is great work, and a great feature!
I left a few comments, but I don't think we need to address all of them here.

crates/containerd-shim-wasmtime/src/tests.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/http_proxy.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/http_proxy.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wasmtime/src/instance.rs Outdated Show resolved Hide resolved
resource_table: ResourceTable::default(),
};
Ok(wasi_data)
pub(crate) fn envs_from_ctx(ctx: &impl RuntimeContext) -> Vec<(String, String)> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought: I'm inclined to think that this functionality should be part of the context, but not sure what name it should have.

@andreiltd
Copy link
Member Author

Here is a follow up PR that implements a graceful server shutdown: https://github.com/andreiltd/runwasi/pull/1/files

@andreiltd andreiltd force-pushed the wasi-http branch 2 times, most recently from 6b51a1b to ea036fa Compare October 25, 2024 15:54
Mossaka
Mossaka previously approved these changes Oct 25, 2024
Copy link
Collaborator

@jprendes jprendes left a comment

Choose a reason for hiding this comment

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

Thanks @andreiltd for your contribution!

crates/containerd-shim-wasmtime/src/http_proxy.rs Outdated Show resolved Hide resolved
@Mossaka Mossaka merged commit 6180600 into containerd:main Oct 25, 2024
53 checks passed
@Mossaka
Copy link
Member

Mossaka commented Oct 25, 2024

🥂 thanks for working on this, @andreiltd !

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.

Feature: Support wasi:http/proxy world in wasmtime shim
3 participants