Example Spin HTTP Application written in Go.
Start the application:
spin up --build
Access the HTTP endpoint:
xdg-open http://localhost:3000
There are two ways to run a WebAssembly binary in a container:
- Ship the
spin
binary and your.wasm
file in a docker container image. - Ship the
.wasm
file and thespin.toml
manifest file in a oci image artifact; this can be done in a single step withspin registry push
. Then use a container runtime or orchestrator that supports running wasm containers. For example,containerd
and thecontainerd-shim-spin-v2
containerd shim.
NB The Fermyon Cloud directly uses the .wasm
file, so there is no need to
use a container. Instead use spin deploy
to deploy the application to the
Fermyon Cloud.
See https://developer.fermyon.com/spin/v2/kubernetes.
Install containerd and the containerd-shim-spin.
Use crictl
:
# see https://kubernetes.io/docs/concepts/architecture/cri/
# see https://kubernetes.io/docs/tasks/debug/debug-cluster/crictl/
# see https://kubernetes.io/docs/reference/tools/map-crictl-dockercli/
# see https://github.com/kubernetes-sigs/cri-tools/blob/master/docs/crictl.md
# see https://github.com/kubernetes-sigs/cri-tools/blob/master/cmd/crictl/sandbox.go
# see https://github.com/kubernetes-sigs/cri-tools/blob/master/cmd/crictl/container.go
# see https://github.com/kubernetes/cri-api/blob/kubernetes-1.27.10/pkg/apis/runtime/v1/api.proto
crictl pull \
ghcr.io/rgl/spin-http-go-example:0.3.1
crictl images list
crictl info | jq .config.containerd.runtimes
install -d -m 700 /var/log/cri
cat >cri-spin-http-go-example.pod.yml <<'EOF'
metadata:
uid: cri-spin-http-go-example
name: cri-spin-http-go-example
namespace: default
log_directory: /var/log/cri/cri-spin-http-go-example
EOF
cat >cri-spin-http-go-example.web.ctr.yml <<'EOF'
metadata:
name: web
image:
image: ghcr.io/rgl/spin-http-go-example:0.3.1
command:
- /
log_path: web.log
EOF
pod_id="$(crictl runp \
--runtime spin \
cri-spin-http-go-example.pod.yml)"
web_ctr_id="$(crictl create \
$pod_id \
cri-spin-http-go-example.web.ctr.yml \
cri-spin-http-go-example.pod.yml)"
crictl start $web_ctr_id
web_ctr_ip="$(crictl inspectp $pod_id | jq -r .status.network.ip)"
wget -qO- "http://$web_ctr_ip"
crictl ps -a # list containers.
crictl inspect $web_ctr_id | jq # inspect container.
crictl logs $web_ctr_id # dump container logs.
crictl pods # list pods.
crictl inspectp $pod_id | jq # inspect pod.
crictl stopp $pod_id # stop pod.
crictl rmp $pod_id # remove pod.
rm -rf /var/log/cri/cri-spin-http-go-example
NB This is not yet working. See deislabs/containerd-wasm-shims#202.
Use ctr
:
ctr image pull \
ghcr.io/rgl/spin-http-go-example:0.3.1
ctr images list
ctr run \
--detach \
--runtime io.containerd.spin.v2 \
--net-host \
ghcr.io/rgl/spin-http-go-example:0.3.1 \
ctr-spin-http-go-example
ctr sandboxes list # aka pods.
ctr containers list
ctr container rm ctr-spin-http-go-example
- Spin Go SDK
- Spin Go SDK Examples
- Spin Go SDK package
- Building Spin Components in Go
- Done icon
- Creating a container image
- TinyGo WASI support
- Go WASI support
- NB Upstream Go is not yet supported by Spin.