Interacting with Go code from Ruby code
Problem statement
As part of Remote Development, we would like to use the devfile's go sdk from our Ruby codebase. This go sdk provides interfaces for various operations - validating a devfile, flattening a devfile, converting devfile to kubernetes resources, etc.
We would like a way to call these functions written in Go from our Ruby code.
Possible solutions
Run go code directly from Ruby
https://github.com/DavidHuie/quartz
Compile go sdk to binary and shell out from Ruby to call this binary
It looks like there is a precedent for this in GitLab with https://gitlab.com/gitlab-org/gitlab-elasticsearch-indexer
Compile go sdk to binary and package it a Ruby gem
We can have a repository that tracks upstream go sdk and publishes a Ruby gem for every new version of the upstream release/tag for various architectures. We then use this gem natively in our codebase.
Compile go sdk to wasm and run wasm from Ruby
It looks like the SDK is not compiling to wasm
Error
GOOS=js GOARCH=wasm go build -o main.wasm main.go
package command-line-arguments
imports github.com/devfile/library/v2/pkg/devfile
imports github.com/devfile/library/v2/pkg/devfile/parser
imports github.com/devfile/registry-support/registry-library/library
imports oras.land/oras-go/pkg/content
imports oras.land/oras-go/pkg/auth/docker
imports github.com/docker/docker/registry
imports github.com/docker/docker/pkg/jsonmessage
imports github.com/moby/term
imports golang.org/x/sys/unix: build constraints exclude all Go files in /Users/vishaltak/.asdf/installs/golang/1.18.7/packages/pkg/mod/golang.org/x/sys@v0.0.0-20211216021012-1d35b9e2eb4e/unix
Create Go-Ruby FFI(Foreign Function Interface)
UI over the Wire (gitlab-org/frontend/rfcs#112 - closed) uses Rust, and there are plans to build rubygems with Rust FFI in gitlab. We can build something similar for Go-Ruby FFI.
Use KAS
kas would transform devfile it got from rails into kubernetes resources using the go sdk before returning to agent.
As part of the spike, agentk is calling Rails directly(no server module is written in KAS since we never needed it).
We can add a server module to expose gRPC endpoints which converts devfile to k8s resources which Rails will call and then Rails will respond back to agentk. However, this feels patchy.
Alternatively, if we were to make agentk <-> kas <-> rails communication more explicit (doing long polls from agentk to kas and short polls from kas to rails), then that would not be patchy. Because KAS is already an explicit part of the architecture.