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