43 lines
1.2 KiB
Bash
Raw Normal View History

2019-08-16 19:14:27 +03:00
#!/usr/bin/env bash
set -e
2019-08-18 16:05:11 +03:00
set -o pipefail
2019-08-16 19:14:27 +03:00
mkdir -p wasm
# Build fluid WASM module
2019-08-18 13:59:06 +03:00
echo "Building to WASM..."
2019-08-16 19:14:27 +03:00
npm --silent install
npm --quiet run flbuild
2019-08-16 19:32:49 +03:00
cp build/fluid.wasm ./wasm/
2019-08-16 19:14:27 +03:00
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
# 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
)
echo -e "Sending request... $JSON"
# Send json as a request, and receive result
2019-08-18 13:48:45 +03:00
RESPONSE=$(curl -s 'http://localhost:30000/apps/0/tx' --data $'sessionId/0\n'"$JSON" --compressed)
RESPONSE=$(echo "$RESPONSE" | jq -r .result.data | base64 --decode 2>/dev/null || echo "$RESPONSE")
2019-08-16 19:14:27 +03:00
# Parse json or print response as is
echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE"
# Remove frun container
echo -e "Stopping..."
docker rm -f frun >/dev/null