From d1482590bc3d2b4017c163a2bf86f80e380d9dd9 Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Fri, 7 Jun 2024 08:50:25 -0700 Subject: [PATCH 1/8] Add MQTT trigger and tests Signed-off-by: Kate Goldenring --- Cargo.lock | 53 ++++++++++++ containerd-shim-spin/Cargo.toml | 1 + containerd-shim-spin/src/engine.rs | 15 +++- images/spin-mqtt-message-logger/.gitignore | 2 + images/spin-mqtt-message-logger/Cargo.toml | 14 ++++ images/spin-mqtt-message-logger/README | 60 ++++++++++++++ images/spin-mqtt-message-logger/spin.toml | 29 +++++++ images/spin-mqtt-message-logger/src/lib.rs | 16 ++++ tests/Cargo.toml | 1 + tests/src/integration_test.rs | 80 +++++++++++++++++++ tests/workloads-common/mqtt-broker.yaml | 25 ++++++ .../workloads.yaml | 42 +++++++++- 12 files changed, 335 insertions(+), 3 deletions(-) create mode 100644 images/spin-mqtt-message-logger/.gitignore create mode 100644 images/spin-mqtt-message-logger/Cargo.toml create mode 100644 images/spin-mqtt-message-logger/README create mode 100644 images/spin-mqtt-message-logger/spin.toml create mode 100644 images/spin-mqtt-message-logger/src/lib.rs create mode 100644 tests/workloads-common/mqtt-broker.yaml diff --git a/Cargo.lock b/Cargo.lock index 92f15108..941d9783 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1626,6 +1626,7 @@ dependencies = [ "kube", "rand 0.8.5", "redis 0.25.4", + "rumqttc", "tokio", "tower", ] @@ -1659,6 +1660,7 @@ dependencies = [ "temp-env", "tokio", "trigger-command", + "trigger-mqtt", "trigger-sqs", "url", "wasmtime", @@ -2802,6 +2804,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" + [[package]] name = "futures-util" version = "0.3.30" @@ -5270,6 +5278,32 @@ dependencies = [ "winapi", ] +[[package]] +name = "paho-mqtt" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8367868d51cef74c28da328ed8f60529ddd3f04dca1867dd825fcc3085a4308" +dependencies = [ + "async-channel 1.9.0", + "crossbeam-channel", + "futures", + "futures-timer", + "libc", + "log", + "paho-mqtt-sys", + "thiserror", +] + +[[package]] +name = "paho-mqtt-sys" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e482419d847af4ec43c07eed70f5f94f87dc712d267aecc91ab940944ab6bf4" +dependencies = [ + "cmake", + "openssl-sys", +] + [[package]] name = "parking" version = "2.2.0" @@ -8657,6 +8691,25 @@ dependencies = [ "wasmtime-wasi", ] +[[package]] +name = "trigger-mqtt" +version = "0.2.0" +source = "git+https://github.com/kate-goldenring/spin-trigger-mqtt?branch=use-spin-telemetry#4814a09d13bf559079da726c86f710b469cb47d0" +dependencies = [ + "anyhow", + "clap 3.2.25", + "futures", + "paho-mqtt", + "serde 1.0.204", + "spin-app", + "spin-core", + "spin-expressions", + "spin-telemetry", + "spin-trigger", + "tokio", + "wasmtime", +] + [[package]] name = "trigger-sqs" version = "0.7.0" diff --git a/containerd-shim-spin/Cargo.toml b/containerd-shim-spin/Cargo.toml index d554738b..c63ef9ad 100644 --- a/containerd-shim-spin/Cargo.toml +++ b/containerd-shim-spin/Cargo.toml @@ -21,6 +21,7 @@ spin-componentize = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } spin-trigger = { git = "https://github.com/fermyon/spin", tag = "v2.6.0", features = ["unsafe-aot-compilation"] } spin-trigger-http = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } spin-trigger-redis = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } +trigger-mqtt = { git = "https://github.com/kate-goldenring/spin-trigger-mqtt", branch = "use-spin-telemetry" } trigger-sqs = { git = "https://github.com/fermyon/spin-trigger-sqs", rev = "v0.7.0" } trigger-command = { git = "https://github.com/fermyon/spin-trigger-command", tag = "v0.1.0" } spin-manifest = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } diff --git a/containerd-shim-spin/src/engine.rs b/containerd-shim-spin/src/engine.rs index bd8734dd..d92a8f85 100644 --- a/containerd-shim-spin/src/engine.rs +++ b/containerd-shim-spin/src/engine.rs @@ -25,6 +25,7 @@ use spin_trigger_http::HttpTrigger; use spin_trigger_redis::RedisTrigger; use tokio::runtime::Runtime; use trigger_command::CommandTrigger; +use trigger_mqtt::MqttTrigger; use trigger_sqs::SqsTrigger; use url::Url; @@ -280,8 +281,17 @@ impl SpinEngine { guest_args: ctx.args().to_vec(), }) } + MqttTrigger::TRIGGER_TYPE => { + let mqtt_trigger: MqttTrigger = self + .build_spin_trigger(working_dir.clone(), app.clone(), app_source.clone()) + .await + .context("failed to build spin trigger")?; + + info!(" >>> running spin trigger"); + mqtt_trigger.run(trigger_mqtt::CliArgs { test: false }) + } _ => { - todo!("Only Http, Redis and SQS triggers are currently supported.") + todo!("Only Http, Redis, MQTT and SQS triggers are currently supported.") } }; @@ -542,9 +552,10 @@ fn trigger_command_for_resolved_app_source(resolved: &ResolvedAppSource) -> Resu RedisTrigger::TRIGGER_TYPE | HttpTrigger::TRIGGER_TYPE | SqsTrigger::TRIGGER_TYPE + | MqttTrigger::TRIGGER_TYPE | CommandTrigger::TRIGGER_TYPE => types.push(trigger_type), _ => { - todo!("Only Http, Redis and SQS triggers are currently supported.") + todo!("Only Http, Redis, MQTT and SQS triggers are currently supported.") } } } diff --git a/images/spin-mqtt-message-logger/.gitignore b/images/spin-mqtt-message-logger/.gitignore new file mode 100644 index 00000000..386474fa --- /dev/null +++ b/images/spin-mqtt-message-logger/.gitignore @@ -0,0 +1,2 @@ +target/ +.spin/ diff --git a/images/spin-mqtt-message-logger/Cargo.toml b/images/spin-mqtt-message-logger/Cargo.toml new file mode 100644 index 00000000..c91da365 --- /dev/null +++ b/images/spin-mqtt-message-logger/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "mqtt-message-logger" +authors = ["Kate Goldenring "] +description = "Triggered by MQTT" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +anyhow = "1" +chrono = "0.4" +spin-mqtt-sdk = { git = "https://github.com/spinkube/spin-trigger-mqtt" } \ No newline at end of file diff --git a/images/spin-mqtt-message-logger/README b/images/spin-mqtt-message-logger/README new file mode 100644 index 00000000..dc3dfd2b --- /dev/null +++ b/images/spin-mqtt-message-logger/README @@ -0,0 +1,60 @@ +# MQTT Message Logger Spin App + +Spin listens to an MQTT broker at a specific topic. It executes the Spin app for each newly published message. The Spin app simply logs the message. + +## Running an MQTT broker + +Download [MQTTX CLI](https://github.com/emqx/MQTTX/tree/main/cli) + +```sh +brew install emqx/mqttx/mqttx-cli +``` + +Run the EMQX broker: https://mqttx.app/docs/get-started + +```sh +docker run -d --name emqx -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqx/emqx +``` + +Connect to locally running broker + +```sh +mqttx conn -h '127.0.0.1' -p 1883 +``` + +Subscribe to the hello topic + +```sh +mqttx sub -t 'hello' -h '127.0.0.1' -p 1883 +``` + +Publish to the hello topic + +```sh +mqttx pub -t 'hello' -h '127.0.0.1' -p 1883 -m 'from me' +``` + + +## Running the spin app to listen to a specific topic + +```sh +SPIN_VARIABLE_MQTT_TOPIC="hello" SPIN_VARIABLE_MQTT_BROKER_URI="mqtt://localhost:1883" spin build --up +``` + +Or use the pushed app: + +```sh +SPIN_VARIABLE_MQTT_TOPIC="hello" SPIN_VARIABLE_MQTT_BROKER_URI="mqtt://localhost:1883" spin up --from ghcr.io/kate-goldenring/mqtt-message-logger:v1 +``` + +Now publish a message to the hello topic: + +```sh +mqttx pub -t 'hello' -h '127.0.0.1' -p 1883 -m 'from me' +``` + +The following should be logged in the `spin build --up` output: + +```sh +"2024-06-07 20:21:32.265317000" Message received by wasm component: 'from me' on topic 'hello' +``` \ No newline at end of file diff --git a/images/spin-mqtt-message-logger/spin.toml b/images/spin-mqtt-message-logger/spin.toml new file mode 100644 index 00000000..4de25c3e --- /dev/null +++ b/images/spin-mqtt-message-logger/spin.toml @@ -0,0 +1,29 @@ +spin_manifest_version = 2 + +[application] +name = "mqtt-message-logger" +version = "0.1.0" +authors = ["Kate Goldenring "] +description = "Triggered by MQTT" + +[variables] +mqtt_topic = { required = true } +mqtt_broker_uri = { required = true } + +[application.trigger.mqtt] +address = "{{ mqtt_broker_uri }}" +username = "" +password = "" +keep_alive_interval = "30" + +[[trigger.mqtt]] +component = "mqtt-message-logger" +topic = "{{ mqtt_topic }}" +qos = "1" + +[component.mqtt-message-logger] +source = "target/wasm32-wasi/release/mqtt_message_logger.wasm" +allowed_outbound_hosts = [] +[component.mqtt-message-logger.build] +command = "cargo build --target wasm32-wasi --release" +watch = ["src/**/*.rs", "Cargo.toml"] \ No newline at end of file diff --git a/images/spin-mqtt-message-logger/src/lib.rs b/images/spin-mqtt-message-logger/src/lib.rs new file mode 100644 index 00000000..c86ef6f4 --- /dev/null +++ b/images/spin-mqtt-message-logger/src/lib.rs @@ -0,0 +1,16 @@ +use chrono::{DateTime, Utc}; +use spin_mqtt_sdk::{mqtt_component, Metadata, Payload}; + +#[mqtt_component] +async fn handle_message(message: Payload, metadata: Metadata) -> anyhow::Result<()> { + let datetime: DateTime = std::time::SystemTime::now().into(); + let formatted_time = datetime.format("%Y-%m-%d %H:%M:%S.%f").to_string(); + + println!( + "{:?} Message received by wasm component: '{}' on topic '{}'", + formatted_time, + String::from_utf8_lossy(&message), + metadata.topic + ); + Ok(()) +} \ No newline at end of file diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 12d573c0..a6239da6 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -20,3 +20,4 @@ http = "1.1" tower = "0.4" hyper = "1.4" redis = { version = "0.25", features = ["tokio-comp"] } +rumqttc = "0.24.0" diff --git a/tests/src/integration_test.rs b/tests/src/integration_test.rs index b25c49db..ce4ecdde 100644 --- a/tests/src/integration_test.rs +++ b/tests/src/integration_test.rs @@ -128,6 +128,60 @@ mod test { Ok(()) } + #[tokio::test] + async fn spin_mqtt_trigger_app_test() -> Result<()> { + use std::time::Duration; + let mqtt_port = 1883; + let message = "MESSAGE"; + let iterations = 5; + + // Ensure kubectl is in PATH + if !is_kubectl_installed().await? { + anyhow::bail!("kubectl is not installed"); + } + + // Port forward the emqx mqtt broker + let forward_port = port_forward_emqx(mqtt_port).await?; + + // Publish a message to the emqx broker + let mut mqttoptions = rumqttc::MqttOptions::new("123", "127.0.0.1", forward_port); + mqttoptions.set_keep_alive(std::time::Duration::from_secs(1)); + + let (client, mut eventloop) = rumqttc::AsyncClient::new(mqttoptions, 10); + client + .subscribe("hello", rumqttc::QoS::AtMostOnce) + .await + .unwrap(); + + // Publish a message several times for redundancy + tokio::task::spawn(async move { + for _i in 0..iterations { + client + .publish( + "hello", + rumqttc::QoS::AtLeastOnce, + false, + message.as_bytes(), + ) + .await + .unwrap(); + tokio::time::sleep(Duration::from_millis(100)).await; + } + }); + tokio::time::sleep(Duration::from_secs(5)).await; + + // Poll the event loop to ensure messages are published + for _i in 0..iterations { + eventloop.poll().await?; + } + thread::sleep(time::Duration::from_secs(5)); + + // Ensure that the message was received and logged by the spin app + let log = get_logs_by_label("app=spin-mqtt-message-logger").await?; + assert!(log.contains(message)); + Ok(()) + } + #[tokio::test] async fn spin_static_assets_test() -> Result<()> { let host_port = 8082; @@ -178,6 +232,32 @@ mod test { Ok(port) } + async fn port_forward_emqx(emqx_port: u16) -> Result { + let port = get_random_port()?; + + println!(" >>> kubectl portforward emqx {}:{} ", port, emqx_port); + + Command::new("kubectl") + .arg("port-forward") + .arg("emqx") + .arg(format!("{}:{}", port, emqx_port)) + .spawn()?; + tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; + Ok(port) + } + + async fn get_logs_by_label(label: &str) -> Result { + let output = Command::new("kubectl") + .arg("logs") + .arg("-l") + .arg(label) + .output() + .await + .context("failed to get logs")?; + let log = std::str::from_utf8(&output.stdout)?; + Ok(log.to_owned()) + } + /// Uses a track to get a random unused port fn get_random_port() -> anyhow::Result { Ok(std::net::TcpListener::bind("localhost:0")? diff --git a/tests/workloads-common/mqtt-broker.yaml b/tests/workloads-common/mqtt-broker.yaml new file mode 100644 index 00000000..4688bc46 --- /dev/null +++ b/tests/workloads-common/mqtt-broker.yaml @@ -0,0 +1,25 @@ +apiVersion: v1 +kind: Pod +metadata: + name: emqx + labels: + app: emqx +spec: + containers: + - name: emqx + image: emqx/emqx + ports: + - containerPort: 1883 +--- +apiVersion: v1 +kind: Service +metadata: + name: emqx +spec: + selector: + app: emqx + ports: + - protocol: TCP + port: 1883 + targetPort: 1883 + type: ClusterIP \ No newline at end of file diff --git a/tests/workloads-pushed-using-spin-registry-push/workloads.yaml b/tests/workloads-pushed-using-spin-registry-push/workloads.yaml index b7dd54cb..e390c3eb 100644 --- a/tests/workloads-pushed-using-spin-registry-push/workloads.yaml +++ b/tests/workloads-pushed-using-spin-registry-push/workloads.yaml @@ -253,4 +253,44 @@ spec: port: 80 targetPort: 80 selector: - app: spin-static-assets \ No newline at end of file + app: spin-static-assets +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: spin-mqtt-message-logger +spec: + replicas: 1 + selector: + matchLabels: + app: spin-mqtt-message-logger + template: + metadata: + labels: + app: spin-mqtt-message-logger + spec: + runtimeClassName: wasmtime-spin + containers: + - name: spin-mqtt-message-logger + image: test-registry:5000/spin-registry-push/spin-mqtt-message-logger:latest + imagePullPolicy: IfNotPresent + command: ["/"] + ports: + - containerPort: 80 + env: + - name: SPIN_VARIABLE_MQTT_TOPIC + value: hello + - name: SPIN_VARIABLE_MQTT_BROKER_URI + value: "mqtt://emqx.default.svc.cluster.local:1883" +--- +apiVersion: v1 +kind: Service +metadata: + name: spin-mqtt-message-logger +spec: + ports: + - protocol: TCP + port: 80 + targetPort: 80 + selector: + app: spin-mqtt-message-logger \ No newline at end of file From d3987e52aada56bb11b9d1a3791557c34ec3b8a8 Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Wed, 21 Aug 2024 11:30:57 -0700 Subject: [PATCH 2/8] Update compile rustflags and cross container for musl builds Signed-off-by: Kate Goldenring --- .cargo/config.toml | 8 ++++++-- Cargo.lock | 3 ++- containerd-shim-spin/Cargo.toml | 4 ++-- cross/Dockerfile | 4 ++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 2b37c758..8fb3aed4 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -3,5 +3,9 @@ strip = "symbols" panic = "abort" [target.aarch64-unknown-linux-musl] -# see https://github.com/fermyon/spin/commit/07db218dccf2d02eb6c8c74d0b39dd2eb59cc4b4 -rustflags = ["-Ctarget-feature=+fp16"] +# see https://github.com/fermyon/spin/pull/2307/files#diff-f6009bd0d260464389ace37ab2f89adae993e1fa4a47f779e4c9859937005ced +rustflags = ["-C", "target-feature=+fp16", "-C", "target-feature=+crt-static", "-C", "link-self-contained=yes"] + +[target.x86_64-unknown-linux-musl] +# see https://github.com/fermyon/spin/pull/2307/files#diff-f6009bd0d260464389ace37ab2f89adae993e1fa4a47f779e4c9859937005ced +rustflags = ["-C", "target-feature=+crt-static", "-C", "link-self-contained=yes"] \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 941d9783..04a1df3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8694,7 +8694,7 @@ dependencies = [ [[package]] name = "trigger-mqtt" version = "0.2.0" -source = "git+https://github.com/kate-goldenring/spin-trigger-mqtt?branch=use-spin-telemetry#4814a09d13bf559079da726c86f710b469cb47d0" +source = "git+https://github.com/spinkube/spin-trigger-mqtt#8d3e0c23dc675df9dcd695f5a4791fe0095e8ca3" dependencies = [ "anyhow", "clap 3.2.25", @@ -8707,6 +8707,7 @@ dependencies = [ "spin-telemetry", "spin-trigger", "tokio", + "tracing", "wasmtime", ] diff --git a/containerd-shim-spin/Cargo.toml b/containerd-shim-spin/Cargo.toml index c63ef9ad..f852a84d 100644 --- a/containerd-shim-spin/Cargo.toml +++ b/containerd-shim-spin/Cargo.toml @@ -21,12 +21,12 @@ spin-componentize = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } spin-trigger = { git = "https://github.com/fermyon/spin", tag = "v2.6.0", features = ["unsafe-aot-compilation"] } spin-trigger-http = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } spin-trigger-redis = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } -trigger-mqtt = { git = "https://github.com/kate-goldenring/spin-trigger-mqtt", branch = "use-spin-telemetry" } +trigger-mqtt = { git = "https://github.com/spinkube/spin-trigger-mqtt", ref = "8d3e0c23dc675df9dcd695f5a4791fe0095e8ca3" } trigger-sqs = { git = "https://github.com/fermyon/spin-trigger-sqs", rev = "v0.7.0" } trigger-command = { git = "https://github.com/fermyon/spin-trigger-command", tag = "v0.1.0" } spin-manifest = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } spin-loader = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } -spin-oci = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } +spin-oci = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } spin-common = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } spin-expressions = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } spin-telemetry = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } diff --git a/cross/Dockerfile b/cross/Dockerfile index e4dcb9aa..6e079160 100644 --- a/cross/Dockerfile +++ b/cross/Dockerfile @@ -17,5 +17,9 @@ RUN apk-${MARCH} add zlib-dev zlib-static # See https://github.com/fermyon/spin/issues/1786 for the upstream issue requiring this polyfill. RUN --mount=type=bind,from=jorgeprendes420/gcc_vld1q_s8_x4_polyfill,source=/polyfill.sh,target=/polyfill.sh /polyfill.sh +## as per analysis done in https://github.com/fermyon/spin/pull/2287#issuecomment-1970145410 we need +## to disable the cmake config in cross-rs. Setting CROSS_SYSROOT=/ seems to have done the trick +ENV CROSS_SYSROOT=/ + RUN apt-get -y update && \ apt-get install -y pkg-config protobuf-compiler From 32c8e9feb10c94e35a35440bf76ed34ecea64dbe Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Wed, 21 Aug 2024 12:35:43 -0700 Subject: [PATCH 3/8] Add MQTT logging app to prepared apps Signed-off-by: Kate Goldenring --- images/spin-mqtt-message-logger/Cargo.lock | 734 +++++++++++++++++++++ images/spin-mqtt-message-logger/Cargo.toml | 4 +- scripts/up.sh | 14 +- 3 files changed, 745 insertions(+), 7 deletions(-) create mode 100644 images/spin-mqtt-message-logger/Cargo.lock diff --git a/images/spin-mqtt-message-logger/Cargo.lock b/images/spin-mqtt-message-logger/Cargo.lock new file mode 100644 index 00000000..78669c34 --- /dev/null +++ b/images/spin-mqtt-message-logger/Cargo.lock @@ -0,0 +1,734 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "cc" +version = "1.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.75", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mqtt-message-logger" +version = "0.1.0" +dependencies = [ + "anyhow", + "chrono", + "spin-mqtt-sdk", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.208" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.208" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.75", +] + +[[package]] +name = "serde_json" +version = "1.0.125" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "spdx" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47317bbaf63785b53861e1ae2d11b80d6b624211d42cb20efcd210ee6f8a14bc" +dependencies = [ + "smallvec", +] + +[[package]] +name = "spin-executor" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2df1a5e2cc70a628c9ea6914770c234cc4a292218091e6707ae8be68b4a5de76" +dependencies = [ + "futures", + "once_cell", + "wit-bindgen", +] + +[[package]] +name = "spin-mqtt-macro" +version = "0.2.0" +source = "git+https://github.com/spinkube/spin-trigger-mqtt#8d3e0c23dc675df9dcd695f5a4791fe0095e8ca3" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "wit-bindgen", +] + +[[package]] +name = "spin-mqtt-sdk" +version = "0.2.0" +source = "git+https://github.com/spinkube/spin-trigger-mqtt#8d3e0c23dc675df9dcd695f5a4791fe0095e8ca3" +dependencies = [ + "spin-executor", + "spin-mqtt-macro", + "wit-bindgen", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "unicode-xid" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.75", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.75", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "wasm-encoder" +version = "0.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad2b51884de9c7f4fe2fd1043fccb8dcad4b1e29558146ee57a144d15779f3f" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-encoder" +version = "0.41.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "972f97a5d8318f908dded23594188a90bcd09365986b1163e66d70170e5287ae" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-metadata" +version = "0.10.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18ebaa7bd0f9e7a5e5dd29b9a998acf21c4abed74265524dd7e85934597bfb10" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder 0.41.2", + "wasmparser 0.121.2", +] + +[[package]] +name = "wasmparser" +version = "0.118.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77f1154f1ab868e2a01d9834a805faca7bf8b50d041b4ca714d005d0dab1c50c" +dependencies = [ + "indexmap", + "semver", +] + +[[package]] +name = "wasmparser" +version = "0.121.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dbe55c8f9d0dbd25d9447a5a889ff90c0cc3feaa7395310d3d826b2c703eaab" +dependencies = [ + "bitflags", + "indexmap", + "semver", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wit-bindgen" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b76f1d099678b4f69402a421e888bbe71bf20320c2f3f3565d0e7484dbe5bc20" +dependencies = [ + "bitflags", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75d55e1a488af2981fb0edac80d8d20a51ac36897a1bdef4abde33c29c1b6d0d" +dependencies = [ + "anyhow", + "wit-component", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01ff9cae7bf5736750d94d91eb8a49f5e3a04aff1d1a3218287d9b2964510f8" +dependencies = [ + "anyhow", + "heck", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "804a98e2538393d47aa7da65a7348116d6ff403b426665152b70a168c0146d49" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.75", + "wit-bindgen-core", + "wit-bindgen-rust", + "wit-component", +] + +[[package]] +name = "wit-component" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a35a2a9992898c9d27f1664001860595a4bc99d32dd3599d547412e17d7e2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder 0.38.1", + "wasm-metadata", + "wasmparser 0.118.2", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "316b36a9f0005f5aa4b03c39bc3728d045df136f8c13a73b7db4510dec725e08" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", +] diff --git a/images/spin-mqtt-message-logger/Cargo.toml b/images/spin-mqtt-message-logger/Cargo.toml index c91da365..9af9d3e2 100644 --- a/images/spin-mqtt-message-logger/Cargo.toml +++ b/images/spin-mqtt-message-logger/Cargo.toml @@ -11,4 +11,6 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1" chrono = "0.4" -spin-mqtt-sdk = { git = "https://github.com/spinkube/spin-trigger-mqtt" } \ No newline at end of file +spin-mqtt-sdk = { git = "https://github.com/spinkube/spin-trigger-mqtt" } + +[workspace] \ No newline at end of file diff --git a/scripts/up.sh b/scripts/up.sh index 3da0bd94..75d2ed66 100755 --- a/scripts/up.sh +++ b/scripts/up.sh @@ -5,9 +5,9 @@ set -euo pipefail cluster_name="test-cluster" # name of the k3d cluster dockerfile_path="deployments/k3d" # path to the Dockerfile -DOCKER_IMAGES=("spin" "spin-keyvalue" "spin-outbound-redis" "spin-multi-trigger-app" "spin-static-assets") +DOCKER_IMAGES=("spin" "spin-keyvalue" "spin-outbound-redis" "spin-multi-trigger-app" "spin-static-assets" "spin-mqtt-message-logger") OUT_DIRS=("test/out_spin" "test/out_spin_keyvalue" "test/out_spin_outbound_redis" "test/out_spin_multi_trigger_app" "test/out_spin_static_assets") -IMAGES=("spin-hello-world" "spin-keyvalue" "spin-outbound-redis" "spin-multi-trigger-app" "spin-static-assets") +IMAGES=("spin-hello-world" "spin-keyvalue" "spin-outbound-redis" "spin-multi-trigger-app" "spin-static-assets" "spin-mqtt-message-logger") # build the Docker image for the k3d cluster docker build -t k3d-shim-test "$dockerfile_path" @@ -20,10 +20,12 @@ kubectl wait --for=condition=ready node --all --timeout=120s # Iterate through the Docker images and build them for i in "${!DOCKER_IMAGES[@]}"; do - docker buildx build -t "${IMAGES[$i]}:latest" "./images/${DOCKER_IMAGES[$i]}" --load - mkdir -p "${OUT_DIRS[$i]}" - docker save -o "${OUT_DIRS[$i]}/img.tar" "${IMAGES[$i]}:latest" - k3d image import "${OUT_DIRS[$i]}/img.tar" -c "$cluster_name" + if [ -f "./images/${DOCKER_IMAGES[$i]}/Dockerfile" ]; then + docker buildx build -t "${IMAGES[$i]}:latest" "./images/${DOCKER_IMAGES[$i]}" --load + mkdir -p "${OUT_DIRS[$i]}" + docker save -o "${OUT_DIRS[$i]}/img.tar" "${IMAGES[$i]}:latest" + k3d image import "${OUT_DIRS[$i]}/img.tar" -c "$cluster_name" + fi ## also do spin builds and spin registry push ## images pushed as localhost:5000//: From f8cd881ef980f296ca5ebfacc1003be4282bc5c0 Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Wed, 21 Aug 2024 14:34:13 -0700 Subject: [PATCH 4/8] Use cluster IP for MQTT broker address for Spin app trigger Signed-off-by: Kate Goldenring --- scripts/deploy-workloads.sh | 13 ++++++++++++- .../workloads.yaml | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/deploy-workloads.sh b/scripts/deploy-workloads.sh index 245e9b6e..a9de4dde 100755 --- a/scripts/deploy-workloads.sh +++ b/scripts/deploy-workloads.sh @@ -9,11 +9,21 @@ if ! command -v kubectl &> /dev/null; then sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl; fi +update_mqtt_workload_with_broker_cluster_ip() { + # The MQTT trigger cannot do DNS resolution, so we need to use the IP address of the MQTT broker + # Replace "EMQX_CLUSTER_IP" with the actual ClusterIP of the EMQX service + local cluster_ip=$(kubectl get svc emqx -o jsonpath='{.spec.clusterIP}') + sed -i "s/EMQX_CLUSTER_IP/$cluster_ip/g" tests/workloads-pushed-using-spin-registry-push/workloads.yaml + echo "Updated workloads.yaml with ClusterIP: $cluster_ip" +} + + # apply the workloads echo ">>> apply workloads" kubectl apply -f tests/workloads-common if [ "$1" == "workloads-pushed-using-spin-registry-push" ]; then + update_mqtt_workload_with_broker_cluster_ip echo "deploying spin apps pushed to registry using 'spin registry push' command" kubectl apply -f tests/workloads-pushed-using-spin-registry-push else @@ -37,4 +47,5 @@ kubectl describe deployments # get and describe all the services echo ">>> Services:" kubectl get services -o wide -kubectl describe services \ No newline at end of file +kubectl describe services + diff --git a/tests/workloads-pushed-using-spin-registry-push/workloads.yaml b/tests/workloads-pushed-using-spin-registry-push/workloads.yaml index e390c3eb..ff08ad8d 100644 --- a/tests/workloads-pushed-using-spin-registry-push/workloads.yaml +++ b/tests/workloads-pushed-using-spin-registry-push/workloads.yaml @@ -280,14 +280,17 @@ spec: env: - name: SPIN_VARIABLE_MQTT_TOPIC value: hello + # The MQTT trigger cannot do DNS resolution, so we need to use the IP address of the MQTT broker + # Substitute `EMQX_CLUSTER_IP` with the result of `kubectl get svc emqx -n default -o jsonpath='{.spec.clusterIP}'` - name: SPIN_VARIABLE_MQTT_BROKER_URI - value: "mqtt://emqx.default.svc.cluster.local:1883" + value: "mqtt://EMQX_CLUSTER_IP:1883" --- apiVersion: v1 kind: Service metadata: name: spin-mqtt-message-logger spec: + type: LoadBalancer ports: - protocol: TCP port: 80 From 6a13b1662cf2cb28c601b05a2ee1d1653c640c23 Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Wed, 21 Aug 2024 19:40:21 -0700 Subject: [PATCH 5/8] Add MQTT test app to Dockerfile tests and increase pod deletion timeout for tests Signed-off-by: Kate Goldenring --- images/spin-mqtt-message-logger/Dockerfile | 8 ++++ scripts/deploy-workloads.sh | 6 ++- scripts/pod-terminates-test.sh | 9 ++-- scripts/up.sh | 2 - .../workloads.yaml | 43 +++++++++++++++++++ 5 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 images/spin-mqtt-message-logger/Dockerfile diff --git a/images/spin-mqtt-message-logger/Dockerfile b/images/spin-mqtt-message-logger/Dockerfile new file mode 100644 index 00000000..352ec926 --- /dev/null +++ b/images/spin-mqtt-message-logger/Dockerfile @@ -0,0 +1,8 @@ +FROM --platform=${BUILDPLATFORM} rust:1.72 AS build +WORKDIR /opt/build +COPY . . +RUN rustup target add wasm32-wasi && cargo build --target wasm32-wasi --release + +FROM scratch +COPY --from=build /opt/build/target/wasm32-wasi/release/mqtt_message_logger.wasm ./target/wasm32-wasi/release/mqtt_message_logger.wasm +COPY --from=build /opt/build/spin.toml . \ No newline at end of file diff --git a/scripts/deploy-workloads.sh b/scripts/deploy-workloads.sh index a9de4dde..d865140c 100755 --- a/scripts/deploy-workloads.sh +++ b/scripts/deploy-workloads.sh @@ -10,10 +10,11 @@ if ! command -v kubectl &> /dev/null; then fi update_mqtt_workload_with_broker_cluster_ip() { + local dir=$1 # The MQTT trigger cannot do DNS resolution, so we need to use the IP address of the MQTT broker # Replace "EMQX_CLUSTER_IP" with the actual ClusterIP of the EMQX service local cluster_ip=$(kubectl get svc emqx -o jsonpath='{.spec.clusterIP}') - sed -i "s/EMQX_CLUSTER_IP/$cluster_ip/g" tests/workloads-pushed-using-spin-registry-push/workloads.yaml + sed -i "s/EMQX_CLUSTER_IP/$cluster_ip/g" $dir/workloads.yaml echo "Updated workloads.yaml with ClusterIP: $cluster_ip" } @@ -23,10 +24,11 @@ echo ">>> apply workloads" kubectl apply -f tests/workloads-common if [ "$1" == "workloads-pushed-using-spin-registry-push" ]; then - update_mqtt_workload_with_broker_cluster_ip + update_mqtt_workload_with_broker_cluster_ip "tests/workloads-pushed-using-spin-registry-push" echo "deploying spin apps pushed to registry using 'spin registry push' command" kubectl apply -f tests/workloads-pushed-using-spin-registry-push else + update_mqtt_workload_with_broker_cluster_ip "tests/workloads-pushed-using-docker-build-push" echo "deploying spin apps pushed to registry using 'docker build && k3d image import' command" kubectl apply -f tests/workloads-pushed-using-docker-build-push fi diff --git a/scripts/pod-terminates-test.sh b/scripts/pod-terminates-test.sh index 33265da4..942b17cb 100755 --- a/scripts/pod-terminates-test.sh +++ b/scripts/pod-terminates-test.sh @@ -3,8 +3,9 @@ set -euo pipefail ## test that the workload pods can be terminated -kubectl delete pod -l app=wasm-spin --timeout 10s -kubectl delete pod -l app=spin-keyvalue --timeout 10s -kubectl delete pod -l app=spin-outbound-redis --timeout 10s -kubectl delete pod -l app=spin-multi-trigger-app --timeout 10s +kubectl delete pod -l app=wasm-spin --timeout 20s +kubectl delete pod -l app=spin-keyvalue --timeout 20s +kubectl delete pod -l app=spin-outbound-redis --timeout 20s +kubectl delete pod -l app=spin-multi-trigger-app --timeout 20s +kubectl delete pod -l app=spin-mqtt-message-logger --timeout 20s diff --git a/scripts/up.sh b/scripts/up.sh index 75d2ed66..096cf826 100755 --- a/scripts/up.sh +++ b/scripts/up.sh @@ -20,12 +20,10 @@ kubectl wait --for=condition=ready node --all --timeout=120s # Iterate through the Docker images and build them for i in "${!DOCKER_IMAGES[@]}"; do - if [ -f "./images/${DOCKER_IMAGES[$i]}/Dockerfile" ]; then docker buildx build -t "${IMAGES[$i]}:latest" "./images/${DOCKER_IMAGES[$i]}" --load mkdir -p "${OUT_DIRS[$i]}" docker save -o "${OUT_DIRS[$i]}/img.tar" "${IMAGES[$i]}:latest" k3d image import "${OUT_DIRS[$i]}/img.tar" -c "$cluster_name" - fi ## also do spin builds and spin registry push ## images pushed as localhost:5000//: diff --git a/tests/workloads-pushed-using-docker-build-push/workloads.yaml b/tests/workloads-pushed-using-docker-build-push/workloads.yaml index db5256e9..b657e543 100644 --- a/tests/workloads-pushed-using-docker-build-push/workloads.yaml +++ b/tests/workloads-pushed-using-docker-build-push/workloads.yaml @@ -254,3 +254,46 @@ spec: targetPort: 80 selector: app: spin-static-assets +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: spin-mqtt-message-logger +spec: + replicas: 1 + selector: + matchLabels: + app: spin-mqtt-message-logger + template: + metadata: + labels: + app: spin-mqtt-message-logger + spec: + runtimeClassName: wasmtime-spin + containers: + - name: spin-mqtt-message-logger + image: docker.io/library/spin-mqtt-message-logger:latest + imagePullPolicy: IfNotPresent + command: ["/"] + ports: + - containerPort: 80 + env: + - name: SPIN_VARIABLE_MQTT_TOPIC + value: hello + # The MQTT trigger cannot do DNS resolution, so we need to use the IP address of the MQTT broker + # Substitute `EMQX_CLUSTER_IP` with the result of `kubectl get svc emqx -n default -o jsonpath='{.spec.clusterIP}'` + - name: SPIN_VARIABLE_MQTT_BROKER_URI + value: "mqtt://EMQX_CLUSTER_IP:1883" +--- +apiVersion: v1 +kind: Service +metadata: + name: spin-mqtt-message-logger +spec: + type: LoadBalancer + ports: + - protocol: TCP + port: 80 + targetPort: 80 + selector: + app: spin-mqtt-message-logger From 14faa20030c36e49ef9805df3ce57c0ba38ddbd4 Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Wed, 21 Aug 2024 19:45:17 -0700 Subject: [PATCH 6/8] Pin MQTT trigger version Signed-off-by: Kate Goldenring --- Cargo.lock | 2 +- containerd-shim-spin/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04a1df3b..cecfa779 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8694,7 +8694,7 @@ dependencies = [ [[package]] name = "trigger-mqtt" version = "0.2.0" -source = "git+https://github.com/spinkube/spin-trigger-mqtt#8d3e0c23dc675df9dcd695f5a4791fe0095e8ca3" +source = "git+https://github.com/spinkube/spin-trigger-mqtt?tag=v0.2.0#a9a4107fe6fa03afe329340ed3e087ce41b1c9a9" dependencies = [ "anyhow", "clap 3.2.25", diff --git a/containerd-shim-spin/Cargo.toml b/containerd-shim-spin/Cargo.toml index f852a84d..fe457475 100644 --- a/containerd-shim-spin/Cargo.toml +++ b/containerd-shim-spin/Cargo.toml @@ -21,7 +21,7 @@ spin-componentize = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } spin-trigger = { git = "https://github.com/fermyon/spin", tag = "v2.6.0", features = ["unsafe-aot-compilation"] } spin-trigger-http = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } spin-trigger-redis = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } -trigger-mqtt = { git = "https://github.com/spinkube/spin-trigger-mqtt", ref = "8d3e0c23dc675df9dcd695f5a4791fe0095e8ca3" } +trigger-mqtt = { git = "https://github.com/spinkube/spin-trigger-mqtt", tag = "v0.2.0" } trigger-sqs = { git = "https://github.com/fermyon/spin-trigger-sqs", rev = "v0.7.0" } trigger-command = { git = "https://github.com/fermyon/spin-trigger-command", tag = "v0.1.0" } spin-manifest = { git = "https://github.com/fermyon/spin", tag = "v2.6.0" } From 3ee6dfcfb16363045d8cb6f8aaf766de49f30532 Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Thu, 22 Aug 2024 07:27:13 -0700 Subject: [PATCH 7/8] Bump rust version for MQTT test app Dockerfile Signed-off-by: Kate Goldenring --- images/spin-mqtt-message-logger/Dockerfile | 2 +- scripts/up.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/images/spin-mqtt-message-logger/Dockerfile b/images/spin-mqtt-message-logger/Dockerfile index 352ec926..4463655d 100644 --- a/images/spin-mqtt-message-logger/Dockerfile +++ b/images/spin-mqtt-message-logger/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=${BUILDPLATFORM} rust:1.72 AS build +FROM --platform=${BUILDPLATFORM} rust:1.73 AS build WORKDIR /opt/build COPY . . RUN rustup target add wasm32-wasi && cargo build --target wasm32-wasi --release diff --git a/scripts/up.sh b/scripts/up.sh index 096cf826..51777f76 100755 --- a/scripts/up.sh +++ b/scripts/up.sh @@ -6,7 +6,7 @@ cluster_name="test-cluster" # name of the k3d cluster dockerfile_path="deployments/k3d" # path to the Dockerfile DOCKER_IMAGES=("spin" "spin-keyvalue" "spin-outbound-redis" "spin-multi-trigger-app" "spin-static-assets" "spin-mqtt-message-logger") -OUT_DIRS=("test/out_spin" "test/out_spin_keyvalue" "test/out_spin_outbound_redis" "test/out_spin_multi_trigger_app" "test/out_spin_static_assets") +OUT_DIRS=("test/out_spin" "test/out_spin_keyvalue" "test/out_spin_outbound_redis" "test/out_spin_multi_trigger_app" "test/out_spin_static_assets" "test/out_spin_mqtt_message_logger") IMAGES=("spin-hello-world" "spin-keyvalue" "spin-outbound-redis" "spin-multi-trigger-app" "spin-static-assets" "spin-mqtt-message-logger") # build the Docker image for the k3d cluster From 488eecb33fa1a2b3b2f1a1fc7ee0f36aefd112f5 Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Thu, 22 Aug 2024 14:35:17 -0700 Subject: [PATCH 8/8] Update workloads deployment to fix indentation Signed-off-by: Kate Goldenring --- scripts/deploy-workloads.sh | 2 ++ tests/workloads-pushed-using-docker-build-push/workloads.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/deploy-workloads.sh b/scripts/deploy-workloads.sh index d865140c..926da903 100755 --- a/scripts/deploy-workloads.sh +++ b/scripts/deploy-workloads.sh @@ -11,6 +11,8 @@ fi update_mqtt_workload_with_broker_cluster_ip() { local dir=$1 + echo "Waiting for emqx pod to be ready" + kubectl wait --for=condition=ready --timeout=20s pod/emqx # The MQTT trigger cannot do DNS resolution, so we need to use the IP address of the MQTT broker # Replace "EMQX_CLUSTER_IP" with the actual ClusterIP of the EMQX service local cluster_ip=$(kubectl get svc emqx -o jsonpath='{.spec.clusterIP}') diff --git a/tests/workloads-pushed-using-docker-build-push/workloads.yaml b/tests/workloads-pushed-using-docker-build-push/workloads.yaml index b657e543..ccac9a57 100644 --- a/tests/workloads-pushed-using-docker-build-push/workloads.yaml +++ b/tests/workloads-pushed-using-docker-build-push/workloads.yaml @@ -271,7 +271,7 @@ spec: spec: runtimeClassName: wasmtime-spin containers: - - name: spin-mqtt-message-logger + - name: spin-mqtt-message-logger image: docker.io/library/spin-mqtt-message-logger:latest imagePullPolicy: IfNotPresent command: ["/"]