Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add tests CI #130

Merged
merged 29 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 109 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,37 @@ on:
description: "git ref to checkout to"
type: string
default: "main"
nox-image:
description: "nox image tag"
type: string
default: "null"
fcli-version:
description: "fcli version to use"
type: string
# default: "unstable"
default: "main"
js-client-version:
description: "@fluencelabs/js-client version"
type: string
default: "null"
fluence-env:
description: "env to run tests against"
type: string
default: "local"

jobs:
tests:
name: "build"
runs-on: ubuntu-latest
name: "Run tests"
runs-on: builder

env:
FLUENCE_USER_DIR: "${{ github.workspace }}/tmp/.fluence"
CI: true
# FORCE_COLOR: true

permissions:
contents: read
id-token: write

steps:
- name: Checkout repository
Expand All @@ -20,11 +46,86 @@ jobs:
repository: fluencelabs/frpc
ref: ${{ inputs.ref }}

- name: Install fluence-cli@unstable
run: npm i -g @fluencelabs/cli@0.11.1
- name: Import secrets
uses: hashicorp/vault-action@v2.5.0
with:
url: https://vault.fluence.dev
path: jwt/github
role: ci
method: jwt
jwtGithubAudience: "https://github.com/fluencelabs"
jwtTtl: 300
secrets: |
kv/docker-registry/basicauth/ci username | DOCKER_USERNAME ;
kv/docker-registry/basicauth/ci password | DOCKER_PASSWORD ;
kv/npm-registry/basicauth/ci token | NODE_AUTH_TOKEN ;
kv/ci/frpc chain_urls | RPC_PROVIDERS ;
kv/ci/frpc private_key | FLUENCE_CHAIN_PRIVATE_KEY

- name: Login to DockerHub
uses: docker/login-action@v2
with:
registry: docker.fluence.dev
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}

- name: Setup Rust toolchain
uses: dsherret/rust-toolchain-file@v1

- name: Setup fcli
uses: fluencelabs/setup-fluence@v1
with:
artifact: fcli
version: ${{ inputs.fcli-version }}

- name: Init local env with fcli
run: fluence local init --no-input

- name: Replace nox image in docker-compose
if: inputs.nox-image != 'null'
working-directory: .fluence
run: |
sed -i'' -e '/nox-/!b;n;s|image: fluencelabs/nox:.*$|image: ${{ inputs.nox-image }}|' docker-compose.yaml

- name: Run local env
run: fluence local up

- name: Setup node with self-hosted registry
uses: actions/setup-node@v3
with:
node-version: "18"
registry-url: "https://npm.fluence.dev"
cache: "npm"

- name: Run npm i
run: npm i

- name: Run npm i in gateway
working-directory: gateway
run: npm i

- name: Set js-client version
if: inputs.js-client-version != 'null'
uses: fluencelabs/github-actions/npm-set-dependency@main
with:
package: "@fluencelabs/js-client"
version: "${{ inputs.js-client-version }}"
working-directory: gateway

- name: Run npm run build
run: npm run build

- name: Run tests
env:
FLUENCE_ENV: ${{ inputs.fluence-env }}
run: npm run test -- -t deploy

- name: Check if main.aqua compiles
run: fluence aqua --dry
- name: Dump container logs
if: always()
uses: jwalton/gh-docker-logs@v2

- name: Check if services builds
run: fluence build
- name: Cleanup
if: always()
run: |
fluence local down
rm -rf tmp ${{ env.FLUENCE_USER_DIR }}
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ src/js/src/aqua
aqua-compiled

# recommended by Fluence Labs:
/.fluence/project-secrets.yaml
/.fluence/schemas
/.fluence/tmp
.fluence/project-secrets.yaml
.fluence/docker-compose.yaml
.fluence/schemas
.fluence/secrets
.fluence/tmp

# to avoid accidental publish of RPC URLs
gateway/configs/quickstart_config.json
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,55 @@ Fluence CLI did a bunch of work for us behind the scenes and signing the transac

Note that the deal's section in [fluence.yaml](./fluence.yaml) specifies the minimum and maximum workers that should be deployed under the *defaultWorker* namespace. Fluence CLI currently provides default values for min and max workers of one (1) and three (3), respectively. In the near future, you will be able to provide your spot price for service execution, hosting targets in the form of named capacity providers and more.

After successful deal deployment it is possible to retrieve logs for the deployed deal.

**Command**:

```bash
fluence deal logs
```

**Output**:

```bash
Connecting to random stage relay: /dns4/0-stage.fluence.dev/tcp/9000/wss/p2p/12D3KooWDcpWuyrMTDinqNgmXAuRdfd2mTdY9VoXZSAet2pDzh6r
Connected
defaultWorker (host_id: 12D3KooWMMGdfVEJ1rWe1nH1nehYDzNEHhg5ogdfiGk88AupCMnf, worker_id: 12D3KooWGctQEUKcgWBetu9aiR3owMZcBGNcpDC5ZE3H6dL16uSP, spell_id: 679acf1c-57e2-4dd7-aa78-bb181df7a00a):

2023-10-25 14:41:48 Installing worker for deal 0x02ab47b7b2737e16a516421c1b8ad36475e0f7ce
2023-10-25 14:41:48 parsed worker definition bafkreifp4gbp3emepswptldwlpbhpybt47uy2c3ksm3y7rut6cmcdnljwa {
"services": [
{
"modules": [
{
"config": "bafkreia2wftbxfd4blycnvlxw2yl7ibhan2g7vauexv7fspibodlu34que",
"wasm": "bafkreiarl3nin4jtauc52k76h4ze7yekvc5d2uno5fkgpotmcekwm7cnqa"
},
{
"config": "bafkreiaclbxbmtydpwdcpoh2yggcd6uimicmbb6rxzab7bgp342w5vcz2m",
"wasm": "bafybeieeemeldllgokrkgybbrrjqeehyin3blv5cgehhdp3nlrfyj4eqoa"
}
],
"name": "eth_rpc"
}
],
"spells": []
}
2023-10-25 14:41:50 Created service eth_rpc 2b5967ae-e5f9-4929-8668-d2039593af28
2023-10-25 14:41:50 Installation finished
2023-10-25 14:41:50 Worker installation finished with status {
"message": "",
"state": "INSTALLATION_SUCCESSFUL",
"timestamp": 1698244910
}

defaultWorker (host_id: 12D3KooWJ4bTHirdTFNZpCS72TAzwtdmavTBkkEXtzo6wHL25CtE, worker_id: unknown, spell_id: unknown): Worker is not installed yet

defaultWorker (host_id: 12D3KooWAKNos2KogexTXhrkMZzFYpLHuWJ4PgoAhurSAv7o5CWA, worker_id: unknown, spell_id: unknown): Worker is not installed yet
```

In the example output above, we see that the worker for the *defaultWorker* namespace was installed successfully. The worker is now ready to receive requests from the gateway. The other two workers are not installed yet. It should happen in a while and one can check the logs again to see the progress.

### fRPC Aqua Code

Now that we have our services deployed and ready for action, it's time to look at Aqua, which is utilized by the Gateway to bridge HTTP to/from libp2p. Let's have a look at the Aqua code and structure.
Expand Down
7 changes: 6 additions & 1 deletion fluence.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@

# Documentation: https://github.com/fluencelabs/fluence-cli/tree/main/docs/configs/fluence.md

version: 2
version: 4

aquaInputPath: src/aqua/main.aqua

workers:
defaultWorker:
services: [ eth_rpc ]

deals:
defaultWorker:
minWorkers: 3
targetWorkers: 3

relays: stage

services:
eth_rpc:
get: wasm-modules
1 change: 0 additions & 1 deletion gateway/aqua/rpc.aqua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func balancedEthCall{Logger, Balancer}(method: string, jsonArgs: []string) -> Js
worker, provider <- Balancer.next()
Logger.logWorker(worker)
Logger.logCall(provider)
Op.noop() -- dirty hack for topology to converge
rpc <- fromWorkerProvider(worker, provider)
result <- rpcCall{rpc}(method, jsonArgs)
<- result
Expand Down
85 changes: 59 additions & 26 deletions gateway/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
"main": "src/index.js",
"type": "module",
"scripts": {
"run:example": "fluence aqua -i aqua/ -o aqua-compiled/ --js && node src/index.js \"config.json\"",
"run": "fluence aqua -i aqua/ -o aqua-compiled/ --js && node src/index.js",
"compile": "fluence aqua -i aqua/ -o aqua-compiled/ --js",
"run": "npm run compile && node src/index.js",
"compile": "fluence aqua -i aqua/ -o aqua-compiled/ --js --no-input",
"req": "node web3run.js"
},
"bin": {
Expand All @@ -21,7 +20,7 @@
"author": "Fluence Labs",
"license": "Apache-2.0",
"dependencies": {
"@fluencelabs/js-client": "0.3.0",
"@fluencelabs/js-client": "0.4.2",
"@fluencelabs/marine-worker": "0.3.3",
"body-parser": "1.20.2",
"express": "4.18.2",
Expand Down
Loading
Loading