From c25674f79c75c703ef6708141f2da3422e97ca01 Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 21 Mar 2022 10:21:46 +0300 Subject: [PATCH] Using try finally in nodejs examples, fix CI pipelines (#199) --- .github/check_connection.aqua | 7 ++ .github/deploy.aqua | 8 ++ .github/workflows/check-connection.yml | 84 ++++++++++++++ ...k-deploy.yml => check-deploy.yml.disabled} | 39 ++++--- .../workflows/test-aqua-ipfs-integration.yml | 5 +- .github/workflows/test-js-projects.yml | 1 + .../aqua-ipfs-integration/nodejs/src/main.ts | 108 +++++++++--------- .../echo-greeter/client-peer/src/main.ts | 66 +++++------ .../price-oracle/client-peer/src/main.ts | 47 ++++---- marine-examples/call_parameters/deploy.sh | 12 +- 10 files changed, 249 insertions(+), 128 deletions(-) create mode 100644 .github/check_connection.aqua create mode 100644 .github/deploy.aqua create mode 100644 .github/workflows/check-connection.yml rename .github/workflows/{check-deploy.yml => check-deploy.yml.disabled} (51%) diff --git a/.github/check_connection.aqua b/.github/check_connection.aqua new file mode 100644 index 0000000..9170fbe --- /dev/null +++ b/.github/check_connection.aqua @@ -0,0 +1,7 @@ +service Op("op"): + noop() + +func check_connection() -> string: + on HOST_PEER_ID: + Op.noop() + <- "ok" \ No newline at end of file diff --git a/.github/deploy.aqua b/.github/deploy.aqua new file mode 100644 index 0000000..ed50228 --- /dev/null +++ b/.github/deploy.aqua @@ -0,0 +1,8 @@ +service CallParameters: + call_parameters() -> string + +func call(service_id: string) -> string: + on HOST_PEER_ID: + CallParameters service_id + r <- CallParameters.call_parameters() + <- r \ No newline at end of file diff --git a/.github/workflows/check-connection.yml b/.github/workflows/check-connection.yml new file mode 100644 index 0000000..09a4816 --- /dev/null +++ b/.github/workflows/check-connection.yml @@ -0,0 +1,84 @@ +name: "check-connection" + +on: + push: + # branches: + # - "master" + +jobs: + check-deployment: + runs-on: ubuntu-latest + + strategy: + matrix: + node: [ + '/dns4/kras-00.fluence.dev/tcp/19990/wss/p2p/12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e', + '/dns4/kras-00.fluence.dev/tcp/19001/wss/p2p/12D3KooWR4cv1a8tv7pps4HH6wePNaK6gf1Hww5wcCMzeWxyNw51', + '/dns4/kras-01.fluence.dev/tcp/19001/wss/p2p/12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA', + '/dns4/kras-02.fluence.dev/tcp/19001/wss/p2p/12D3KooWHLxVhUQyAuZe6AHMB29P7wkvTNMn7eDMcsqimJYLKREf', + '/dns4/kras-03.fluence.dev/tcp/19001/wss/p2p/12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE', + '/dns4/kras-04.fluence.dev/tcp/19001/wss/p2p/12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi', + '/dns4/kras-05.fluence.dev/tcp/19001/wss/p2p/12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS', + '/dns4/kras-06.fluence.dev/tcp/19001/wss/p2p/12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr', + '/dns4/kras-07.fluence.dev/tcp/19001/wss/p2p/12D3KooWEFFCZnar1cUJQ3rMWjvPQg6yMV2aXWs2DkJNSRbduBWn', + '/dns4/kras-08.fluence.dev/tcp/19001/wss/p2p/12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt', + '/dns4/kras-09.fluence.dev/tcp/19001/wss/p2p/12D3KooWD7CvsYcpF9HE9CCV9aY3SJ317tkXVykjtZnht2EbzDPm' + ] + fail-fast: false + + defaults: + run: + shell: bash + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + ~/.cargo/bin + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - run: docker run -d --rm -e RUST_LOG="info" -p 1210:1210 -p 4310:4310 fluencelabs/fluence -t 1210 -w 4310 -k gKdiCSUr1TFGFEgu2t8Ch1XEUsrN5A2UfBLjSZvfci9SPR3NvZpACfcpPGC3eY4zma1pk7UvYv5zb1VjvPHwCjj --local + + - name: Download marine + run: sudo bash $GITHUB_WORKSPACE/.github/download_marine.sh + + - name: Install Rust + run: | + rustup toolchain install nightly-2021-04-24-x86_64-unknown-linux-gnu + rustup default nightly-2021-04-24-x86_64-unknown-linux-gnu + rustup target add wasm32-wasi --toolchain nightly-2021-04-24-x86_64-unknown-linux-gnu + + - uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-v1-node-16-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-v1-node-16 + + - name: Setup Node.js 16 + uses: actions/setup-node@v1 + with: + node-version: 16 + + - run: npm install -g @fluencelabs/aqua@0.6.4-283 + + - name: "Check connection to network" + run: | + set -x + NODE=${{ matrix.node }} + INPUT=$GITHUB_WORKSPACE/.github/check_connection.aqua + + RESULT=$(aqua run --addr $NODE --sk qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo= -f 'check_connection()' --input $INPUT) + RESULT=$(echo $RESULT | sed -e 's/Your peerId: [a-zA-Z0-9]*//g' | xargs) + + if [ "$RESULT" != "ok" ]; then + echo "Failed to connect to $NODE" + exit 1 + fi + + working-directory: marine-examples/call_parameters + diff --git a/.github/workflows/check-deploy.yml b/.github/workflows/check-deploy.yml.disabled similarity index 51% rename from .github/workflows/check-deploy.yml rename to .github/workflows/check-deploy.yml.disabled index 2de126e..726cf74 100644 --- a/.github/workflows/check-deploy.yml +++ b/.github/workflows/check-deploy.yml.disabled @@ -37,27 +37,40 @@ jobs: - uses: actions/cache@v2 with: path: ~/.npm - key: ${{ runner.os }}-v1-node-14-${{ hashFiles('**/package-lock.json') }} + key: ${{ runner.os }}-v1-node-16-${{ hashFiles('**/package-lock.json') }} restore-keys: | - ${{ runner.os }}-v1-node-14 + ${{ runner.os }}-v1-node-16 - - name: Setup Node.js 14 + - name: Setup Node.js 16 uses: actions/setup-node@v1 with: - node-version: 14 + node-version: 16 - - run: npm install -g @fluencelabs/fldist + - run: npm install -g @fluencelabs/aqua@0.6.4-283 - name: "Check call_parameters deployment" run: | set -x - export NODE="/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3" - SERVICE_ID=`./deploy.sh` - fldist --node-addr $NODE run_air -d '{"service_id": "'$SERVICE_ID'"}' -p <(echo ' - (seq - (call relay (service_id "call_parameters") [] result) - (call %init_peer_id% (returnService "run") [result]) - ) - ') + NODE="/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3" + SERVICE_ID=`./deploy.sh $NODE` + INPUT=$GITHUB_WORKSPACE/.github/deploy.aqua + + RESULT=$(aqua run --addr $NODE --sk qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo= -f 'call(service_id)' -d '{"service_id": "'$SERVICE_ID'"}' --input $INPUT) + RESULT=$(echo $RESULT | sed -e 's/Your peerId: [a-zA-Z0-9]*//g') + + EXPECTED_PEER_ID=$(echo -e "$RESULT" | sed -n '1p' | grep -o '12D3.*') + RESULT_PEER_ID=$(echo -e "$RESULT" | sed -n '2p' | tr -d \") + if [ "$EXPECTED_PEER_ID" -neq "$RESULT_PEER_ID" ]; then + echo "Expected $EXPECTED_PEER_ID, got $RESULT_PEER_ID" + exit 1 + fi + + RESULT_SERVICE_ID=$(echo -e "$RESULT" | sed -n '3p') + if [ "$SERVICE_ID" -neq "$RESULT_SERVICE_ID" ]; then + echo "Expected $SERVICE_ID, got $RESULT_SERVICE_ID" + exit 1 + fi + + aqua dist remove --addr $NODE --sk qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo= --id "$SERVICE_ID" working-directory: marine-examples/call_parameters diff --git a/.github/workflows/test-aqua-ipfs-integration.yml b/.github/workflows/test-aqua-ipfs-integration.yml index 0a8b0dd..e7eda32 100644 --- a/.github/workflows/test-aqua-ipfs-integration.yml +++ b/.github/workflows/test-aqua-ipfs-integration.yml @@ -10,6 +10,8 @@ jobs: strategy: matrix: node-version: [16.x] + project: [web, nodejs] + fail-fast: false steps: - uses: actions/checkout@v2 @@ -61,5 +63,4 @@ jobs: run: | npm i CI=false npm run build - npm run test -w nodejs - npm run test -w web + npm run test -w ${{ matrix.project }} diff --git a/.github/workflows/test-js-projects.yml b/.github/workflows/test-js-projects.yml index ee39fb7..55a479e 100644 --- a/.github/workflows/test-js-projects.yml +++ b/.github/workflows/test-js-projects.yml @@ -20,6 +20,7 @@ jobs: "./aqua-examples/price-oracle/client-peer", "./aqua-examples/price-oracle/web" ] + fail-fast: false steps: - uses: actions/checkout@v2 diff --git a/aqua-examples/aqua-ipfs-integration/nodejs/src/main.ts b/aqua-examples/aqua-ipfs-integration/nodejs/src/main.ts index 813c969..b48d518 100644 --- a/aqua-examples/aqua-ipfs-integration/nodejs/src/main.ts +++ b/aqua-examples/aqua-ipfs-integration/nodejs/src/main.ts @@ -29,65 +29,67 @@ export async function main(environment: Node[]) { let serviceHost = environment[2]; let providerClient = new FluencePeer(); - await providerClient.start({ connectTo: providerHost }); - console.log('šŸ“˜ uploading .wasm to node %s', providerHost.multiaddr); - let path = globSource('../service/artifacts/process_files.wasm'); - let { file, swarmAddr, rpcAddr } = await provideFile(path, providerClient); - console.log('šŸ“— swarmAddr', swarmAddr); - console.log('šŸ“— rpcAddr', rpcAddr); + try { + await providerClient.start({ connectTo: providerHost }); + console.log('šŸ“˜ uploading .wasm to node %s', providerHost.multiaddr); + let path = globSource('../service/artifacts/process_files.wasm'); + let { file, swarmAddr, rpcAddr } = await provideFile(path, providerClient); + console.log('šŸ“— swarmAddr', swarmAddr); + console.log('šŸ“— rpcAddr', rpcAddr); - await Fluence.start({ connectTo: relay }); - console.log( - 'šŸ“— created a fluence client %s with relay %s', - Fluence.getStatus().peerId, - Fluence.getStatus().relayPeerId, - ); + await Fluence.start({ connectTo: relay }); + console.log( + 'šŸ“— created a fluence client %s with relay %s', + Fluence.getStatus().peerId, + Fluence.getStatus().relayPeerId, + ); - // default IPFS timeout is 1 sec, set to 10 secs to retrieve file from remote node - await set_timeout(serviceHost.peerId, 10); + // default IPFS timeout is 1 sec, set to 10 secs to retrieve file from remote node + await set_timeout(serviceHost.peerId, 10); - console.log('\n\nšŸ“˜ Will deploy ProcessFiles service'); - var service_id = await deploy_service( - serviceHost.peerId, - file.cid.toString(), - rpcAddr, - (label, error) => { - console.error('šŸ“• deploy_service failed: ', label, error); - }, - { ttl: 10000 }, - ); - service_id = fromOption(service_id); - if (service_id === null) { + console.log('\n\nšŸ“˜ Will deploy ProcessFiles service'); + var service_id = await deploy_service( + serviceHost.peerId, + file.cid.toString(), + rpcAddr, + (label, error) => { + console.error('šŸ“• deploy_service failed: ', label, error); + }, + { ttl: 10000 }, + ); + service_id = fromOption(service_id); + if (service_id === null) { + await Fluence.stop(); + await providerClient.stop(); + return; + } + + console.log('šŸ“— ProcessFiles service is now deployed and available as', service_id); + + console.log('\n\nšŸ“˜ Will upload file & calculate its size'); + let { file: newFile } = await provideFile(urlSource('https://i.imgur.com/NZgK6DB.png'), providerClient); + var putResult = await put_file_size( + serviceHost.peerId, + newFile.cid.toString(), + rpcAddr, + service_id, + (fileSize) => console.log('šŸ“— Calculated file size:', fileSize), + (label, error) => { + console.error('šŸ“• put_file_size failed: ', label, error); + }, + { ttl: 10000 }, + ); + putResult = fromOption(putResult); + if (putResult !== null) { + console.log('šŸ“— File size is saved to IPFS:', putResult); + } + + let result = await remove_service(serviceHost.peerId, service_id); + console.log('šŸ“— ProcessFiles service removed', result); + } finally { await Fluence.stop(); await providerClient.stop(); - return; } - - console.log('šŸ“— ProcessFiles service is now deployed and available as', service_id); - - console.log('\n\nšŸ“˜ Will upload file & calculate its size'); - let { file: newFile } = await provideFile(urlSource('https://i.imgur.com/NZgK6DB.png'), providerClient); - var putResult = await put_file_size( - serviceHost.peerId, - newFile.cid.toString(), - rpcAddr, - service_id, - (fileSize) => console.log('šŸ“— Calculated file size:', fileSize), - (label, error) => { - console.error('šŸ“• put_file_size failed: ', label, error); - }, - { ttl: 10000 }, - ); - putResult = fromOption(putResult); - if (putResult !== null) { - console.log('šŸ“— File size is saved to IPFS:', putResult); - } - - let result = await remove_service(serviceHost.peerId, service_id); - console.log('šŸ“— ProcessFiles service removed', result); - - await Fluence.stop(); - await providerClient.stop(); } function fromOption(opt: T | T[] | null): T | null { diff --git a/aqua-examples/echo-greeter/client-peer/src/main.ts b/aqua-examples/echo-greeter/client-peer/src/main.ts index c816aba..21f1ae9 100644 --- a/aqua-examples/echo-greeter/client-peer/src/main.ts +++ b/aqua-examples/echo-greeter/client-peer/src/main.ts @@ -89,40 +89,42 @@ export async function main() { // console.log("hello"); // setLogLevel('DEBUG'); - await Fluence.start({ connectTo: krasnodar[2] }); - console.log( - 'created a fluence client %s with relay %s', - Fluence.getStatus().peerId, - Fluence.getStatus().relayPeerId, - ); + try { + await Fluence.start({ connectTo: krasnodar[2] }); + console.log( + 'created a fluence client %s with relay %s', + Fluence.getStatus().peerId, + Fluence.getStatus().relayPeerId, + ); - let echo_result = await echo(names, echo_topos[0].node, echo_topos[0].service_id); + let echo_result = await echo(names, echo_topos[0].node, echo_topos[0].service_id); - let result = ''; + let result = ''; - for (let item of echo_result) { - result += item.echo + ','; + for (let item of echo_result) { + result += item.echo + ','; + } + console.log('echo result : ', result); + + let greeting_result = await greeting(names[0], true, greeting_topos[0].node, greeting_topos[0].service_id); + console.log('greeting result : ', greeting_result); + + // echo_greeting_par(greet: bool, echo_service: EchoServiceInput, greeting_services: []NodeServicePair) -> []string: + let seq_result = await echo_greeting_seq( + names, + true, + echo_topos[0].node, + echo_topos[0].service_id, + greeting_topos[0].service_id, + ); + console.log('seq result : ', seq_result); + + let par_result = await echo_greeting_par(true, echo_service, greeting_services); + console.log('par result : ', par_result); + + par_result = await echo_greeting_par_improved(echo_service, greeting_services); + console.log('par improved signature result : ', par_result); + } finally { + await Fluence.stop(); } - console.log('echo result : ', result); - - let greeting_result = await greeting(names[0], true, greeting_topos[0].node, greeting_topos[0].service_id); - console.log('greeting result : ', greeting_result); - - // echo_greeting_par(greet: bool, echo_service: EchoServiceInput, greeting_services: []NodeServicePair) -> []string: - let seq_result = await echo_greeting_seq( - names, - true, - echo_topos[0].node, - echo_topos[0].service_id, - greeting_topos[0].service_id, - ); - console.log('seq result : ', seq_result); - - let par_result = await echo_greeting_par(true, echo_service, greeting_services); - console.log('par result : ', par_result); - - par_result = await echo_greeting_par_improved(echo_service, greeting_services); - console.log('par improved signature result : ', par_result); - - await Fluence.stop(); } diff --git a/aqua-examples/price-oracle/client-peer/src/main.ts b/aqua-examples/price-oracle/client-peer/src/main.ts index 973e481..296168b 100644 --- a/aqua-examples/price-oracle/client-peer/src/main.ts +++ b/aqua-examples/price-oracle/client-peer/src/main.ts @@ -54,29 +54,30 @@ export async function main() { // Uncomment to enable debug logs: // setLogLevel('DEBUG'); + try { + // create the Fluence client for the Krasnodar testnet + await Fluence.start({ connectTo: krasnodar[5] }); + console.log( + 'Created a fluence client with peer id %s and relay id %s', + Fluence.getStatus().peerId, + Fluence.getStatus().relayPeerId, + ); - // create the Fluence client for the Krasnodar testnet - await Fluence.start({ connectTo: krasnodar[5] }); - console.log( - 'Created a fluence client with peer id %s and relay id %s', - Fluence.getStatus().peerId, - Fluence.getStatus().relayPeerId, - ); + // call the get_price function -- sequential processing + const network_result = await get_price( + 'ethereum', + 'usd', + getter_topo[1].node, + getter_topo[1].service_id, + mean_topo[1].service_id, + ); + console.log('seq result: ', network_result); - // call the get_price function -- sequential processing - const network_result = await get_price( - 'ethereum', - 'usd', - getter_topo[1].node, - getter_topo[1].service_id, - mean_topo[1].service_id, - ); - console.log('seq result: ', network_result); - - // call the get_price_par function -- parallel processing - // func get_price_par(coin: string, currency: string, getter_topo: []NodeServicePair, mean_topo: NodeServicePair) -> Result: - const network_result_par = await get_price_par('ethereum', 'usd', getter_topo, mean_topo[0]); - console.log('par result: ', network_result_par); - - await Fluence.stop(); + // call the get_price_par function -- parallel processing + // func get_price_par(coin: string, currency: string, getter_topo: []NodeServicePair, mean_topo: NodeServicePair) -> Result: + const network_result_par = await get_price_par('ethereum', 'usd', getter_topo, mean_topo[0]); + console.log('par result: ', network_result_par); + } finally { + await Fluence.stop(); + } } diff --git a/marine-examples/call_parameters/deploy.sh b/marine-examples/call_parameters/deploy.sh index ce635ff..71d6183 100755 --- a/marine-examples/call_parameters/deploy.sh +++ b/marine-examples/call_parameters/deploy.sh @@ -1,13 +1,15 @@ #!/bin/bash set -o errexit -o nounset -o pipefail -if [[ -z "${NODE:-}" ]]; then - NODE_ADDR="" +./build.sh + +if [ $# -eq 1 ]; then + NODE="$1" else - NODE_ADDR="--node-addr $NODE" + echo "Expected single argument: node multiaddress. Got $# arguments." + exit 1 fi -./build.sh # check it .wasm was built WASM="artifacts/call_parameters.wasm" @@ -15,5 +17,5 @@ test -f "$WASM" || echo >&2 "Couldn't find $WASM" # create a service from that .wasm CONFIG="config.json" -SERVICE_ID=$(fldist new_service $NODE_ADDR --modules "$WASM:$CONFIG" --name call_parameters | head -n1 | sed -e 's/service id: //') +SERVICE_ID=$(aqua dist deploy --sk qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo= --data-path config.json --service call_parameters --addr "$NODE" | tail -n 1 | tr -d \") echo $SERVICE_ID