Compare commits
2 Commits
4f47194d8d
...
cb51ae31e7
Author | SHA1 | Date | |
---|---|---|---|
cb51ae31e7 | |||
ac9a119eb5 |
106
Dockerfile
106
Dockerfile
@ -1,54 +1,52 @@
|
||||
FROM ubuntu:24.04 AS wash-build-image
|
||||
|
||||
# Install dependencies and tools
|
||||
RUN apt-get update && apt-get install -y \
|
||||
curl \
|
||||
wget \
|
||||
tar \
|
||||
git \
|
||||
build-essential \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# ----------------- Install WasmCloud -----------------
|
||||
RUN curl -s "https://packagecloud.io/install/repositories/wasmcloud/core/script.deb.sh" | bash && \
|
||||
apt-get install -y wash
|
||||
|
||||
# ----------------- Install Go 1.23 -----------------
|
||||
RUN wget https://go.dev/dl/go1.23.4.linux-amd64.tar.gz && \
|
||||
tar -C /usr/local -xzf go1.23.4.linux-amd64.tar.gz && \
|
||||
rm go1.23.4.linux-amd64.tar.gz
|
||||
|
||||
# Set Go environment variables
|
||||
ENV PATH="/usr/local/go/bin:${PATH}"
|
||||
ENV GOPATH="/go"
|
||||
ENV GOROOT="/usr/local/go"
|
||||
|
||||
# ----------------- Install TinyGo 0.34.0 -----------------
|
||||
RUN wget https://github.com/tinygo-org/tinygo/releases/download/v0.34.0/tinygo_0.34.0_amd64.deb && \
|
||||
dpkg -i tinygo_0.34.0_amd64.deb && \
|
||||
rm tinygo_0.34.0_amd64.deb
|
||||
|
||||
# ----------------- Install Rust -----------------
|
||||
# Install Rust
|
||||
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
|
||||
. "$HOME/.cargo/env" && \
|
||||
cargo install --locked wasm-tools
|
||||
|
||||
# Set Rust environment variables
|
||||
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||
|
||||
# Verify installations
|
||||
RUN go version && tinygo version && cargo --version && wash --version && wasm-tools --version
|
||||
|
||||
|
||||
# ----------------- Build the WasmCloud module -----------------
|
||||
FROM wash-build-image
|
||||
|
||||
RUN mkdir /app
|
||||
WORKDIR /app
|
||||
|
||||
USER ubuntu
|
||||
|
||||
# Install go dependencies, build the wasm module, push it to the registry
|
||||
#CMD ["sh", "-c", "go mod download && go mod verify && go mod tidy && wash build && wash push $REGISTRY build/*_s.wasm"]
|
||||
CMD ["sh", "-c", "go mod download && go mod verify && go mod tidy && chmod -R u+rw /app && sleep 2 && wash build && wash push $REGISTRY build/*_s.wasm"]
|
||||
FROM ubuntu:24.04 AS wash-build-image
|
||||
|
||||
# Install dependencies and tools
|
||||
RUN apt-get update && apt-get install -y \
|
||||
curl \
|
||||
wget \
|
||||
tar \
|
||||
git \
|
||||
build-essential \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# ----------------- Install WasmCloud -----------------
|
||||
RUN curl -s "https://packagecloud.io/install/repositories/wasmcloud/core/script.deb.sh" | bash && \
|
||||
apt-get install -y wash
|
||||
|
||||
# ----------------- Install Go 1.23 -----------------
|
||||
RUN wget https://go.dev/dl/go1.23.4.linux-amd64.tar.gz && \
|
||||
tar -C /usr/local -xzf go1.23.4.linux-amd64.tar.gz && \
|
||||
rm go1.23.4.linux-amd64.tar.gz
|
||||
|
||||
# Set Go environment variables
|
||||
ENV PATH="/usr/local/go/bin:${PATH}"
|
||||
ENV GOPATH="/go"
|
||||
ENV GOROOT="/usr/local/go"
|
||||
|
||||
# ----------------- Install TinyGo 0.34.0 -----------------
|
||||
RUN wget https://github.com/tinygo-org/tinygo/releases/download/v0.34.0/tinygo_0.34.0_amd64.deb && \
|
||||
dpkg -i tinygo_0.34.0_amd64.deb && \
|
||||
rm tinygo_0.34.0_amd64.deb
|
||||
|
||||
# ----------------- Install Rust -----------------
|
||||
# Install Rust
|
||||
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
|
||||
. "$HOME/.cargo/env" && \
|
||||
cargo install --locked wasm-tools
|
||||
|
||||
# Set Rust environment variables
|
||||
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||
|
||||
# Verify installations
|
||||
RUN go version && tinygo version && cargo --version && wash --version && wasm-tools --version
|
||||
|
||||
|
||||
# ----------------- Build the WasmCloud module -----------------
|
||||
FROM wash-build-image
|
||||
|
||||
RUN mkdir /app
|
||||
WORKDIR /app
|
||||
|
||||
# Install go dependencies, build the wasm module, push it to the registry
|
||||
#CMD ["sh", "-c", "go mod download && go mod verify && go mod tidy && wash build && wash push $REGISTRY build/*_s.wasm"]
|
||||
CMD ["sh", "-c", "go env -w GOFLAGS=-buildvcs=false && go mod download && go mod verify && wash build && wash push $REGISTRY build/*_s.wasm"]
|
@ -5,6 +5,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
gitea_rebus_ninja__lore__go___nats___client__gen__wasi__config__runtime "gitea.rebus.ninja/lore/go-nats-client/gen/wasi/config/runtime"
|
||||
gitea_rebus_ninja__lore__go___nats___client__gen__wasmcloud__messaging__consumer "gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/consumer"
|
||||
gitea_rebus_ninja__lore__go___nats___client__gen__wasmcloud__messaging__types "gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/types"
|
||||
github_com__bytecodealliance__wasm___tools___go__cm "github.com/bytecodealliance/wasm-tools-go/cm"
|
||||
@ -17,6 +18,46 @@ const _ string = runtime.Compiler
|
||||
|
||||
var _ unsafe.Pointer
|
||||
|
||||
//go:linkname wasmimport_Get gitea.rebus.ninja/lore/go-nats-client/gen/wasi/config/runtime.wasmimport_Get
|
||||
func wasmimport_Get(key0 *uint8, key1 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[gitea_rebus_ninja__lore__go___nats___client__gen__wasi__config__runtime.OptionStringShape, github_com__bytecodealliance__wasm___tools___go__cm.Option[string], gitea_rebus_ninja__lore__go___nats___client__gen__wasi__config__runtime.ConfigError]) {
|
||||
var __p runtime.Pinner
|
||||
defer __p.Unpin()
|
||||
if __err := wadge.WithCurrentInstance(func(__instance *wadge.Instance) error {
|
||||
return __instance.Call("wasi:config/runtime@0.2.0-draft", "get", func() unsafe.Pointer {
|
||||
ptr := unsafe.Pointer(key0)
|
||||
__p.Pin(ptr)
|
||||
return ptr
|
||||
}(), func() unsafe.Pointer {
|
||||
ptr := unsafe.Pointer(&key1)
|
||||
__p.Pin(ptr)
|
||||
return ptr
|
||||
}(), func() unsafe.Pointer {
|
||||
ptr := unsafe.Pointer(result)
|
||||
__p.Pin(ptr)
|
||||
return ptr
|
||||
}())
|
||||
}); __err != nil {
|
||||
wadge.CurrentErrorHandler()(__err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//go:linkname wasmimport_GetAll gitea.rebus.ninja/lore/go-nats-client/gen/wasi/config/runtime.wasmimport_GetAll
|
||||
func wasmimport_GetAll(result *github_com__bytecodealliance__wasm___tools___go__cm.Result[gitea_rebus_ninja__lore__go___nats___client__gen__wasi__config__runtime.ConfigErrorShape, github_com__bytecodealliance__wasm___tools___go__cm.List[[2]string], gitea_rebus_ninja__lore__go___nats___client__gen__wasi__config__runtime.ConfigError]) {
|
||||
var __p runtime.Pinner
|
||||
defer __p.Unpin()
|
||||
if __err := wadge.WithCurrentInstance(func(__instance *wadge.Instance) error {
|
||||
return __instance.Call("wasi:config/runtime@0.2.0-draft", "get-all", func() unsafe.Pointer {
|
||||
ptr := unsafe.Pointer(result)
|
||||
__p.Pin(ptr)
|
||||
return ptr
|
||||
}())
|
||||
}); __err != nil {
|
||||
wadge.CurrentErrorHandler()(__err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//go:linkname wasmimport_Log gitea.rebus.ninja/lore/go-nats-client/gen/wasi/logging/logging.wasmimport_Log
|
||||
func wasmimport_Log(level0 uint32, context0 *uint8, context1 uint32, message0 *uint8, message1 uint32) {
|
||||
var __p runtime.Pinner
|
||||
|
79
messaging.go
79
messaging.go
@ -1,35 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/bytecodealliance/wasm-tools-go/cm"
|
||||
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/consumer"
|
||||
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/types"
|
||||
logger "gitea.rebus.ninja/lore/go-nats-client/gen/wasi/logging/logging"
|
||||
)
|
||||
|
||||
type messagingConsumerAdapter struct {
|
||||
Publish func(msg types.BrokerMessage) (result cm.Result[string, struct{}, string])
|
||||
}
|
||||
|
||||
// NOTE(lxf): this is overridden in tests
|
||||
var messagingConsumer = &messagingConsumerAdapter{
|
||||
Publish: consumer.Publish,
|
||||
}
|
||||
|
||||
func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] {
|
||||
|
||||
logger.Log(logger.LevelInfo,"MessageHandler", "Received message on subject" + msg.Subject)
|
||||
|
||||
reply := types.BrokerMessage{
|
||||
Subject: msg.Subject + ".reply",
|
||||
Body: msg.Body,
|
||||
ReplyTo: cm.None[string](),
|
||||
}
|
||||
res := messagingConsumer.Publish(reply)
|
||||
if res.IsErr() {
|
||||
logger.Log(logger.LevelError, "MessageHandler", "Failed to send reply, error: " + *res.Err())
|
||||
return res
|
||||
}
|
||||
|
||||
return cm.OK[cm.Result[string, struct{}, string]](struct{}{})
|
||||
}
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/bytecodealliance/wasm-tools-go/cm"
|
||||
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/consumer"
|
||||
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/types"
|
||||
logger "gitea.rebus.ninja/lore/go-nats-client/gen/wasi/logging/logging"
|
||||
//config "gitea.rebus.ninja/lore/go-nats-client/gen/wasi/config/runtime"
|
||||
)
|
||||
|
||||
type messagingConsumerAdapter struct {
|
||||
Publish func(msg types.BrokerMessage) (result cm.Result[string, struct{}, string])
|
||||
}
|
||||
|
||||
// NOTE(lxf): this is overridden in tests
|
||||
var messagingConsumer = &messagingConsumerAdapter{
|
||||
Publish: consumer.Publish,
|
||||
}
|
||||
|
||||
func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] {
|
||||
|
||||
logger.Log(logger.LevelInfo,"MessageHandler", "Received message on subject" + msg.Subject)
|
||||
|
||||
// TODO implement the logic to get the destination topic from the config
|
||||
// dest_topic := config.GetAll()
|
||||
dest_topic := msg.Subject + ".reply"
|
||||
|
||||
// TASK
|
||||
|
||||
|
||||
// Send reply
|
||||
reply := types.BrokerMessage{
|
||||
Subject: dest_topic,
|
||||
Body: msg.Body,
|
||||
ReplyTo: cm.None[string](),
|
||||
}
|
||||
res := messagingConsumer.Publish(reply)
|
||||
if res.IsErr() {
|
||||
logger.Log(logger.LevelError, "MessageHandler", "Failed to send reply, error: " + *res.Err())
|
||||
return res
|
||||
}
|
||||
|
||||
return cm.OK[cm.Result[string, struct{}, string]](struct{}{})
|
||||
}
|
||||
|
162
wadm.yaml
162
wadm.yaml
@ -1,79 +1,83 @@
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: tinygo-hello-world
|
||||
annotations:
|
||||
description: 'HTTP hello world demo in Golang (TinyGo), using the WebAssembly Component Model and WebAssembly Interfaces Types (WIT)'
|
||||
wasmcloud.dev/authors: wasmCloud team
|
||||
wasmcloud.dev/source-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/golang/components/http-hello-world/wadm.yaml
|
||||
wasmcloud.dev/readme-md-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/golang/components/http-hello-world/README.md
|
||||
wasmcloud.dev/homepage: https://github.com/wasmCloud/wasmCloud/tree/main/examples/golang/components/http-hello-world
|
||||
wasmcloud.dev/categories: |
|
||||
http,outgoing-http,http-server,tinygo,golang,example
|
||||
spec:
|
||||
components:
|
||||
- name: echo
|
||||
type: component
|
||||
properties:
|
||||
# To use the locally compiled code in this folder, use the line below instead after running `wash build`:
|
||||
# image: file://./build/echo_messaging_s.wasm
|
||||
image: gitea.rebus.ninja/lore/go-nats-client:1.0.1
|
||||
id: echo
|
||||
traits:
|
||||
# Govern the spread/scheduling of the component
|
||||
- type: spreadscaler
|
||||
properties:
|
||||
instances: 1
|
||||
spread:
|
||||
- name: edge
|
||||
weight: 100
|
||||
requirements:
|
||||
host-type: edge
|
||||
# Establish a unidirectional link to the messaging capability provider (powered by NATS),
|
||||
# so the `echo` component can make use of messaging interface functionality
|
||||
# (i.e. making interacting with the messaging system, in this case NATS)
|
||||
- type: link
|
||||
properties:
|
||||
target: nats
|
||||
namespace: wasmcloud
|
||||
package: messaging
|
||||
interfaces: [consumer]
|
||||
|
||||
# Add a capability provider that implements `wasmcloud:messaging` using NATS
|
||||
- name: nats
|
||||
type: capability
|
||||
properties:
|
||||
image: ghcr.io/wasmcloud/messaging-nats:0.23.1
|
||||
## To configure OTEL integration for this provider specifically, uncomment the lines below
|
||||
# config:
|
||||
# - name: otel
|
||||
# properties:
|
||||
# otel_exporter_otlp_endpoint: "http://all-in-one:4318"
|
||||
# otel_exporter_otlp_traces_endpoint: "http://traces-backend/v1/traces"
|
||||
# otel_exporter_otlp_metrics_endpoint: "http://metrics-backend/v1/metrics"
|
||||
# otel_exporter_otlp_logs_endpoint: "http://logs-backend/v1/logs"
|
||||
traits:
|
||||
# Since the `nats` capability provider calls an component to handle messages
|
||||
# coming over subscriptions, this provider needs a unidirectional link to the
|
||||
# component that wil be called.
|
||||
#
|
||||
# Here we link the `nats` provider (the "source"), to the `echo` component (the "target"),
|
||||
# so that so the provider can deliver messages to the component (by invoking the wasmcloud:messaging/handler interface) .
|
||||
- type: link
|
||||
properties:
|
||||
target: echo
|
||||
namespace: wasmcloud
|
||||
package: messaging
|
||||
interfaces: [handler]
|
||||
source_config:
|
||||
- name: simple-subscription
|
||||
properties:
|
||||
subscriptions: wasmcloud.echo
|
||||
- type: spreadscaler
|
||||
properties:
|
||||
instances: 1
|
||||
spread:
|
||||
- name: edge
|
||||
weight: 100
|
||||
requirements:
|
||||
host-type: edge
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: tinygo-hello-world
|
||||
annotations:
|
||||
description: 'HTTP hello world demo in Golang (TinyGo), using the WebAssembly Component Model and WebAssembly Interfaces Types (WIT)'
|
||||
wasmcloud.dev/authors: wasmCloud team
|
||||
wasmcloud.dev/source-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/golang/components/http-hello-world/wadm.yaml
|
||||
wasmcloud.dev/readme-md-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/golang/components/http-hello-world/README.md
|
||||
wasmcloud.dev/homepage: https://github.com/wasmCloud/wasmCloud/tree/main/examples/golang/components/http-hello-world
|
||||
wasmcloud.dev/categories: |
|
||||
http,outgoing-http,http-server,tinygo,golang,example
|
||||
spec:
|
||||
components:
|
||||
- name: echo
|
||||
type: component
|
||||
properties:
|
||||
# To use the locally compiled code in this folder, use the line below instead after running `wash build`:
|
||||
# image: file://./build/echo_messaging_s.wasm
|
||||
image: gitea.rebus.ninja/lore/go-nats-client:1.0.1
|
||||
id: echo
|
||||
config:
|
||||
- name: nats-topic
|
||||
properties:
|
||||
dest-topic: wasmcloud.echo.reply
|
||||
traits:
|
||||
# Govern the spread/scheduling of the component
|
||||
- type: spreadscaler
|
||||
properties:
|
||||
instances: 1
|
||||
spread:
|
||||
- name: edge
|
||||
weight: 100
|
||||
requirements:
|
||||
host-type: edge
|
||||
# Establish a unidirectional link to the messaging capability provider (powered by NATS),
|
||||
# so the `echo` component can make use of messaging interface functionality
|
||||
# (i.e. making interacting with the messaging system, in this case NATS)
|
||||
- type: link
|
||||
properties:
|
||||
target: nats
|
||||
namespace: wasmcloud
|
||||
package: messaging
|
||||
interfaces: [consumer]
|
||||
|
||||
# Add a capability provider that implements `wasmcloud:messaging` using NATS
|
||||
- name: nats
|
||||
type: capability
|
||||
properties:
|
||||
image: ghcr.io/wasmcloud/messaging-nats:0.23.1
|
||||
## To configure OTEL integration for this provider specifically, uncomment the lines below
|
||||
# config:
|
||||
# - name: otel
|
||||
# properties:
|
||||
# otel_exporter_otlp_endpoint: "http://all-in-one:4318"
|
||||
# otel_exporter_otlp_traces_endpoint: "http://traces-backend/v1/traces"
|
||||
# otel_exporter_otlp_metrics_endpoint: "http://metrics-backend/v1/metrics"
|
||||
# otel_exporter_otlp_logs_endpoint: "http://logs-backend/v1/logs"
|
||||
traits:
|
||||
# Since the `nats` capability provider calls an component to handle messages
|
||||
# coming over subscriptions, this provider needs a unidirectional link to the
|
||||
# component that wil be called.
|
||||
#
|
||||
# Here we link the `nats` provider (the "source"), to the `echo` component (the "target"),
|
||||
# so that so the provider can deliver messages to the component (by invoking the wasmcloud:messaging/handler interface) .
|
||||
- type: link
|
||||
properties:
|
||||
target: echo
|
||||
namespace: wasmcloud
|
||||
package: messaging
|
||||
interfaces: [handler]
|
||||
source_config:
|
||||
- name: simple-subscription
|
||||
properties:
|
||||
subscriptions: wasmcloud.echo
|
||||
- type: spreadscaler
|
||||
properties:
|
||||
instances: 1
|
||||
spread:
|
||||
- name: edge
|
||||
weight: 100
|
||||
requirements:
|
||||
host-type: edge
|
||||
|
@ -2,6 +2,15 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 1
|
||||
|
||||
[[packages]]
|
||||
name = "wasi:config"
|
||||
registry = "wasi.dev"
|
||||
|
||||
[[packages.versions]]
|
||||
requirement = "=0.2.0-draft"
|
||||
version = "0.2.0-draft"
|
||||
digest = "sha256:aa2d36d0843999edad80a13bf22f4529277f7b6012429f8a5d1f9499f3793c1a"
|
||||
|
||||
[[packages]]
|
||||
name = "wasi:logging"
|
||||
registry = "wasi.dev"
|
||||
|
Loading…
Reference in New Issue
Block a user