Skip to main content

Blobstore Operations (NATS)

A demonstration of blob storage operations that exposes the results via HTTP, implemented as a Wasm component and packaged for Cosmonic Control.

Deploy with Helm

helm install blobstore-nats --version 0.1.2 oci://ghcr.io/cosmonic-labs/charts/http-trigger -f https://raw.githubusercontent.com/cosmonic-labs/control-demos/refs/heads/main/blobstore-nats/values.http-trigger.yaml

Repository: cosmonic-labs/control-demos/blobstore-nats
Languages: Rust
Interfaces: wasi/http, wasi/blobstore

Running on Kubernetes

You will need a local Kubernetes environment with Cosmonic Control installed according to the Get Started guide.

Connect to the component at http://blobstore.localhost.cosmonic.sh:

curl http://blobstore.localhost.cosmonic.sh

The component will return a JSON response showing the results of all operations:

{
  "container_ops": {
    "create_container": {
      "success": true,
      "message": "Created ying",
      "timestamp": "2024-12-05 16:30:00 UTC"
    },
    "container_info": {
      "success": true,
      "message": "Container ying created at 2024-12-05 16:30:00 UTC",
      "timestamp": "2024-12-05 16:30:00 UTC"
    }
    // ... more container operations
  },
  "blob_ops": {
    "write_blob": {
      "success": true,
      "message": "Wrote earth to ying",
      "timestamp": "2024-12-05 16:30:01 UTC"
    }
    // ... more blob operations
  },
  "container_names": ["ying", "yang"]
}

The component performs a series of blobstore operations:

  1. Container Operations:

    • Creates two containers (default: "ying" and "yang")
    • Verifies container existence
    • Retrieves container metadata
  2. Basic Blob Operations:

    • Writes four blobs ("earth", "air", "fire", "water") to "ying" container
    • Reads back and verifies content
    • Demonstrates partial content reading (first 4 bytes)
  3. Advanced Operations:

    • Moves "fire" from "ying" to "yang" container
    • Copies "water" from "ying" to "yang" container
    • Lists objects in both containers
    • Cleans up by clearing "ying" container

Development

Development requirements:

  • cargo 1.82+ for the Rust toolchain
  • wasm32-wasip2 target for Rust: Install with rustup target add wasm32-wasip2
  • Wasm Shell (wash) for component development

Clone the cosmonic-labs/control-demos repository:

git clone https://github.com/cosmonic-labs/control-demos.git
cd control-demos/blobstore-nats

Install the blobstore-filesystem plugin, which enables you to back blobstore operations with your local filesystem during the development loop:

wash plugin install ghcr.io/wasmcloud/wash-plugins/blobstore-filesystem:0.1.0

Start the development loop:

wash dev

The component is accessible at localhost:8000. View the code and make changes in src/lib.rs.

You can cancel the wash dev process with Ctrl-C.

Build the Wasm Binary

Compile the component:

wash build

The .wasm binary will output to /target/wasm32-wasip2/debug.

Learn More

  • To learn how to extend this example with additional capabilities, see the Adding Capabilities section of the wasmCloud documentation.

  • For more on building components in Go, see the Component Developer Guide in the wasmCloud documentation.