#works after i run rootless buildkitd
buildctl --addr unix:///run/user/1005/buildkit/buildkitd.sock build --frontend=dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=docker.io/ashpect/testimage,push=true
sudo /home/ashish/bin/buildctl build 
--frontend=dockerfile.v0 
--local context=. 
--local dockerfile=. 
--output type=image,name=docker.io/ashpect/testimage,push=true

#push doesn't work on poseidon
if [ "$(id -u)" -eq 0 ] || sudo -v >/dev/null 2>&1; then
    echo "You are root or have sudo privileges."
else
    echo "You are not root and do not have sudo privileges."
fi
rootlesskit buildkitd unix://run/user/1005/buildkit/buildkitd.sock
rootlesskit buildkitd
./main py node rb

  1. Build Metacall Runtime Image: First, you would create a Docker image that contains the Metacall runtime environment. This image would include all the necessary dependencies, libraries, and configurations required to execute code that uses the Metacall library.
  2. Build Application Image: Once you have the Metacall runtime image, you can then build your application image. This image would include your application code along with any additional dependencies it requires. This could be code written in various programming languages that utilize Metacall for inter-language communication.
  3. Separate API: If you have a separated API, as mentioned in your requirement, you might have an API service that interacts with your application. This API service could also be containerized into its own Docker image.
  4. Integration: Your CLI tool would orchestrate these steps. It might have commands to build the Metacall runtime image, build the application image, and then combine them as necessary, depending on your deployment requirements.

#!/bin/sh
# buildctl-daemonless.sh spawns ephemeral buildkitd for executing buildctl.
#
# Usage: buildctl-daemonless.sh build ...
#
# Flags for buildkitd can be specified as $BUILDKITD_FLAGS .
#
# The script is compatible with BusyBox shell.
set -eu

: ${BUILDCTL=buildctl}
: ${BUILDCTL_CONNECT_RETRIES_MAX=10}
: ${BUILDKITD=buildkitd}
: ${BUILDKITD_FLAGS=}
: ${ROOTLESSKIT=rootlesskit}
: ${LIMACTL=limactl}

# $tmp holds the following files:
# * pid
# * addr
# * log
tmp=$(mktemp -d /tmp/buildctl-daemonless.XXXXXX)

if [ "$(uname)" == "Darwin" ]; then
    echo "$tmp"
    trap "rm -rf $tmp" EXIT
else
    trap "kill \\$(cat $tmp/pid) || true; wait \\$(cat $tmp/pid) || true; rm -rf $tmp" EXIT
fi

startBuildkitd() {
    addr=
    helper=
    if [ "$(uname)" == "Darwin" ]; then
        echo "MacOS: $(sw_vers -productName) $(sw_vers -productVersion) detected"
        if which buildctl >/dev/null 2>&1; then
            echo "buildctl is installed at $(which buildctl)"
            if which lima > /dev/null 2>&1; then
                echo "lima is installed at $(which lima)"
                    addr="unix://$HOME/.lima/buildkit/sock/buildkitd.sock"
                    echo "$addr" > "$tmp/addr"
                return
            else
                echo "Please install lima for running buildkitd using : brew install lima"
                exit 1
            fi
        else
            echo "builtctl is not installed. Please install it via brew install buildkit or build it using the moby/buildkit repo."
            exit 1
        fi
    elif [ $(id -u) = 0 ]; then
        addr=unix:///run/buildkit/buildkitd.sock
    else
        addr=unix://$XDG_RUNTIME_DIR/buildkit/buildkitd.sock
        helper=$ROOTLESSKIT
    fi
    $helper $BUILDKITD $BUILDKITD_FLAGS --addr=$addr >$tmp/log 2>&1 &
    pid=$!
    echo $pid >$tmp/pid
    echo $addr >$tmp/addr
}

# buildkitd supports NOTIFY_SOCKET but as far as we know, there is no easy way
# to wait for NOTIFY_SOCKET activation using busybox-builtin commands...
waitForBuildkitd() {
    addr=$(cat $tmp/addr)
    try=0
    max=$BUILDCTL_CONNECT_RETRIES_MAX
    until $BUILDCTL --addr=$addr debug workers >/dev/null 2>&1; do
        if [ $try -gt $max ]; then
            echo >&2 "could not connect to $addr after $max trials"
            echo >&2 "========== log =========="
            cat >&2 $tmp/log
            exit 1
        fi
        sleep $(awk "BEGIN{print (100 + $try * 20) * 0.001}")
        try=$(expr $try + 1)
    done
}

startBuildkitd
waitForBuildkitd
$BUILDCTL --addr=$(cat $tmp/addr) "$@"

Good Reads ( ) :

https://www.docker.com/blog/compiling-containers-dockerfiles-llvm-and-buildkit/

https://www.freecodecamp.org/news/the-basic-design-patterns-all-developers-need-to-know/

https://dev.to/kittipat1413/understanding-the-builder-pattern-in-go-gp9