mirror of
https://github.com/fluencelabs/fluid
synced 2025-06-23 01:51:32 +00:00
WIP
This commit is contained in:
46
backend-rust/step2-database-only/run.sh
Executable file
46
backend-rust/step2-database-only/run.sh
Executable file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
mkdir -p wasm
|
||||
|
||||
SQLITE="sqlite3_0.2.0.wasm"
|
||||
if [ ! -f "wasm/$SQLITE" ]; then
|
||||
echo "Downloading $SQLITE..."
|
||||
wget -q https://github.com/fluencelabs/sqlite/releases/download/v0.2.0_w/$SQLITE -O ./wasm/$SQLITE
|
||||
fi
|
||||
|
||||
# Build fluid WASM module
|
||||
echo "Building..."
|
||||
cargo +nightly build --target wasm32-unknown-unknown --release >/dev/null
|
||||
cp target/wasm32-unknown-unknown/release/*.wasm ./wasm/
|
||||
echo
|
||||
|
||||
# Run it all on 30000 port with default Fluence API
|
||||
echo "Running..."
|
||||
docker rm -f frun &>/dev/null || true
|
||||
echo 'docker run -d --name frun --rm -v "$(pwd)/wasm:/code" -p 30000:30000 fluencelabs/frun:latest'
|
||||
docker run -d --name frun --rm -v "$(pwd)/wasm:/code" -p 30000:30000 fluencelabs/frun:latest >/dev/null
|
||||
echo
|
||||
|
||||
# Wait for app to be initialized
|
||||
sleep 1 && (docker logs -f frun 2>&1 &) | grep -q initialized && sleep 1
|
||||
|
||||
# Send our username to the application
|
||||
echo -e "Sending request..."
|
||||
|
||||
# Assign json to a variable using heredoc technique
|
||||
JSON=$(cat <<JSON
|
||||
{"action":"Post","message":"I'm nice, you're nice, it's nice!","username":"random_joe"}
|
||||
JSON
|
||||
)
|
||||
|
||||
# Send json as a request, and receive result
|
||||
RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$JSON" --compressed | jq -r .result.data | base64 -D)
|
||||
|
||||
# Parse result as JSON and print to console
|
||||
echo -e "$RESPONSE" | jq .
|
||||
|
||||
# Remove frun container
|
||||
echo -e "Stopping..."
|
||||
docker rm -f frun >/dev/null
|
@ -1,6 +1,7 @@
|
||||
use log;
|
||||
|
||||
use crate::api::AppResult;
|
||||
use crate::errors::AppResult;
|
||||
|
||||
use crate::errors::err_msg;
|
||||
use crate::ffi;
|
||||
|
||||
|
@ -14,3 +14,5 @@ impl fmt::Display for Error {
|
||||
pub fn err_msg(s: &str) -> Box<Error> {
|
||||
Error(s.to_string()).into()
|
||||
}
|
||||
|
||||
pub type AppResult<T> = ::std::result::Result<T, Box<Error>>;
|
||||
|
@ -1,11 +1,4 @@
|
||||
use fluence::sdk::*;
|
||||
use serde_json::value::RawValue;
|
||||
|
||||
use api::Request;
|
||||
use api::Response;
|
||||
|
||||
use crate::api::AppResult;
|
||||
use crate::errors::err_msg;
|
||||
|
||||
pub mod database;
|
||||
pub mod errors;
|
||||
|
Reference in New Issue
Block a user