Skip to content

wasm: adds support to natively build and run wasm workload and wasm containers - #742

Merged
giuseppe merged 4 commits into
containers:mainfrom
flouthoc:crun-wasm-workload
Oct 28, 2021
Merged

giuseppe merged 4 commits into
containers:mainfrom
flouthoc:crun-wasm-workload

Conversation

@flouthoc

@flouthoc flouthoc commented Sep 29, 2021 •

Copy link
Copy Markdown
Collaborator

Following PR initiates and adds support for crun to be able to build and
run wasm workload in a native manner. With recent development in wasm and
amalgamation of OCI, crun should be able to build and run wasm workload in
an isolated environment.

Ref:
https://github.com/engineerd/wasm-to-oci
https://www.solo.io/blog/announcing-the-webassembly-wasm-oci-image-spec/
https://github.com/solo-io/wasm/blob/master/spec/spec-compat.md

Comment thread src/libcrun/container.c Resolved
@flouthoc

Copy link
Copy Markdown
Collaborator Author

/hold till TODO

@giuseppe
giuseppe marked this pull request as draft September 29, 2021 16:11
@flouthoc
flouthoc force-pushed the crun-wasm-workload branch from dfa77a9 to 3e5f286 Compare October 4, 2021 10:58
@flouthoc
flouthoc force-pushed the crun-wasm-workload branch 3 times, most recently from 47eea8a to c08b3c2 Compare October 13, 2021 05:00
@flouthoc

Copy link
Copy Markdown
Collaborator Author

Just need to add a working example.

@flouthoc
flouthoc force-pushed the crun-wasm-workload branch 6 times, most recently from 532b3bb to 366bcca Compare October 18, 2021 05:17
@flouthoc
flouthoc marked this pull request as ready for review October 18, 2021 05:44

@giuseppe giuseppe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

great work!

Just some minor comments

Comment thread src/libcrun/utils.c Outdated
size_t lensuffix = strlen (suffix);
if (lensuffix > lenstr)
return 0;
return strncmp (str + lenstr - lensuffix, suffix, lensuffix) == 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we use memcmp here since you've already calculated the length?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

thanks fixed in latest commit.

Comment thread src/libcrun/container.c Resolved
Comment thread docs/wasm-wasi-example.md Resolved
Comment thread docs/wasm-wasi-example.md Resolved
Comment thread docs/wasm-wasi-example.md Outdated
}
```
* Compile to `wasm32-wasi` target using `wasm-pack` or any other relevent tool. We are going to be using `cargo build --target wasm32-wasi`
* Create relevent image and use your container manager. But for this example we will be running directly using crun and plub config manually.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how would it be possible to use such example from an OCI image?

Is Buildah able to build an image with a wasm binary that runs automatically with the correct handler?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes running image with build with annotation buildah build --annotation "module.wasm.image/variant=compat" -t mywasm . or buildah build --annotation "run.oci.handler=wasm" -t mywasm . will switch handlers.

Also added a working example with buildah and podman.

Comment thread src/libcrun/container.c Resolved
Comment thread src/libcrun/container.c Resolved
@giuseppe

Copy link
Copy Markdown
Member

I think this is a great feature and we should try to get it into the next release.

Do you have a working example of running wasm modules in compatibility mode (from building the image with Buildah to run it with Podman)?

@flouthoc

Copy link
Copy Markdown
Collaborator Author

@giuseppe Sure i'll get it in this PR. I still have to rig buildah.

@flouthoc

flouthoc commented Oct 21, 2021 •

Copy link
Copy Markdown
Collaborator Author

@giuseppe Added a new change for supporting module.wasm.image/variant=compat annotations.

Running image built with annotations

  • buildah build --annotation "module.wasm.image/variant=compat" -t mywasm . or
  • buildah build --annotation "run.oci.handler=wasm" -t mywasm

Will switch handlers to wasm given that crun was built with wasm support.

Also added a working example with buildah and podman.

@flouthoc
flouthoc force-pushed the crun-wasm-workload branch 3 times, most recently from 16d038b to 28cdbec Compare October 21, 2021 08:54
@giuseppe

Copy link
Copy Markdown
Member

For the CI failure I am fine if we temporarily stick to a working commit in the runtime-tools and later revert the change once it is fixed upstream

@flouthoc
flouthoc force-pushed the crun-wasm-workload branch 2 times, most recently from 873f3da to ec924ae Compare October 26, 2021 09:54
@flouthoc

Copy link
Copy Markdown
Collaborator Author

rebased after #762

@giuseppe giuseppe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

some few minor comments, the one about exec is just to understand what is the plan, probably there is nothing to deal with as part of this PR.

Once these minor comments are addressed, I am fine to merge

Comment thread src/libcrun/container.c Outdated
if (data_read_size > 0)
{
stdout_size += data_read_size;
fwrite (buffer, sizeof (char), data_read_size, memory_stream);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we need to buffer the data? Cannot we just print it as soon as we read it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@giuseppe I agree with you on this one but my only concern was to handle NULL before every print. Just relying on module's EOF seemed natural to me. But i will optimize this in a separate PR if that works.

Optimizing this should reduce the use of open_memstream as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Won't that be kept in memory until the container exits? I don't think we can buffer the entire amount of stdout produced and print it only when the container exits

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@giuseppe ackd and makes sense to me. I'll rectify this one.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@giuseppe fixed on latest commit.

Comment thread src/libcrun/container.c Outdated

{
FILE *memory_stream;
char *stdout_ptr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isn't this buffer leaked?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

thanks fixed don't know how missed it.

Comment thread src/libcrun/container.c Resolved
Comment thread src/libcrun/container.c Resolved
Comment thread src/libcrun/container.c Resolved
Comment thread src/libcrun/container.c Resolved
Signed-off-by: Aditya Rajan <arajan@redhat.com>
Add support to switch handler to "wasm" if annotation
`module.wasm.image/variant=compat` is detected.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
Comment thread src/libcrun/container.c Resolved
Comment thread src/libcrun/utils.c Resolved
@giuseppe

Copy link
Copy Markdown
Member

how can we get wasmer on Fedora?

@lsm5 do you have any suggestions?

printf might be adding additional buffering since a level of buffering
might be happening at wasm binary itself.

Plus safe_write guarantees that we relay binary output as it is without
any additional modification or buffering.

Signed-off-by: Aditya Rajan <arajan@redhat.com>

@giuseppe giuseppe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@giuseppe
giuseppe merged commit a3721da into containers:main Oct 28, 2021
@giuseppe

Copy link
Copy Markdown
Member

@flouthoc congratulations on moving this major feature to completion!

@flouthoc

Copy link
Copy Markdown
Collaborator Author

yay !!!! I'll take @lsm5's help for library distribution.

@rhatdan

rhatdan commented Oct 28, 2021

Copy link
Copy Markdown
Member

Now how do we make it useful by integrating it into Podman and then writing a blog explaining what it does. Including the power of crun as an OCI Runtime.

@flouthoc

Copy link
Copy Markdown
Collaborator Author

@rhatdan

rhatdan commented Oct 28, 2021

Copy link
Copy Markdown
Member

Can you build this out into a Blog where you could actually push the image to a registry so that others could try it out.

@giuseppe

Copy link
Copy Markdown
Member

the issue is that users need to build a custom crun, since wasmer is not present on Fedora so we cannot build with it.

As soon as it is present, I think we should build crun with support for wasm

@rhatdan

rhatdan commented Oct 28, 2021

Copy link
Copy Markdown
Member

Is this worth pushing for?

@lsm5

lsm5 commented Oct 28, 2021

Copy link
Copy Markdown
Member

how can we get wasmer on Fedora?

@lsm5 do you have any suggestions?

@giuseppe what's the exact source repo for wasmer? Is it the wasm repo mentioned in the PR description? I see a bunch of rust-wasm packages in fedora already.

@lsm5

lsm5 commented Oct 28, 2021

Copy link
Copy Markdown
Member

fwiw, i don't yet see any non-rust packages in fedora for a dnf search wasm

@rhatdan

rhatdan commented Oct 28, 2021

Copy link
Copy Markdown
Member

Could we use the rust packages? @flouthoc @giuseppe

@flouthoc

Copy link
Copy Markdown
Collaborator Author

We would need wasmer's shared library. But I'll check once if its already being distributed with any other packages and will report back.

flouthoc added a commit to flouthoc/crun that referenced this pull request Jul 5, 2022
Following PR initiates and adds support for crun to be able to build and
run wasm/wasi workload in a native manner using `wasmtime`.

Crun already supports running `wasm` workload using `wasmer` and `wasmedge`
following PR extends this feature so that end-users can switch to `wasmtime`,
following feature is proposed inorder to maintain feature parity with
other tools in the same space.

Ref:
* Wasmedge integration: containers#774
* Wasmer integration: containers#742

Signed-off-by: Aditya R <arajan@redhat.com>
flouthoc added a commit to flouthoc/crun that referenced this pull request Jul 5, 2022
Following PR initiates and adds support for crun to be able to build and
run wasm/wasi workload in a native manner using `wasmtime`.

Crun already supports running `wasm` workload using `wasmer` and `wasmedge`
following PR extends this feature so that end-users can switch to `wasmtime`,
following feature is proposed inorder to maintain feature parity with
other tools in the same space like `krustlet` which rely on `wasmtime` under the hood.

Ref:
* Wasmedge integration: containers#774
* Wasmer integration: containers#742
* https://github.com/krustlet/krustlet

Signed-off-by: Aditya R <arajan@redhat.com>
flouthoc added a commit to flouthoc/crun that referenced this pull request Jul 6, 2022
Following PR initiates and adds support for crun to be able to build and
run wasm/wasi workload in a native manner using `wasmtime`.

Crun already supports running `wasm` workload using `wasmer` and `wasmedge`
following PR extends this feature so that end-users can switch to `wasmtime`,
following feature is proposed inorder to maintain feature parity with
other tools in the same space like `krustlet` which rely on `wasmtime` under the hood.

Ref:
* Wasmedge integration: containers#774
* Wasmer integration: containers#742
* https://github.com/krustlet/krustlet

Signed-off-by: Aditya R <arajan@redhat.com>
flouthoc added a commit to flouthoc/crun that referenced this pull request Jul 11, 2022
Following PR initiates and adds support for crun to be able to build and
run wasm/wasi workload in a native manner using `wasmtime`.

Crun already supports running `wasm` workload using `wasmer` and `wasmedge`
following PR extends this feature so that end-users can switch to `wasmtime`,
following feature is proposed inorder to maintain feature parity with
other tools in the same space like `krustlet` which rely on `wasmtime` under the hood.

Ref:
* Wasmedge integration: containers#774
* Wasmer integration: containers#742
* https://github.com/krustlet/krustlet

Signed-off-by: Aditya R <arajan@redhat.com>
flouthoc added a commit to flouthoc/crun that referenced this pull request Jul 11, 2022
Following PR initiates and adds support for crun to be able to build and
run wasm/wasi workload in a native manner using `wasmtime`.

Crun already supports running `wasm` workload using `wasmer` and `wasmedge`
following PR extends this feature so that end-users can switch to `wasmtime`,
following feature is proposed inorder to maintain feature parity with
other tools in the same space like `krustlet` which rely on `wasmtime` under the hood.

Ref:
* Wasmedge integration: containers#774
* Wasmer integration: containers#742
* https://github.com/krustlet/krustlet

Signed-off-by: Aditya R <arajan@redhat.com>
flouthoc added a commit to flouthoc/crun that referenced this pull request Jul 12, 2022
Following PR initiates and adds support for crun to be able to build and
run wasm/wasi workload in a native manner using `wasmtime`.

Crun already supports running `wasm` workload using `wasmer` and `wasmedge`
following PR extends this feature so that end-users can switch to `wasmtime`,
following feature is proposed inorder to maintain feature parity with
other tools in the same space like `krustlet` which rely on `wasmtime` under the hood.

Ref:
* Wasmedge integration: containers#774
* Wasmer integration: containers#742
* https://github.com/krustlet/krustlet

Signed-off-by: Aditya R <arajan@redhat.com>
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