konveyor / move2kube

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.
https://move2kube.konveyor.io/
Apache License 2.0
383 stars 118 forks source link

feat: run move2kube in wasm #1062

Closed HarikrishnanBalagopal closed 7 months ago

HarikrishnanBalagopal commented 1 year ago

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.

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.

Getting Started

Challenges

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

### Tasks
- [ ] Run Move2Kube CLI in the browser using WASM/WASI
Prakhar-Agarwal-byte commented 1 year ago

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

VaibhavMalik4187 commented 1 year ago

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

HarikrishnanBalagopal commented 1 year ago

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 commented 1 year ago

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/sys@v0.7.0/unix
  2. 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/sprig@v2.22.0+incompatible/network.go:9:18: undefined: net.LookupHost
  3. 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/v5@v5.4.2/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/grpc@v1.53.0/internal/resolver/dns/dns_resolver.go:164:90: undefined: net.SRV
../go/pkg/mod/google.golang.org/grpc@v1.53.0/internal/resolver/dns/dns_resolver.go:83:36: undefined: net.DefaultResolver
../go/pkg/mod/google.golang.org/grpc@v1.53.0/internal/resolver/dns/dns_resolver.go:104:14: undefined: net.Resolver
../go/pkg/mod/google.golang.org/grpc@v1.53.0/internal/resolver/dns/dns_resolver.go:281:29: undefined: net.DNSError
HarikrishnanBalagopal commented 11 months ago

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 commented 11 months ago

Moved the code from https://github.com/HarikrishnanBalagopal/move2kube-wasm into this repo on a new branch https://github.com/konveyor/move2kube/tree/wasm

HarikrishnanBalagopal commented 7 months ago

Completed in https://github.com/konveyor/move2kube/tree/wasm branch. Deployed at https://move2kube.konveyor.io/experimental