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: run move2kube in wasm #1062

Closed
1 task
HarikrishnanBalagopal opened this issue Jul 26, 2023 · 7 comments
Closed
1 task

feat: run move2kube in wasm #1062

HarikrishnanBalagopal opened this issue Jul 26, 2023 · 7 comments
Assignees
Labels
lfx-project https://lfx.linuxfoundation.org/tools/mentorship/

Comments

@HarikrishnanBalagopal
Copy link
Contributor

HarikrishnanBalagopal commented Jul 26, 2023

LFX link

https://mentorship.lfx.linuxfoundation.org/project/c2b5f721-2666-4d9e-85d6-7bedae27e144

Move2Kube is a command-line tool for automating creation of Infrastructure as code (IaC) artifacts. It has inbuilt support for creating IaC artifacts for replatforming to Kubernetes/OpenShift. We want to compile targetting WASM/WASI and run the resulting WASM module in the browser. This will help up showcase Move2Kube for demos and allow users to quickly try out Move2Kube without having to install it or any of its dependencies.

  • Expected Outcome:
    • Run Move2Kube CLI in the browser using WebAssembly.

Prerequisites

Please familiar yourself with the topics and try compiling simple Golang programs to WASI (preferably those that use the filesystem) with TinyGo so that you are familiar with the workflow and challenges involved.

  • Some in-depth knowledge of WASM/WASI and Golang/TinyGo.
  • (Optional) In-depth knowledge of Move2Kube will also help a lot but we can help guide you through that.

Getting Started

Challenges

This is not an exhaustive list, just the ones we have found so far.

Tasks

Preview Give feedback
@HarikrishnanBalagopal HarikrishnanBalagopal added the lfx-project https://lfx.linuxfoundation.org/tools/mentorship/ label Jul 26, 2023
@Prakhar-Agarwal-byte
Copy link
Contributor

I read the description of this issue from LFX project details, I am interested in working on this one.

@VaibhavMalik4187
Copy link

Hello, I'm interested in working on this project.

@HarikrishnanBalagopal
Copy link
Contributor Author

Hello, I'm interested in working on this project.

@Prakhar-Agarwal-byte @VaibhavMalik4187

Thanks for your interest. For future reference, we welcome everyone to follow the getting started steps and familiarize themselves with the project itself and relevant topics like WASM/WASI. However since this issue is part of the LFX project we can't assign it to anyone in particular until the candidate selection is over to avoid any conflict of interest issues.

Feel free to start working on the issue as that will help you write a good proposal for the LFX candidate selection process.

@HarikrishnanBalagopal
Copy link
Contributor Author

HarikrishnanBalagopal commented Sep 27, 2023

Working through some errors when compiling Move2Kube to Wasm using TinyGo compiler:

Done:

  1. Fixed by adding build constraints to exclude the ArgoCD files
prakhar@prakhar-laptop:~/move2kube$ CGO_ENABLED=0 tinygo build -o wasm.wasm -target wasm .
package [github.com/konveyor/move2kube](http://github.com/konveyor/move2kube)
        imports [github.com/konveyor/move2kube/cmd](http://github.com/konveyor/move2kube/cmd)
        imports [github.com/konveyor/move2kube/lib](http://github.com/konveyor/move2kube/lib)
        imports [github.com/konveyor/move2kube/transformer](http://github.com/konveyor/move2kube/transformer)
        imports [github.com/konveyor/move2kube/environment](http://github.com/konveyor/move2kube/environment)
        imports [github.com/konveyor/move2kube/environment/container](http://github.com/konveyor/move2kube/environment/container)
        imports [github.com/docker/docker/pkg/archive](http://github.com/docker/docker/pkg/archive)
        imports [golang.org/x/sys/unix](http://golang.org/x/sys/unix): build constraints exclude all Go files in /home/prakhar/go/pkg/mod/golang.org/x/[email protected]/unix
  1. Fix by stubbing the net.LookupHost function in TinyGo
prakhar@prakhar-laptop:~/move2kube$ CGO_ENABLED=0 tinygo build -o wasm.wasm -target wasm .
# [github.com/Masterminds/sprig](http://github.com/Masterminds/sprig)
../go/pkg/mod/github.com/!masterminds/[email protected]+incompatible/network.go:9:18: undefined: net.LookupHost
  1. Error:
prakhar@prakhar-laptop:~/move2kube$ CGO_ENABLED=0 /home/prakhar/tinygo/build/tinygo build -o wasm.wasm -target wasm .
# [github.com/go-git/go-git/v5](http://github.com/go-git/go-git/v5)
../go/pkg/mod/github.com/go-git/go-git/[email protected]/worktree_js.go:14:30: undefined: syscall.Stat_t

Fix by using the target wasi or wasipi instead of wasm

$ CGO_ENABLED=0 /home/prakhar/tinygo/build/tinygo build -o wasm.wasm -target wasip1 .

https://github.com/tinygo-org/tinygo/blob/731532cd2b6353b60b443343b51296ec0fafae09/src/syscall/syscall_libc_wasi.go#L234-L251
https://tinygo.org/docs/guides/webassembly/wasi/

To Do:

prakhar@prakhar-laptop:~/move2kube$ CGO_ENABLED=0 /home/prakhar/tinygo/build/tinygo build -o wasm.wasm -target wasi .
# [google.golang.org/grpc/internal/resolver/dns](http://google.golang.org/grpc/internal/resolver/dns)
../go/pkg/mod/google.golang.org/[email protected]/internal/resolver/dns/dns_resolver.go:164:90: undefined: net.SRV
../go/pkg/mod/google.golang.org/[email protected]/internal/resolver/dns/dns_resolver.go:83:36: undefined: net.DefaultResolver
../go/pkg/mod/google.golang.org/[email protected]/internal/resolver/dns/dns_resolver.go:104:14: undefined: net.Resolver
../go/pkg/mod/google.golang.org/[email protected]/internal/resolver/dns/dns_resolver.go:281:29: undefined: net.DNSError

@HarikrishnanBalagopal
Copy link
Contributor Author

Switched to a different approach. Previously we used a subtractive approach where we removed code to get Move2Kube to compile to WASM.
New approach is an additive approach where we start from scratch and add code/functionality to an already working WASM binary.
Code: https://github.com/HarikrishnanBalagopal/move2kube-wasm
Running at: https://haribala.dev/move2kube-wasm/

@HarikrishnanBalagopal
Copy link
Contributor Author

@HarikrishnanBalagopal
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lfx-project https://lfx.linuxfoundation.org/tools/mentorship/
Projects
Status: Done
Development

No branches or pull requests

3 participants