add fluence cli packaging, update records (#423)

* add packaging script

* add packaged module

* add packaging script

* add package

* add package script

* add package

* add package script

* add service package

* update figure 1

* add packaged modules

* update records module types

* add packaging script

* add packaedmodule

* add flunce cli reference

* Update marine-examples/README.md

Co-authored-by: Valery Antopol <valery.antopol@gmail.com>

* add newline

* add newline

* add newline

* add newline

* update module order

* update module name

---------

Co-authored-by: Valery Antopol <valery.antopol@gmail.com>
This commit is contained in:
boneyard93501 2023-02-22 11:14:01 -06:00 committed by GitHub
parent 9178a8271c
commit 440b3c3137
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 216 additions and 53 deletions

View File

@ -10,6 +10,7 @@ Figure 1: Module And Service Creation With The Marine Toolchain
```mermaid
stateDiagram
state "Rust Marine Code" as Code
state "Build wasm32-wasi Module" as Build
state "Test Wasm App With Cargo" as Test
@ -26,9 +27,10 @@ Figure 1: Module And Service Creation With The Marine Toolchain
Build --> Test
Build --> Deploy
Service --> Deploy
```
Wasm modules can also be accessed locally through the Marine REPL and tested with `cargo test`.
Wasm modules can also be accessed locally through the Marine REPL and tested with `cargo test`. Moreover, most of the examples listed below have a packaging script providing modules in the archived format, i.e., tar.gz, for easy import into [fluence cli](https://github.com/fluencelabs/fluence-cli) projects.
## Greeting Example

View File

@ -0,0 +1,18 @@
mkdir -p module-exports/modules/call_parameters
sh ./build.sh
cd module-exports
cp ../target/wasm32-wasi/release/call_parameters.wasm modules/call_parameters/
file="modules/call_parameters/module.yaml"
cat > $file <<- EOF
version: 0
name: call_parameters
loggerEnabled: true
EOF
tar -czf call_parameters.tar.gz modules
rm -r modules
cd ../
cargo clean

View File

@ -0,0 +1,19 @@
mkdir -p module-exports/modules/greeting
sh ./build.sh
cd module-exports
cp ../target/wasm32-wasi/release/greeting.wasm modules/greeting/
file="modules/greeting/module.yaml"
cat > $file <<- EOF
version: 0
name: local_storage
loggerEnabled: true
EOF
tar -czvf greeting.tar.gz modules
rm -r modules
cd ../
cargo clean

View File

@ -1,11 +1,11 @@
modules_dir = "artifacts/"
[[module]]
name = "records_effector"
max_heap_size = "10 KiB"
logger_enabled = true
[[module]]
name = "records_pure"
max_heap_size = "10 KiB"
logger_enabled = true
[[module]]
name = "records_facade"
max_heap_size = "10 KiB"
logger_enabled = true

View File

@ -2,17 +2,15 @@
set -o errexit -o nounset -o pipefail
# This script builds all subprojects and puts all created Wasm modules in one dir
cd effector
cargo update --aggressive
cd pure
marine build --release
cd ../pure
cargo update --aggressive
cd ../facade
marine build --release
cd ..
mkdir -p artifacts
rm -f artifacts/*.wasm
cp effector/target/wasm32-wasi/release/records_effector.wasm artifacts/
cp pure/target/wasm32-wasi/release/records_pure.wasm artifacts/
cp facade/target/wasm32-wasi/release/records_facade.wasm artifacts/

View File

@ -1,12 +1,12 @@
[package]
name = "record-effector"
name = "record-facade"
version = "0.1.0"
authors = ["Fluence Labs"]
edition = "2018"
publish = false
[[bin]]
name = "records_effector"
name = "records_facade"
path = "src/main.rs"
[dependencies]

View File

@ -14,6 +14,8 @@
* limitations under the License.
*/
#![allow(improper_ctypes)]
use marine_rs_sdk::marine;
use marine_rs_sdk::module_manifest;
@ -24,20 +26,28 @@ module_manifest!();
pub fn main() {}
#[marine]
pub fn mutate_struct(mut test_record: test_record::TestRecord) -> TestRecord {
test_record.field_0 = true;
test_record.field_1 = 1;
test_record.field_2 = 2;
test_record.field_3 = 3;
test_record.field_4 = 4;
test_record.field_5 = 5;
test_record.field_6 = 6;
test_record.field_7 = 7;
test_record.field_8 = 8;
test_record.field_9 = 9f32;
test_record.field_10 = 10f64;
test_record.field_11 = "field_11".to_string();
test_record.field_12 = vec![0x13, 0x37];
pub fn invoke() -> TestRecord {
let test_record = TestRecord {
field_0: false,
field_1: 0,
field_2: 0,
field_3: 0,
field_4: 0,
field_5: 0,
field_6: 0,
field_7: 0,
field_8: 0,
field_9: 0f32,
field_10: 0f64,
field_11: String::new(),
field_12: Vec::new(),
};
test_record
mutate_struct(test_record)
}
#[marine]
#[link(wasm_import_module = "records_pure")]
extern "C" {
pub fn mutate_struct(test_record: TestRecord) -> TestRecord;
}

Binary file not shown.

View File

@ -0,0 +1,45 @@
mkdir -p module-exports/modules/facade
mkdir -p module-exports/modules/pure
sh ./build.sh
cd module-exports
cp ../facade/target/wasm32-wasi/release/records_facade.wasm modules/facade/
cp ../pure/target/wasm32-wasi/release/records_pure.wasm modules/pure/
file="service.yaml"
cat > $file <<- EOF
version: 0
name: records
modules:
pure:
get: modules/facade
effector:
get: modules/pure
EOF
file="modules/facade/module.yaml"
cat > $file <<- EOF
version: 0
name: facade
loggerEnabled: true
EOF
file="modules/pure/module.yaml"
cat > $file <<- EOF
version: 0
name: pure
loggerEnabled: true
EOF
tar -czf records.tar.gz modules service.yaml
rm -r modules
rm service.yaml
cd ../facade
cargo clean
pwd
cd ../pure
cargo clean

View File

@ -14,8 +14,6 @@
* limitations under the License.
*/
#![allow(improper_ctypes)]
use marine_rs_sdk::marine;
use marine_rs_sdk::module_manifest;
@ -26,28 +24,20 @@ module_manifest!();
pub fn main() {}
#[marine]
pub fn invoke() -> TestRecord {
let test_record = TestRecord {
field_0: false,
field_1: 0,
field_2: 0,
field_3: 0,
field_4: 0,
field_5: 0,
field_6: 0,
field_7: 0,
field_8: 0,
field_9: 0f32,
field_10: 0f64,
field_11: String::new(),
field_12: Vec::new(),
};
pub fn mutate_struct(mut test_record: test_record::TestRecord) -> TestRecord {
test_record.field_0 = true;
test_record.field_1 = 1;
test_record.field_2 = 2;
test_record.field_3 = 3;
test_record.field_4 = 4;
test_record.field_5 = 5;
test_record.field_6 = 6;
test_record.field_7 = 7;
test_record.field_8 = 8;
test_record.field_9 = 9f32;
test_record.field_10 = 10f64;
test_record.field_11 = "field_11".to_string();
test_record.field_12 = vec![0x13, 0x37];
mutate_struct(test_record)
}
#[marine]
#[link(wasm_import_module = "records_effector")]
extern "C" {
pub fn mutate_struct(test_record: TestRecord) -> TestRecord;
test_record
}

Binary file not shown.

View File

@ -0,0 +1,19 @@
mkdir -p module-exports/modules/sqlite
sh ./build.sh
cd module-exports
cp ../artifacts/sqlite3.wasm modules/sqlite/
file="modules/sqlite/module.yaml"
cat > $file <<- EOF
version: 0
name: sqlite
loggerEnabled: true
EOF
tar -czvf sqlite.tar.gz modules
rm -r modules
cd ../
cargo clean

View File

@ -0,0 +1,62 @@
mkdir -p module-exports/modules/curl_adapter
mkdir -p module-exports/modules/facade
mkdir -p module-exports/modules/local_storage
sh ./build.sh
cd module-exports
cp ../curl_adapter/target/wasm32-wasi/release/curl_adapter.wasm modules/curl_adapter/
cp ../facade/target/wasm32-wasi/release/facade.wasm modules/facade/
cp ../local_storage/target/wasm32-wasi/release/local_storage.wasm modules/local_storage/
file="service.yaml"
cat > $file <<- EOF
version: 0
name: urlDownloader
modules:
facade:
get: modules/facade
localStorage:
get: modules/local_storage
curlAdapter:
get: modules/curl_adapter
EOF
file="modules/curl_adapter/module.yaml"
cat > $file <<- EOF
version: 0
name: curl_adapter
loggerEnabled: true
mountedBinaries:
curl: /usr/bin/curl
EOF
file="modules/local_storage/module.yaml"
cat > $file <<- EOF
version: 0
name: local_storage
loggerEnabled: true
volumes:
sites: ./tmp
EOF
file="modules/facade/module.yaml"
cat > $file <<- EOF
version: 0
name: facade
loggerEnabled: true
EOF
tar -czf url_downloader.tar.gz modules service.yaml
rm -r modules
rm service.yaml
cd ../facade
cargo clean
pwd
cd ../curl_adapter
cargo clean
cd ../local_storage
cargo clean